[antlr-interest] CommonErrorNode and using ASTLabelType (3.0.1 -> 3.1.1)

Bruno Marc-Aurele bruno.marc-aurele at polymtl.ca
Sat Feb 14 15:33:00 PST 2009


I don't know what would be recommended, but I also need to have an ErrorNode
that derives from my custom node.

What I did is I overloaded the errorNode method in my NodeAdaptor to tkae as an
input a CustomErrorNode error node. My CustomErrorNode class derives from my
CustomNode and is actually only a wrapper of CommonErrorNode. That way, there
are no class cast exceptions AND I get the full functionnality or error nodes.

Hope that helped,
Bruno M-A.


Selon Matthieu Riou <matthieu at offthelip.org>:

> Hi,
>
> I've just migrated from 3.0.1 to 3.1.1 and the new use of CommonErrorNode to
> handle errors is giving some pain. I use my own AST tree type, so in my
> grammar I have:
>
> options {
>     output=AST;
>     language=Java;
>     ASTLabelType=LinkedListTree;
> }
>
> But it seems that ANTLR casts a little too generously in the generated
> parser as I end up with code like this in all catch blocks:
>
>         retval.tree = (LinkedListTree)adaptor.errorNode(input, retval.start,
> input.LT(-1), re);
>
> The method call returns a CommonErrorNode which can't be cast to my tree
> implementation, resulting in a ClassCastException. I'm wondering wheter my
> tree should extend CommonErrorNode instead of BaseTree but the
> CommonErrorNode implementation (especially the constructors) look fairly
> specific to error handling.
>
> What would be the recommended solution here?
>
> Thanks!
> Matthieu
>



More information about the antlr-interest mailing list