[antlr-interest] Grammar generation results in exception

Thomas Brandon tbrandonau at gmail.com
Mon Jun 25 05:44:13 PDT 2007


On 6/25/07, Johannes Luber <jaluber at gmx.de> wrote:
> Hello!
>
> I've been working on a ANTLR3-to-RelaxNG converter based on Terence's
> ANTLRv3.g. When I want to generate the corresponding C#-files, I receive
> following output:
>
> ANTLR Parser Generator  Version 3.0 (May 17, 2007)  1989-2007
<SNIP>
> error(10):  internal error: ANTLR3ToRelaxNG.g :
> java.lang.IllegalArgumentException: Can't find template
> tokenRefRuleRootTrack.st
<SNIP>
> Lies the error with mine code or is it an ANTLR bug? The file is
> attached. And if I didn't change the license text correctly, please let
> me know!
>
> Best regards,
> Johannes Luber
>
This error is because you have mixed rewrites and AST building
operators (! and ^) in a single rule. In this case the error is
because you have used '^' (as an operator on a token, not in the
rewrite itself) as well as rewrites in your element element rule. Your
atom and ebnf rules also mix rewrites and AST operators.
Due to the lack of location information these errors can be tricky to
track down. Slowly removing (or adding to a new grammar) rules until
you find the error can help. Though due to dependencies between rules
this can be tricky.
Another trick is to introduce the other sort of error, either a !
(tokenRefBangTrack.st error) or a ^ (tokenRefRuleRootTrack.st error)
in a rule with rewrites. For instance, as you have a ^ error adding a
! to a rule before the (first) rule giving the error will change the
error given to a tokenRefBangTrack.st error, by moving the location
where you insert the error through your grammar until the message does
not change you can locate the error.
I assume these errors will be better dealt with when Ter migrates to
an ANTLR 3 grammar in the tool.

Tom.


More information about the antlr-interest mailing list