Header lexy/dsl/newline.hpp
The newline and eol token rules.
Token rule lexy::dsl::newline
lexy/dsl/newline.hppnamespace lexy
{
struct expected_newline {};
}
namespace lexy::dsl
{
constexpr token-rule auto newline;
}newline is a token rule that matches a newline.
It is entirely equivalent to lexy::dsl::literal_set` containing of the literals "\r\n" and "\n",
where the error has been overridden to lexy::expected_newline.
Example 1. Match a newline at the end
Caution | As a token rule, it matches whitespace immediately following the newline.
As such, the rule is best used in contexts where automatic whitespace skipping is disabled,
or where it doesn’t include newline characters. |
Caution | Differentiate between lexy::dsl::ascii::newline, which matches \r or \n, and lexy::dsl::newline, which matches \r\n or \n! |
Branch rule lexy::dsl::eol
lexy/dsl/newline.hppnamespace lexy::dsl
{
constexpr branch-rule auto eol;
}eol is a branch rule that matches the end of a line.
- Requires
The encoding of the input is a char encoding.
- (Branch) Parsing
If at EOF, succeeds without consuming anything. Otherwise, forwards to
lexy::dsl::newline- Errors
lexy::expected_newline: if it could match neither EOF nor a newline; at the starting reader position.- Parse tree
If at EOF, single token node with the
lexy::predefined_token_kindlexy::eof_token_kindwhose range is empty. Otherwise, the token node created bylexy::dsl::newline.
Example 2. Match a newline or EOF at the end
Caution | The same caveat about whitespace as for newline applies here as well. |