[antlr-interest] tree grammar question: how to say "anything"

Hardy, Stephen Stephen.Hardy at digi.com
Fri Aug 17 13:49:05 PDT 2007


Andy,

a similar thread came up recently.  Without actually trying it, I think
your tree parser rule should be something like:

myGuidTreeRule:
     ^( GUID '{' .* '}' )
     ;

since you did not exclude the brace tokens from the initial tree
construction.  Of course, there's probably no need for those tokens so
the parser rule could be

guid:
    '{'! ~('}')* '}'!
    ;

which would simplify the tree rule to 

myGuidTreeRule:
     ^( GUID .* )
     ;

Regards,
SJH
 

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org 
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Andy Tripp
> Sent: Friday, August 17, 2007 9:15 AM
> To: antlr-interest
> Subject: [antlr-interest] tree grammar question: how to say "anything"
> 
> If I have the following parser rule, with no rewrite:
> 
> guid:
>    '{' ~('}')* '}'
>    ;
> 
> ...and assume I have some other parser rule:
> 
> otherRule:
>     'A' ^(GUID guid) 'B'
>     ;
> 
> What would my tree grammar rule for guid look like?
> I need Something like:
> 
> myGuidTreeRule:
>     GUID blah*
>     ;
> 
> ...where I want "blah" to mean "any AST whatsoever" (or I guess
> actually "any AST other than a StringLiteral with text '}')
> Does the treegrammar grammar have any such construct? If not,
> can I do it "by hand" somehow?
> 


More information about the antlr-interest mailing list