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

Kailey Joanette kaileyjo at bigbluebubble.com
Thu Mar 22 10:12:00 PDT 2007


And yet.the first half of the rule works fine ATM. mods actually expands
quite nicely, it's the <rest> bit that breaks

 

Kailey

 

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

 

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/bf0fb6d9/attachment-0001.html 


More information about the antlr-interest mailing list