Header lexy/dsl/eof.hpp

Token rule lexy::dsl::eof

namespace lexy::dsl
    constexpr token-rule auto eof;

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


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


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

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 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;
Without eof, lexy will happily match the prefix of an input only, ignoring any junk characters after it is finished.
It does not skip whitespace before checking for EOF. Use lexy::dsl::whitespace + eof to do that.

See also