[antlr-interest] Minor suggestion re. Java output

Olivier Lefevre lefevrol at yahoo.com
Sat Feb 2 12:13:04 PST 2008


To make things a little nicer in client code,
ANTLR could covariantly specialize return types
in return classes. E.g., when you have

options {
         output = AST;
         ASTLabelType=CommonTree;
}

in the grammar the xxx_return classes in the
Parser could have a method

    public CommonTree getTree() { return tree; }

instead of

    public Object getTree() { return tree; }

That way we wouldn't need to cast. Since one
goal of ANTLR is to emit code that doesn't look
too wildly different from what one might have
written by hand I think it makes sense to try
to make the code more idiomatic.

Regards,

-- O.L.



More information about the antlr-interest mailing list