[antlr-interest] Problem #2: template lists expanding to weird stuff?

Peter Nann peter.nann at vecommerce.com.au
Wed Apr 16 17:54:26 PDT 2008


Thanks Terrence, that did the trick.
 
But I don't recall seeing that {<it.text>} construct in the examples I
copied from...
Can't remember the root example right now...
 
Anyway, figured out what that magic meant from StringTemplate
cheat-sheet...
 
Cheers.
 
________________________________

From: Terence Parr [mailto:parrt at cs.usfca.edu] 
Sent: Thursday, 17 April 2008 1:42 AM
To: Peter Nann
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Problem #2: template lists expanding to
weird stuff?


toString is called on all objects.  that is Token.toString().  use the
.text property of each 

<items:{<it.text>}; separator=", ">

Ter

On Apr 16, 2008, at 7:47 AM, Peter Nann wrote:



	Now, my grammar has a more serious template using Lists and the
'+=' operator. 

	It is getting rather strange expanded output which looks like: 

	        <one-of> [@2,2:2='x',<4>,1:2] </one-of> 


	What the heck is going on there? 
	It looks like the List object has expanded itself using some
strange toString() method. 

	Any clues on this one? 


	Updated grammar: 

	---------------------- 
	grammar Test; 
	options {output=template; rewrite=true;} 

	test 
	        : '[' ( items+=WORD )* ']' 
	                -> template(items={$items}) 
	                        << \<one-of\> <items; separator=", ">
\</one-of\> >> ; 
	        
	WORD : ('a'..'z'|'-'|'_'|'\'') ('a'..'z'|'-'|'_'|'\'')* ; 
	WS : ( ' ' | '\t' | '\r' | '\n' )+ {$channel = HIDDEN;} ; 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080417/ac0f320d/attachment-0001.html 


More information about the antlr-interest mailing list