[antlr-interest] ANTLR3 What's wrong with this ST rule?

Rob Hill rob.hill at blueyonder.co.uk
Thu Mar 22 09:20:56 PDT 2007


Hi Kailey

I think you're missing a bit of extra code here.

Anytime you use += to accumulate templates, you need to call the helper
function toTemplates() when you do the re-write.

 

try

                :               ^(CLASS_INTERFACE_DEF accessModifier?
(m+=modifier)* (n=normalClassDeclaration)? ) -> modSet(
mods={toTemplates($m)}, rest={$n.st} )

 

I wrote a little chunk on the wiki about this, because TBH, it's a bit like
finding out how to do the voodoo chicken-dance.

 

http://www.antlr.org/wiki/display/ANTLR3/Template+construction

 

cheers,

/2ob

 

 

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Kailey Joanette
Sent: 22 March 2007 15:38
To: antlr-interest at antlr.org
Subject: [antlr-interest] ANTLR3 What's wrong with this ST rule?

 

I have the following simple ST rule

 

modSet(mods,rest) ::= "<mods; seperator=\" \"><rest>"

 

And the corresponding output rule

 

classOrInterfaceDeclaration

                :               ^(CLASS_INTERFACE_DEF accessModifier?
(m+=modifier)* (n=normalClassDeclaration)? ) -> modSet( mods={$m},
rest={$n.st} )

                ;

 

When I run the parser and try to get output I end up with a crash that looks
like this:

 

parsing C:\Java_Projects\antlr_java\examples-v3\java\java\Test.java

tree=(JAVA (CLASS_INTERFACE_DEF (NORMAL_CLASS Test CLASS_BODY)))

 

action parse error in group Cpp line 10; template context is [modSet]

line 1:5: expecting LPAREN, found 'null'

        at antlr.Parser.match(Parser.java:211)

        at
org.antlr.stringtemplate.language.ActionParser.singleArg(ActionParser.java:1
084)

        at
org.antlr.stringtemplate.language.ActionParser.function(ActionParser.java:96
4)

        at
org.antlr.stringtemplate.language.ActionParser.primaryExpr(ActionParser.java
:640)

 

I don't understand why I'm ending up with null. actually I'm not sure why
it's expecting an LPAREN either.

 

If I remove the <rest> from the ST rule it works but obviously I don't get
the right output.

Kailey

 

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


More information about the antlr-interest mailing list