[antlr-interest] Template application questions
Terence Parr
parrt at cs.usfca.edu
Tue Jun 26 19:00:20 PDT 2007
On Jun 27, 2007, at 8:34 AM, Johannes Luber wrote:
> 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}
> ;
You could use sem preds after the -> that tests the type of suffix
matched. I think input.LA(-1) should do it.
Ter
More information about the antlr-interest
mailing list