antlr / stringtemplate4

StringTemplate 4
http://www.stringtemplate.org
Other
956 stars 231 forks source link

<attribute:t1():t2():t3()> ignores format expression-option #137

Closed maassg closed 8 years ago

maassg commented 8 years ago
// data.stg
t1( x ) ::= "1-&lt;x&gt;-1"
t2( x ) ::= "2&lt;x&gt;2"
t3( x ) ::= "[3&lt;x; format=\"lower\"&gt;3]"

t() ::= "<\"HELLO\":t1():t2():t3()>"

renders to: [321-HELLO-123] instead of: [321-hello-123]

The renderer call sequence is as follows: class java.lang.String, format=null, value=[3 class java.lang.String, format=null, value=2 class java.lang.String, format=null, value=1- class java.lang.String, format=null, value=HELLO class java.lang.String, format=null, value=-1 class java.lang.String, format=null, value=2 class java.lang.String, format=null, value=3]

T-PWK commented 8 years ago

Hi,

I run into smiler issue many times before. Solution with always works for me is to put parenthesis around formatted element. So in your case the following code:

t1( x ) ::= "1-<x>-1"
t2( x ) ::= "2<x>2"
t3( x ) ::= "[3<(x); format=\"lower\">3]"

t() ::= "<\"HELLO\":t1():t2():t3()>"

will return [321-hello-123] as expected.

maassg commented 8 years ago

Hi Tom, thanks a lot for your help. It now works for me too. best regards.