[antlr-interest] Template rewrite problem?

Hill, Robert rhill03 at eds.com
Wed Nov 15 07:42:18 PST 2006


On a string template re-write, the code generated by the following rule

: ^(BLOCKCODE BlockCode) -> {%{$BlockCode.text}}
| ^(LINECODE LineCode)  {System.out.println($LineCode.text);} ->
{%{$LineCode.text}}


Does not handle the template creation for LineCode correctly, in the
generated Java I get

// TEMPLATE REWRITE
                    // 99:26: -> {%{$LineCode.text}}
                    {
                        retval.st = new
StringTemplate(templateLib,$LineCode.text);
                    }
(it doesn't seem to want to reference the Tree for the LineCode variable
in the action?)
however it does reference $LineCode correctly in the action code.  :

             System.out.println(LineCode4.getText());


The code generation for the BLOCKCODE alt is fine, and the template
creation is ok.

// TEMPLATE REWRITE
                    // 98:27: -> {%{$BlockCode.text}}
                    {
                        retval.st = new
StringTemplate(templateLib,BlockCode3.getText());
                    }


I have done a work around thus
@init {
String code;
} 
	: ^(BLOCKCODE BlockCode) -> {%{$BlockCode.text}}
	| ^(LINECODE LineCode)  {code = $LineCode.text;} -> {%{code}}
;


Can anyone throw any light on this odd behaviour?

Cheers!

Rob

Robert Hill
Information Engineer
UKIMEA DWP ACU, Hallamshire Business Park, 100 Napier St, Sheffield. S11
8HD
email:	rhill03 at eds.com
Office:	+44 114 291 1928
Mobile:	+44 7903 185 516


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


More information about the antlr-interest mailing list