CompilerTeaching / Pegmatite

A library for reusable parsers
http://compilerteaching.github.io/pegmatite/
BSD 2-Clause "Simplified" License
16 stars 9 forks source link

Allow parse_procs to be bound by subclasses. #11

Closed trombonehero closed 9 years ago

trombonehero commented 9 years ago

The BindAST template requires that AST classes have default constructors and a construct method for post-construction initialization. This is fine for some use cases, but it precludes effective patterns like immutable fields and factory methods.

The precise details of how a language's AST nodes are constructed are highly variable, so rather than adding more variants of BindAST to Pegmatite itself, this commit makes ASTParserDelegate::set_parse_proc and bind_parse_proc visible to subclasses of ASTParserDelegate. That way, a language's parser delegate can implement its own binding logic.

davidchisnall commented 9 years ago

Looks fine to me. Please rebase / apply to head. There are a few things that could be a lot nicer in AST construction (e.g. default classes for constructing strings, numbers and so on).