[antlr-interest] Rule automation
John B. Brodie
jbb at acm.org
Wed Sep 9 12:50:57 PDT 2009
Greetings!
On Wed, 2009-09-09 at 10:45 +0200, Martin Potier wrote:
> I've got something on my mind that the Definitive ANTLR Reference
> couldn't solve (yet, I'm not tottally through it).
> Is there a way with ANTLR v3 to automate some rule ?
>
> Id est, while building a small wiki language I wrote this kind of rule :
> text
> : (PURETEXT ( inlinenv | PURETEXT )*)
> | (inlinenv (PURETEXT | inlinenv)*)
> ;
>
> In fact, I use the same sort of rule every time I introduce text in a
> inlinenv.
>
> I'd like to know if there's a way to create a generic rule like the
> following :
> generic altern ((ARG1, ARG2))
> : (ARG1 (ARG2 | ARG1)*)
> | (ARG2 (ARG1 | ARG2)*)
> ;
>
> And then reuse it, like an operator ?
>
>
As earlier replies have stated ANTLR does not do that (at the moment
anyway).
But I just wanted to point out to you that any rule of the form:
any_rule
: ( arg1 ( arg2 | arg1 )* )
| ( arg2 ( arg1 | arg2 )* )
;
is the same as:
any_rule : ( arg1 | arg2 )+ ;
might save you some keyboarding in your .g file....
Not much value added, but hope this helps.
-jbb
More information about the antlr-interest
mailing list