[antlr-interest] Somewhere between actions and string templates

Ted Villalba tedv at esrconsulting.com
Mon May 21 14:49:26 PDT 2007


I'm getting Null values when I try to use the += to gather all the terms in
a list with a StringTemplate.

If I have the following query: 
TO=(spark plugs) AND AU=(Flaig)

And this grammar:
expression : ^('=' tag v=value+) ->
template4(tag={$tag.text},values={$v.text}) ;

Where template4 is defined to print out the values:
template4(tag, values) ::= " IN <tag>:<values> OUT"

I get :
IN TO:spark OUT  IN AU:(Flaig) OUT

If I change the grammar to try to capture the "value" list:
expression : ^('=' tag (v+=value)+) -> template4(t={$tag.text},values={$v})
;

I get:
IN TO: OUT  IN AU: OUT


I'd be glad to offer up any more details on the grammars, just wanted to
keep this as concise as possible without overloading on the detail.
Any help would be greatly appreciated. 

Thanks,
Ted





-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Terence Parr
Sent: Saturday, May 19, 2007 4:21 PM
To: LISTE ANTLR-INTEREST
Subject: Re: [antlr-interest] Somewhere between actions and string templates


On May 18, 2007, at 1:59 PM, Ted Villalba wrote:
> expression returns [String subexpr]:         ^('=' tag (v+=value)+)  
> -> template(values={$v}) "<values>" ;
>
>
>
> //          
> {                                                            // 
> Commented out this code to add the template
>
> //           $subexpr=$tag.text+":"+$value.text;      //added the  
> template because this $value.text would only grab the first value
>
> //       }
>
> //      ;
>
>
>
> I am not so interested in printing something out, but rather in  
> passing back subexpr once I can get the list of 'values' into that  
> expression( $subexpr=.).

With output=template option rule expression will implicitly return a  
ST.  The explicit return values are no longer needed.

What you have should work fine.  What is going wrong?
>  Somewhat related, in the book when StringTemplates are introduced,  
> the embedded actions go away, yet the return statements remain, so  
> I don't see how the [int value] is populated here. Maybe if I  
> understand that, it will help me with the above.

ooops.

Ter



More information about the antlr-interest mailing list