Closed hishamhm closed 7 years ago
The idea behind generating the AST automatically was to minimize the grammar, but provide a complete AST, so that it can be reduced afterwards as necessary. The node
functionality can be achieved by disabling AST generation and adding captures to the tables, however, I do see your point. I'm not sure whether this approach is better in the general case and I'd like to hear some more opinions on this; I'm not against implementing this approach in a separate branch.
I added this feature to the latest commit, please test it out. Before compiling the grammar use
pg.usenodes(true)
Currently, parser-gen generates an AST where it produces a node for each rule, unless told so via
fragment
. This produces a lot of intermediate nodes in ASTs (e.g.statement
,simpleexp
,term
,factor
in the Tiny example of README.md).It would be nice to, instead of marking which rules don't generate nodes, to be able to mark which rules should generate nodes (perhaps with a
node
annotation or some other syntax?).