[antlr-interest] Tree Rewrite Issue with Negation (~)
Foust
javafoust at gmail.com
Wed Jul 30 17:00:10 PDT 2008
At 2:08 PM Gavin Lambert wrote:
> At 05:44 31/07/2008, Foust wrote:
> >Although this works (nonsense):
> >x : ':' ( v+=(';'|'}') )* ';' -> ^(':' $v) ;
>
> Last time I checked, that wouldn't have worked either (= and +=
> didn't work against blocks; you had to use an extra rule).
Yes, the content may not have all been there -- just generated the grammar
successfully (no internal error).
Page 146 of the DAR only shows an example using a single token "ids+=ID (','
ids+=ID)*", but it just seemed like a logical extension that it would work
for synthetic tokens specified as an inline union, as well. The tilde
operator is doing its job on the union of tokens -- it's just the +=
operator that's having trouble storing the result.
And that's probably what causes the internal error when a tree rewrite rule
is added, because only then is the value of $v actually used.
This seems like something that would make sense to support, although in the
mean time, a better error message would help.
>
> Or possibly it still hasn't been fixed -- depends what definition
> of "works" you're using. Certainly in older versions of ANTLR,
> the above would compile perfectly fine but would lead to null
> references or empty lists at runtime instead of providing the
> content you're expecting.
>
> (And incidentally, that should have been $v* in the rewrite.)
Yes, thank you for your comments and for looking so closely.
Brent
More information about the antlr-interest
mailing list