[antlr-interest] stringtemplate lower case/upper case question

Terence Parr parrt at cs.usfca.edu
Thu May 24 08:49:12 PDT 2007


Hi Martin,

Use the format option.  You'll have to search the stringtemplate  
archives for how to use it.  I can't remember the details.  And you  
need the latest build from stringtemplate.org/download/build

Ter

On May 24, 2007, at 8:35 AM, Martin d'Anjou wrote:

> Hi,
>
> We use StringTemplate to produce many outputs based on an in-house  
> created language using ANTLR to parse.  The following situation  
> creeps up a lot: depending on the target output, I need the same  
> data (usually names) in either upper-case, lower-case or the  
> original mixed-case declaration.  I've found myself ending up  
> writing a lot of this for example:
>
> public String getFullName()
> {
>    String regName = this.name.replaceFirst("n", String.valueOf 
> (this.currentIndex+this.startIndex));
>    return regName+this.nameSuffix;
> }
>
> public String getFullNameLower()
> {
>    return fullName().toLowerCase();
> }
>
> public String getFullNameUpper()
> {
>    return fullName().toUpperCase();
> }
>
> And doing $blah.fullname$, $blah.fullNameLower$, or  
> $blah.fullNameUpper$ in the templates based on context.
>
> I was wondering is there a better way that would save the writing  
> of the extra two functions (*Upper and *Lower)?  If not, would  
> StringTemplate not benefit from a simple toLower and toUpper built- 
> in syntax (e.g. $blah.fullName$, $blah.fullName*UpperCase$, or  
> $blah.fullName*LowerCase$) ?
>
> P.S.  So far I have over 30 "triplets" like this (and counting),  
> hence my frustration at the extra functions ;)
>
> Thanks!
> Martin



More information about the antlr-interest mailing list