[stringtemplate-interest] StringTemplate extensions

Mark Venbrux mark.venbrux at gmail.com
Wed Jan 4 02:53:06 PST 2006


Hi,
I'm pleased to have found AntLR and StringTemplate and I've used it
for about a month now. Its powerful and fun at the same time!
But.....(probably this issue was raised several times already)
Sometimes I think that XSL for output generation could be more
effective. I seems that one StringTemplate outputmodel will not hold
for the compilation of a 'C' like language to multiple target assembly
languages.
Currently I think that the approach of choice would be to have
different tree parsers that create output models targeted a the
different output languages. Am I right? In my interpretation it means
that tree parsing occurs somewhere in a grey area between Model and
View. Please comment on this.
Anyway, currently only one outputmodel is sufficient for me. I have
added some options to StringTemplate though:


In: ....\stringtemplate-2.2\src\org\antlr\stringtemplate\language\action.g

optionList! returns [Map opts=new HashMap()]
   :   "separator" ASSIGN e:expr {opts.put("separator",#e);}
   |   "order" ASSIGN e2:expr {opts.put("order",#e2);}// could be:
"reverse" or sort...
   |   "repeat" ASSIGN e3:expr {opts.put("repeat",#e3);}// could be: "10"
   ;

I've updated
...\stringtemplate-2.2\src\org\antlr\stringtemplate\language\ASTExpr.java
accordingly. Probably not the best implementation, but it works for me.

The reverse option is used for pushing parameters on the stack, the
repeat option for default initializers of arrays.
Two questions:
- Is this the right way to go?
- If so, is it possible to have these options integrated in StringTemplate?

Cheers, and thanks for the splendid work,

Mark


More information about the stringtemplate-interest mailing list