antlr / stringtemplate4

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

Only first format is applied to a value while processing multiple templates with formats #119

Closed barbalion closed 9 years ago

barbalion commented 9 years ago

Test the code below ("lower" and "cap" string format assumed to be implemented). All templates work well but "cap" format is never applied.

BugReport() ::= <<
<"aaaBBBccc": Lower(): Cap()>1
>>

Lower(s) ::= <<
<s; format="lower">2
>>
Cap(s) ::= <<
<s; format="cap">3
>>

Actual output:

aaabbbccc231

Expected output (capitalized first letter):

Aaabbbccc231

Tested on 4.0.8.

sharwell commented 9 years ago

What happens if you force the string to be rendered before applying the formats? Note that I changed s to (s) (parentheses is the "to string" operator in StringTemplate).

Lower(s) ::= <<
<(s); format="lower">
>>
Cap(s) ::= <<
<(s); format="cap">
>>
barbalion commented 9 years ago

It works properly then!

sharwell commented 9 years ago

Glad to hear that. :smile: :+1:

I'm fairly sure this is by design. The result of applying Lower() to the string is a template, not a string. The cap format was only defined for strings, so you needed to coerce the input before applying the format.