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

Jared Bunting jared.bunting at peachjean.com
Wed Dec 17 12:10:02 PST 2008


Is there a reason that "alphanumeric" is a parser rule?  Making it a 
lexer rule would reduce it to one token.

-Jared

Mihai Danila wrote:
>
> 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';
>
> ------------------------------------------------------------------------
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>   


More information about the antlr-interest mailing list