phorward / unicc

LALR parser generator targetting C, C++, Python, JavaScript, JSON and XML
MIT License
58 stars 9 forks source link

Provide method for keyword's AST visibility #26

Closed phorward closed 2 years ago

phorward commented 2 years ago

An useful feature would be to allow keywords to be recognizes by the AST generator or not.

Currently, all keywords are also made into AST leafs:

start$ : "test" = test;

This will become an ast-node "prog" with a leaf "test". The keyword is always recognized and turned as part of the AST.

A possible solution: The double quotation mark, likewise in Tokay, might specify if a keyword should become part of the AST, otherwise it is ignored.

start$ : ""test"" = prog;  // creates one AST node "prog" with the keyword "test" as leaf
start$ : "test" = prog;  // creates one AST node (leaf) "prog". The keyword is ignored.

This solution is only a minor enhancement to the syntax but might break existing grammars when they use the AST feature. Little effort would be required to fix these.