[antlr-interest] book, online doc discrepancy?

Benjamin Niemann pink at odahoda.de
Thu Jan 17 13:15:19 PST 2008


Hi Mathew,

Mathew Yeates wrote:

> Using StringTemplate the book says to do (using Python)
> 
> hello=stringtemplate.StringTemplate("Hello, <name>")
> hello.setAttribute("name","World")
> print hello.toString() #is an error :AttributeError: 'StringTemplate'
> object has no attribute 'toString'
> 
> if I do
> print str(hello) I get Hello, <name>
> 
> But the online docs say to use $name$ and hello["name"] = "World"
> and this works.

Please note that, if you want to use ANTLR in conjunction with
StringTemplate and Python, you'll have to use the stringtemplate3 package
that you can download from the StringTemplate site or the pypi.

I think the old stringtemplate (V2.x) package did not have a toString method
and only implemented __str__, but V3 has both - and str() will actually
throw an exception, if you work with unicode strings, so I recommend to use
toString.

I think there was also a change of the default lexer between V2 and V3 and
the book refers to V3.

hello.setAttribute("name","World") and hello["name"] = "World" should be
equivalent.

-Ben

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/



More information about the antlr-interest mailing list