[antlr-interest] adding content at endofrulewithTokenRewriteStream
Jean Marc Vanel
JeanMarc.Vanel at mathworks.fr
Mon Feb 26 10:42:06 PST 2007
> How about abusing the rewrite syntax a bit, just so that you can
access
> the result tree for the rule,
>
> name_or_pointer
> : (NAME STAR? -> NAME STAR?)
> { tokens.insertAfter( $name_or_pointer.tree.stop, "blah"
); }
> ;
>
> I didn't test the code above, but I think I've done something like
that
> in the past.
[Jean-Marc Vanel] It's smart , but in fact , $name_or_pointer.tree.stop
, or
name_or_pointer.tree.stop don't compile in the generated Java code.
>
> The problem is (I think) that ANTLR doesn't normally set the
stop-token
> for the result tree until *after* the rule and all its actions have
> executed, which makes it tricky for the rule itself to get at this
> information.
>
> Actually, all ANTLR does to set the stop-token is to assign the value
> from input.LT(-1), so maybe you could just use that,
>
> name_or_pointer
> : NAME STAR? { tokens.insertAfter(input.LT(-1), "blah"); }
> ;
[Jean-Marc Vanel] This works !!! Thanks a lot. I should have found it
myself ....
More information about the antlr-interest
mailing list