[antlr-interest] Interesting problem with ANTLR and CSS 2.1
David Holroyd
dave at badgers-in-foil.co.uk
Fri Oct 12 13:58:01 PDT 2007
On Fri, Oct 12, 2007 at 04:23:04PM -0400, Simon Janes wrote:
> parse : stylesheet -> ^(stylesheet); /* I think this sets the "root"
> of the AST. */
> stylesheet
> : (comment_stylesheet|ruleset|media|page)* ;
> I'll get a runtime error:
>
> "more than one node as root"
I've not seen that before, but I assume the problem is that..
-> ^(stylesheet)
..attempts to make the AST referenced by 'stylesheet' be the root node of
the result AST, but in your case 'stylesheet' does not represent a
single node, but a list of nodes.
Probably you should just remove the '^'..
parse : stylesheet -> stylesheet;
..but then you might as well just remove the rewrite, because it doesn't
add anything..
parse : stylesheet;
Alternatively, you could add an 'imaginary' node to act as the root, if
you really want a single node result rather than a list..
parse : stylesheet -> ^(STYLESHEET stylesheet);
Note that for the standard ANTLR tree implementation, a 'list' of nodes
is really just a special case node:
http://www.antlr.org/api/Java/classorg_1_1antlr_1_1runtime_1_1tree_1_1_common_tree.html#670edeb282b219bc714ed9490aa5a728
ta,
dave
--
http://david.holroyd.me.uk/
More information about the antlr-interest
mailing list