[antlr-interest] Template application questions

Johannes Luber jaluber at gmx.de
Tue Jun 26 15:34:34 PDT 2007


Hello!

I have the following rule:

element
   :   e=(atom|block) ebnfSuffix? -> ???
   ;

I have to generate different a different template depending on the type
of the optional token. Below there is a version, in which I replaced by
all of its alternatives. But this results in a wordy rule and requires
syntactic predicates.

element
   :   (. OPTIONAL)=> e=(atom|block) OPTIONAL -> Optional(name={$e.st})
   |   (. CLOSURE)=> e=(atom|block) CLOSURE -> ZeroOrMore(name={$e.st})
   |   (. POSITIVE_CLOSURE)=> e=(atom|block) POSITIVE_CLOSURE
	-> OneOrMore(name={$e.st})
   |   e=(atom|block) -> {$e.st}
   ;

How can I generate a template depending on the type and presence of
ebnfSuffix? And another problem: The generated code for the replacement
rule complains, the $e.st has no st-attribute, as it is a CommonTree. I
don't understand what I've done wrong, as in every other rule this
construct works. The whole is attached.

Best regards,
Johannes Luber

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ANTLR3ToRelaxNGGenerator.g
Url: http://www.antlr.org/pipermail/antlr-interest/attachments/20070627/b016739a/attachment.pl 


More information about the antlr-interest mailing list