[stringtemplate-interest] Dynamic attribute reference?
Terence Parr
parrt at cs.usfca.edu
Wed Nov 8 09:37:25 PST 2006
On Nov 8, 2006, at 9:23 AM, Mark Cooke wrote:
> Hi,
> I've not found a way to get this to work...
>
> I have a "model" in a code generator which is
> basically a database table of strings (ID, lang1Text,
> ..., langNText) which I want to generate separate java
> .properties files from.
>
> What I ideally want to do is have a template which can
> be used for every language, and just repeatedly apply
> it, changing the language each time.
> I can't seem to find a way of doing this with
> stringTemplate.
> (I Think I'm basically asking - can I doubly nest
> attribute references for property refs - i.e.
> String.<<language>Text> where if language was
> "English" String.getEnglishText() would be called?
Hi Mark. Sure you can. Use <(attr)()> to instantiate the template
whose name is stored in attr rather than creating an attr template
like <attr()> does. Will that help? You can also do <aMap.
(keyNameInAttr)> to get the value for a key name stored in an
attribute. :)
Also try <x.(language+"Text")>, etc... Ain't that cool?
> Note: I'm looking at different "engines" comparing
> usability, ease of writing, running templates for
> re-writing a code generator which uses horrible string
> concatenation...
Yes, that is the pain. ST is the answer. I guarantee that the ANTLR
v3 code generator is extremely complicated and that all backends are
completely encapsulated in templates with no model-based computation
nor is there a single char literal from the model that is emitted.
Ter
More information about the stringtemplate-interest
mailing list