Skip to content

v1.19.1

Latest

Choose a tag to compare

@yhirose yhirose released this 01 Oct 03:27
· 7 commits to master since this release

✨ New

enable_ast(collapse_mode, opt_mode, rules)

enable_ast(true) builds the optimized AST directly, keeping the nodes of the rules marked no_ast_opt. A program that optimizes with its own AstOptimizer(opt_mode, rules) can now have that same tree built directly by passing the list as a third argument:

parser.enable_ast(true, true, {"ARGUMENTS", "BLOCK"});

Marking those rules no_ast_opt instead would not give the same tree: a node of a no_ast_opt rule keeps its own source range when the parent it stands in for collapses onto it, so ranges would change.

On culebra's grammar, with 59 such rules over its 576 test and example files, the tree is identical in every field of every node, and parsing with the optimization takes 34% fewer instructions than enable_ast() followed by AstOptimizer (Release, min of 3 alternating runs).