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

Mihai Danila viridium at gmail.com
Wed Dec 17 12:15:48 PST 2008


Yup, this has to do with another message I've just posted; I'm having
problems with certain tokens and I've promoted them to parser rules to avoid
those problems. In any case, it seems to work with the bracket and
additional imaginary token, so I'm happy with it right now.

In short, it seems that rule matching and "backtracking" is smart enough to
overcome those difficulties (which have to do with ISO dates and ranges that
are specified as date-date or number-number, where the range dash will cause
a token not to be matched because it just so happens the token could be
continued with a dash in some cases).


Mihai


On Wed, Dec 17, 2008 at 3:10 PM, Jared Bunting
<jared.bunting at peachjean.com>wrote:

> 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
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081217/20187bcf/attachment.html 


More information about the antlr-interest mailing list