[antlr-interest] Reuse of tokens and rules
Emond Papegaaij
e.papegaaij at student.utwente.nl
Sun Jul 2 23:49:00 PDT 2006
On Saturday 01 July 2006 21:20, Thomas Brandon wrote:
> No problem, though note, as Ter says, that just having your lexer rule
> handle the whole action block and then parsing the resulting string to
> another parser may be a more straightforward option.
> So, to handle multiple languages you could have something like:
> ACTION:
> ( {isPython}? a=PYTHON_ACTION
>
> | {isJava}? a=JAVA_ACTION
>
> ...
> ) { parseAction($a.text); }
>
> fragment PYTHON_ACTION ...;
This will lead to many lexer rules matching almost everything, with a
predicate to enable them. Right now I'm already hitting the limit of what
ANTLR can handle with ambiguous lexers. I need several rules, both lexer and
parser, for every language. Keeping them together in a single grammar file
will make it a lot easier to maintain them. It also means I can reuse the
same grammar file in multiple parsers (I actually need 2 parsers with
embedded actions).
Thanks for the help.
Best regards,
Emond
More information about the antlr-interest
mailing list