template<class Tok, class Tag, size_t K, class S>
requires (std::is_convertible_v<Tok, bool> || std::is_constructible_v<bool, Tok>) || std::is_default_constructible_v<Tok>
class fe::Parser< Tok, Tag, K, S >
The blueprint for a recursive descent/ ascent parser using a K lookahead of Tokens.
Parser::accept and Parser::expect indicate failure by constructing a Token with its default constructor. Provide a conversion operator to bool to check for an error:
class Tok {
public:
enum class Tag {
Nil,
};
explicit bool operator() const { return tag_ != Tag::Nil; }
};
if (
auto tok =
accept(Tok::Tag::My_Tag)) {
do_something(tok);
}
Tok accept(Tag tag)
If Parser::ahead() is a tag, consume and return it, otherwise yield std::nullopt.
Definition at line 31 of file parser.h.
template<class Tok, class Tag, size_t K, class S>
| Tok fe::Parser< Tok, Tag, K, S >::accept |
( |
Tag | tag | ) |
|
|
inlineprotected |
template<class Tok, class Tag, size_t K, class S>
| Tok fe::Parser< Tok, Tag, K, S >::expect |
( |
Tag | tag, |
|
|
std::string_view | ctxt ) |
|
inlineprotected |
template<class Tok, class Tag, size_t K, class S>