[antlr-interest] constructing AST nodes from variables

John Ridgway john at jacelridge.com
Wed Dec 12 16:16:54 PST 2007


I think you need
   -> ^(ASSERT $r $left $right {msg})

note the braces around msg

Peace
- John


On Dec 12, 2007, at 6:20 PM, Mark Volkmann wrote:

> Is it possible to set a variable that is used in an AST rewrite rule?
> In the example below that doesn't currently work I'm trying to set the
> variable "msg" and then output it into my AST. Maybe the underlying
> question is whether you can use both { } and -> in the same rule.
>
> myRule
> @init { String msg; }
>   : 'assert' left=value r=RELATION right=value
>     { msg = "some string value"; }
>     -> ^(ASSERT $r $left $right msg);
>
> -- 
> R. Mark Volkmann
> Object Computing, Inc.



More information about the antlr-interest mailing list