[antlr-interest] StringTemplate enhancement question

Terence Parr parrt at cs.usfca.edu
Fri Jun 25 12:48:17 PDT 2004


On Jun 24, 2004, at 3:16 PM, matthew ford wrote:
>> Bob's Phone: $db.bob.phone$
>>
>> A view should not be part of the program and hence should never be 
>> able
>> to go ask for a specific person's data.  Humor me that it's good to be
>> ruthless (or read my paper <snicker>).  Is there another way to fake
>> aggregates by given separate pieces of data to ST and have it
>> aggregate?
>
> WebStringTemplates does just that.
> Given db.bob.phone
> it tries to get db from the attributes map.
> if db is a map then it uses get("bob") to get the next level object
> if db is an object it tries db.getBob() to get the next level object
> and so on recursively.
>
> Now you can only ask for a specific person's data if  you know it is  
> there.
> One thing WebStringTemplates has that StringTemplates does not is the
> concept of a Data Interface Definition file.
>
> This DID is an html file that defines all the attributes that will be
> available to the template and gives some sample data values.

Yes, with another file that limits or explicitly states what is 
available, I think I might be able to concur with this. :)

> I think you real problem is you want to supply a two lists of data 
> that are
> synchronized.
> In WebStringTemplates (and StringTemplates) this is achieved by 
> creating a
> list of objects
> that have attributes of Name and Type
>
> It seems you are looking for a way to short cut creating the objects.
> A list of  Maps seems the easiest.
>
> ArrayList items = new ArrayList();
> items.add(new HashMap() {{put("name","Ter"); put("type","342");}});
> items.add(new HashMap() {{put("name","Tom"); put("type","1342");}});
> items.add(new HashMap() {{put("name","Fred"); put("type","42");}});
> attributeMap.add("items",items);

Yep, 'cept the HashMap thing I don't want to allow as an attribute.

> Then in the template use
> $items:{$attr.name$=$attr.type$}$
>
> WebStringTemplates V2 will use the syntax
> $[list items]$
>     $[name]$=$[type]$
> $[endlist]$
>
> a la PHP. Which is more readable (IMHO :-) )

Some people like loops and some don't ;)

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!
Cofounder, http://www.peerscope.com pure link sharing





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list