Header lexy/dsl/eof.hpp

Token rule lexy::dsl::eof

lexy/dsl/eof.hpp
namespace lexy::dsl
{
    constexpr token-rule auto eof;
}

eof is a token rule that matches the end of input (EOF).

Matching

Succeeds if the reader is at the end of the input, without consuming anything.

Errors

lexy::expected_char_class ("EOF"): at the unchanged reader position.

Parse tree

Single token type 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 1. Match the empty input
struct production
{
    static constexpr auto rule = dsl::eof;
};
Example 2. Prevent trailing characters
struct production
{
    static constexpr auto rule = LEXY_LIT("Hello") + dsl::eof;
};
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.

See also