Header lexy/dsl/until.hpp

Token rule lexy::dsl::until

lexy/dsl/until.hpp
namespace lexy::dsl
{
    class until-dsl // models token-rule
    {
    public:
        constexpr token-rule auto or_eof() const;
    };

    constexpr until-dsl until(token-rule auto condition);
}

until is a token rule that matches all input until and including a terminating condition.

Matching

Tries to match condition anywhere in the remaining input, then consumes it. If .or_eof() has been used, succeeds when it reaches EOF without matching condition. Otherwise, fails when it reaches EOF.

Errors

All errors raised by matching condition at EOF, if .or_eof() has not been used. It then fails. If .or_eof() has been used, it can never fail.

Parse tree

A single token node that contains everything consumed before condition and everything consumed by condition. It has the lexy::predefined_token_kind lexy::any_token_kind.

until(condition) aggressively discards input to find a match for condition. It doesn’t matter what the input is. until(condition).or_eof() behaves just like until(condition / lexy::dsl::eof ), i.e. the end of the input is also considered to be a terminating condition. If .or_eof() was used, the rule never fails, but it may consume the rest of the input.

Example 1. A C++-style comment
struct production
{
    static constexpr auto rule = LEXY_LIT("//") + dsl::until(dsl::newline).or_eof();
};
Caution
until() does not care what input it consumes to find condition; it can be lexy::dsl::anything, including ill-formed Unicode. To restrict the input that is allowed before condition, use lexy::dsl::terminator(condition).while_(before).
Warning
If the condition is missing, until(condition).or_eof() will happily discard the rest of the input. This is similar to the behavior of an unterminated /* comment.
Note
until will include condition.

See also