|
|
void | init (const std::filesystem::path *path) |
|
|
Use like this:
auto foo = parse_foo();
auto bar = parse_bar();
auto foobar = new FooBar(track, foo, bar);
Tracker tracker() Factory method to build a Parser::Tracker.
|
Tracker | tracker () |
| Factory method to build a Parser::Tracker.
|
|
|
Tok | ahead (size_t i=0) const |
|
Tok | lex () |
| Invoke Lexer to retrieve next Token.
|
|
Tok | accept (Tag tag) |
| If Parser::ahead() is a tag , consume and return it, otherwise yield std::nullopt .
|
|
Tok | expect (Tag tag, std::string_view ctxt) |
| Parser::lex Parser::ahead() which must be a tag .
|
|
Tok | eat (Tag tag) |
| Consume Parser::ahead which must be a tag ; asserts otherwise.
|
|
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 Tok
ens.
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_sth(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.