[antlr-interest] wildcard in tree grammar
Oliver Zeigermann
oliver.zeigermann at gmail.com
Wed Nov 26 12:45:08 PST 2008
2008/11/26 Gavin Lambert <antlr at mirality.co.nz>:
> At 09:14 27/11/2008, Oliver Zeigermann wrote:
>>Too bad for me as I have this in a tree parser (rule is spelled
>>with 3xe on purpose):
>>
>>treee
>> : ^(. treee* )
>> ;
>>
>>which will never come to see the "treee*" part as the first "."
>>matches the complete subtree making my analysis (code is left out
>>for clarity) defunct.
>>
>>Or am I missing something here (as usual).
>
> I'm not sure how Ter ended up implementing it, but I don't think there
> should be any problem with what you have here.
>
> A wildcard in the 'root' position can only be a single node, because you
> can't have a subtree as a root. So the meaning of the above shouldn't have
> changed.
I agree with what you say, but in 3.1 this special wildcard consumes
the full subtree.
> Although incidentally, I would expect the above to fail to match if you have
> anything other than subtrees; ie. while it should match this:
>
> ^(FOO ^(BAR ^(BAZ)) ^(WIBBLE))
>
> I would expect it to fail to match this:
>
> ^(FOO ^(BAR BAZ) WIBBLE)
Right. That would be what I had expected as well. But in 3.1 it works
the way described above.
Would you agree that chaning the rule to
treee
: ^(. treee* )
| .
;
should make it accept the second tree as well?
Oliver
More information about the antlr-interest
mailing list