[antlr-interest] Parsing portions of the input with different grammars.

Luis Pureza pureza at gmail.com
Fri Sep 10 14:37:24 PDT 2010


Hi,

Is there any way i can parse a portion of text using a rule from
grammar A, while parsing the rest of the text with grammar B?

More concretely, I have an expression grammar which is central to my
project and used everywhere. But now, I need to parse new kinds of
inputs which may contain expressions inside. For this, I'm creating a
new grammar. However, I'd like to reuse the old grammar just to parse
the expressions. I don't want to modify it because it is a generic
grammar and the new use-case is too specific. Moreover, I'd prefer not
to copy the entire grammar verbatim into the new one, because then I'd
have two expression grammars to maintain.

What I really want is some mechanism that allows me to express "Parse
the entire thing with grammar A, except expressions, which are
delegated to the Expression grammar".

What is the best way to achieve this?

Thank you,

Luís Pureza


More information about the antlr-interest mailing list