[antlr-interest] Syntax for Merging AST Nodes / Rule Text as AST Node

Mihai Danila viridium at gmail.com
Wed Dec 17 11:57:41 PST 2008


Hi,

An AST-producing grammar I've been using generates many nodes that I'd like
joined into one node. Is there syntax for joining nodes at a certain level
into one node? Alternatively, is there a way to specify that the entire text
matched by a rule be put in an AST node?

For example, the rule in the grammar below will produce as many nodes as
there are characters matched in all the rules that use it, whereas I'd
prefer the text alone to be used to simplify grammars that consume the AST:
(well, maybe grammars that use the AST can match the whole subtree and be
able to obtain the text over an entire subtree, in which case they're good,
but I'd still like to have a smaller AST for better debugging)

alphanumeric: (A | D)+;

A: 'A'..'Z' | 'a'..'z';
D: '0'..'9';
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081217/17163e3e/attachment.html 


More information about the antlr-interest mailing list