[antlr-interest] StringTemplate enhancement question

matthew ford Matthew.Ford at forward.com.au
Fri Jun 25 17:44:30 PDT 2004


From: "Terence Parr" <parrt at cs.usfca.edu>
To: <antlr-interest at yahoogroups.com>
Sent: Saturday, June 26, 2004 5:48 AM
Subject: Re: [antlr-interest] StringTemplate enhancement question


>
> On Jun 24, 2004, at 3:16 PM, matthew ford wrote:
> > 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. :)
>

Hey I like this.  You could have "strict" mode in which the DID is
loaded and then when processing the  template, before looking up
the string data, the  DID map is checked to see that this attribute is
valid
eg
Given db.bob.phone   in "strict"mode
First check DID that contains  db.bob.phone, if not return an error string
or error message as appropiate,
then get db.bob.phone  from the attributes map.

Actually this is how it works in WebStringTemplates in design mode, I just
did not realize it before.
In the design stage, the web designer only has the DID to work with and if
the DID
does not contain any sample data for an attribute path, the web designer
will get an
 error message on processing. (Note the web designer designs the template
without
using any kind of server.)  So by definition an error free template in
design mode will only
access attributes contained in the Data Interface Definition file.

In deployment mode,  this check is dispensed with (usually).

> > 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.
>

You seem to be tieing your hands behind you back.

As I understand it, in StringTemplates, the top level is already a HashMap.

In WebStringTemplates V2, the top level (in fact any level) can be any
object
but typically only Lists, Maps, or Beans will be any use, except at the
lowest
level where  object.toString() is called to return the actual string data
for this
attribute.

matthew



 
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