Pegmatite
|
A parser delegate that is responsible for creating AST nodes from the input. More...
#include <ast.hh>
Public Member Functions | |
ASTParserDelegate () | |
Default constructor, registers this class in thread-local storage so that it can be referenced by BindAST fields in subclasses when their constructors are run. | |
virtual parse_proc | get_parse_proc (const Rule &) const |
Returns the handler for the specified rule. | |
template<class T > | |
bool | parse (Input &i, const Rule &g, const Rule &ws, ErrorReporter err, std::unique_ptr< T > &ast) const |
Parse an input i , starting from rule g in the grammar for which this is a delegate. More... | |
Protected Member Functions | |
void | set_parse_proc (const Rule &r, parse_proc p) |
Registers a callback in this delegate. | |
Static Protected Member Functions | |
static void | bind_parse_proc (const Rule &r, parse_proc p) |
Registers a callback for a specific rule in the instance of this class currently under construction in this thread. | |
Friends | |
template<class T > | |
class | BindAST |
BindAST is a friend so that it can call the set_parse_proc() function, which should never be called from anything else. | |
A parser delegate that is responsible for creating AST nodes from the input.
This class manages a mapping from rules in some grammar to AST nodes. Instances of the BindAST
class that are fields of a subclass of this will automatically register rules on creation.
The recommended use for this class is to only register rules on construction (either explicitly in the constructor or implicitly via BindAST
members). This will give a completely reentrant delegate, which can be used by multiple threads to parse multiple inputs safely.
|
inline |
Parse an input i
, starting from rule g
in the grammar for which this is a delegate.
The rule ws
is used as whitespace. Errors are returned via the el
parameter and the root of the AST via the ast
parameter.
This function returns true on a successful parse, or false otherwise.