[antlr-interest] Template application questions

Johannes Luber jaluber at gmx.de
Wed Jun 27 09:43:42 PDT 2007


Terence Parr wrote:
> You could use sem preds after the -> that tests the type of suffix
> matched.  I think input.LA(-1) should do it.

I've changed the rule into:

element
   :   (a=atom|b=block) ebnfSuffix? ->
       { (input.LA(-1) == OPTIONAL) ?
           templateLib.GetInstanceOf("Optional",
                new STAttrMap().Add("name", ($a!=null)?$a.st:$b.st)) :
       (input.LA(-1) == CLOSURE) ?
           templateLib.GetInstanceOf("ZeroOrMore",
                new STAttrMap().Add("name", ($a!=null)?$a.st:$b.st)) :
       (input.LA(-1) == POSITIVE_CLOSURE) ?
           templateLib.GetInstanceOf("OneOrMore",
                new STAttrMap().Add("name", ($a!=null)?$a.st:$b.st)) :
       ($a!=null)?$a.st:$b.st;
       }			
    ;

Basically it says: Which type is the last token? Depending on that, it
will apply a new template on the atom or block, whichever was selected.
Problem is that I have to test if $a or $b are null, but I get the
following error message:

error(117): ANTLR3ToRelaxNGGenerator.g:201:3: missing attribute access
on rule scope: a

How do I solve this problem?

Best regards,
Johannes Luber

P.S.: Terence, are you already back in the USA?


More information about the antlr-interest mailing list