[antlr-interest] Pruning malformed ASTs

Jim Idle jimi at temporal-wave.com
Fri Jun 4 12:50:30 PDT 2010


You might be better off just improving the error catching capabilities of your parser such that you do not generate the error nodes in the first place. You can use the error recovery techniques shown in the Wiki article:

http://www.antlr.org/wiki/display/ANTLR3/Custom+Syntax+Error+Recovery

And then download the JavaFX parser grammar to see how to intercept errors such that you can create a tree with a defined pattern for error nodes. I think that you will need to build the tree manually to do that, but you can build an ANTLR AST, you don't have to come up with your own format.

Jim


> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Richard Thrippleton
> Sent: Friday, June 04, 2010 9:30 AM
> To: ANTLR Interest
> Subject: [antlr-interest] Pruning malformed ASTs
> 
> I am in the slightly painful situation of wanting to apply a tree
> grammar
> (type and other constraints checking) after a parser grammar even in
> the
> case that there were parse errors.
> 
> At the moment I just have the tree grammar exit at the moment that it
> encounters a malformed part of the tree; as I've seen stated on here
> before,
> there's no other sensible thing to do.
> 
> Sometimes I'm fortunate to have simple parse errors that still result
> in a
> correct tree (e.g. standalone unexpected tokens just get removed in
> recovery). For the larger parse errors I'll get an AST containing
> CommonErrorNodes which obviously trip up the tree grammar.
> 
> What I'm looking for is some common pattern or part of the ANTLR API
> that
> will allow the parser to snip subtrees at a specific granularity that
> contain error nodes as I create them. For example:
> 
> procedure:
> 	command* -> ^(PROC command*)
> 
> needs to ignore any tree coming out of the 'command' rule that contains
> error nodes.
> 
> Thanks,
> Richard
> --
> \o/
> 
> 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