[antlr-interest] StringTemplate "reflection" enhancement

Terence Parr parrt at cs.usfca.edu
Sat Sep 25 13:31:00 PDT 2004


Howdy,

When debugging templates particularly for web pages with lots of nested 
templates, printing out the list of attributes you've set with 
setAttribute() is pretty handy.  You could, for example, display the 
contents of all attributes at the bottom of a web page if in "debug" 
mode.  So if you had set two attributes title (a simple string) and 
user (a user-defined object), you might want this info:

Name: title
Type: java.lang.String

Name: user
Type: org.foo.MyUser
Properties: name, email, address, phone

It shows the incoming data not the references in the template.

Seems like this can be easily had by allowing templates to access the 
list of attribute name/value pairs via a reflection method.  We'd want 
this to be on-demand rather than computing a set of reflection 
descriptors each time.  Rather than make a special attribute, we should 
make it something like <self.attributes> which will on demand (when 
rendered) call getAttributes() on "self" (the template object).

<self.attributes> would return not the raw attribute data, but a 
reflection object that describes the key/value pair.  That reflection 
object would let you say:

<self.attributes:{Name: <it.name> Type: <it.type.name> Properties: 
<it.properties>}>

Further you want to be able to be able to recursively walk down to 
embedded templates and get those attributes.  You'd probably want a 
flattened list of all attributes for any particular page.  Perhaps that 
requires <self.embedded> or <self.children> so you can use 
StringTemplate to walk down to those templates. :)

All I have to do is set "self" to be a predefined attribute pointing to 
the surrounding template "this" pointer and all this will just work.  
<self.name> etc... will just work as they are getXXX methods already 
defined.

Hmm...anybody have any suggestions or problems with this approach?

Thanks,
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!





 
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