Header lexy/dsl/eof.hpp
Branch rule lexy::dsl::eof
lexy/dsl/eof.hpp
namespace lexy
{
struct expected_eof {};
}
namespace lexy::dsl
{
constexpr branch-rule auto eof;
}
eof
is a branch rule that matches the end of input (EOF).
- (Branch) Parsing
Succeeds if the reader is at the end of the input, without consuming anything.
- Errors
lexy::expected_eof
: at the unchanged reader position. It then recovers immediately.- Parse tree
Single token node whose range is empty with the
lexy::predefined_token_kind
lexy::eof_token_kind
.
Parsing eof
multiple times in sequence has no additional effect:
they all succeed if the first one succeeded and they all fail if the first one failed.
Example 2. Prevent trailing characters
Caution | Without eof , lexy will happily match the prefix of an input only, ignoring any junk characters after it is finished. |
Note | It does not skip whitespace before checking for EOF. Use lexy::dsl::whitespace + eof to do that. |