Header lexy/dsl/until.hpp
Token rule lexy::dsl::until
lexy/dsl/until.hppnamespace 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
conditionanywhere in the remaining input, then consumes it. If.or_eof()has been used, succeeds when it reaches EOF without matchingcondition. Otherwise, fails when it reaches EOF.- Errors
All errors raised by matching
conditionat 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
conditionand everything consumed bycondition. It has thelexy::predefined_token_kindlexy::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.
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::loop(condition >> dsl::break_ | 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. |