[antlr-interest] How to use StringTemplate in Antler 3

Hugo Garcia hugo.a.garcia at gmail.com
Thu Nov 9 06:58:36 PST 2006


hi

newbie here.

I am using Parr's Java grammar. I am trying to figure out how to get a
simple usage of StringTemplate working so....

I did this (almost straight from the docs):

http://www.antlr.org/wiki/pages/viewpage.action?pageId=719

<snip>

grammar JavaParser;
options {k=2; backtrack=true; memoize=true; output=template;}
...
importDeclaration
	:	'import' 'static'? Identifier ('.' Identifier)* ('.' '*')? ';'
	-> import(name={$Identifier.st},
                begin={$Identifier.start},
                end={$Identifier.stop})
	;

</snip>

I run antlr from command line to generate the JavaParser and JavaParserLexer.

I get the folloing in the code of JavaParser.java :

<snip>

            match(input,25,FOLLOW_25_in_importDeclaration121); if
(failed) return retval;

            // TEMPLATE REWRITE
            if ( backtracking==0 ) {
              // 50:2: ->
import(name=$Identifier.stbegin=$Identifier.startend=$Identifier.stop)
              {
                  retval.st = templateLib.getInstanceOf("import",
                new STAttrMap().put("name",
Identifier1.st).put("begin", Identifier1.start).put("end",
Identifier1.stop));
              }

            }

            }

</snip>

which generates an error where

'Identifier1*' cannot be resolved.

-------

what am I missing? something I should further read?

-H


More information about the antlr-interest mailing list