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

Jim Idle jimi at temporal-wave.com
Fri Sep 10 15:06:40 PDT 2010


Look at the examples and find 'island grammars', If your switch over can be
triggered lexically, then it is very easy.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Luis Pureza
> Sent: Friday, September 10, 2010 2:37 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Parsing portions of the input with different
> grammars.
> 
> 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
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address



More information about the antlr-interest mailing list