[antlr-interest] Problem with rewrite rule referencing the previous value of the AST

Mats Behre mb.fgel at ownit.nu
Tue Oct 23 15:13:08 PDT 2007


Hi,

I am in the process of converting a v2 grammar to v3, and have some rules that (I would like to) look basically like this:

	optionCmd: p=OptionKeyword (Dot!)? (
			t=StrictKeyword
			| t=MaxDurationKeyword intData
		) -> ^(GenericStatement $optionCmd);

The problem is that when I have the exclamation mark after the optional Dot token, I get a "Can't find template tokenRefBangTrack.st" exception.
The exception itself is obviously just a missing template, but it seems to indicate that when I want to reference the tree 'so far' in a rewrite rule, I am not allowed to exclude any of the matched parts.
Is this a correct assumption, or should my rule work?

I know that I can work around this by having several rewrite rules instead of just one, but that would make the grammar less readable, so I would prefer not to do it.
An equivalent construct worked fine in v2, but then the rule generation has changed dramatically, so I'm not really surprised that there are differences. Generally it appears that the grammar will be more readable in v3, except that I have to add many 'options {k = 1;}' followed by a syntactic predicate where earlier 'options {greedy = true;}' made the job.

Rgds,
Mats 



More information about the antlr-interest mailing list