[antlr-interest] BUG - ANT plugin for Antlr3 does not parse "parser grammar" at top of file (Workaround)
Austin Hastings
Austin_Hastings at Yahoo.com
Wed Oct 10 06:50:28 PDT 2007
The Ant task to support ANTLR3 calls a private routine called
"getGeneratedFile" to parse the header of the source grammar file. This
is done to determine the name of the output file, in order to compare
the "output" file with the "input" file to determine if the input has
been modified.
The pattern used is about line 446 of ANTLR3.java:
Pattern p =
Pattern.compile("^\\p{javaWhitespace}*(grammar|lexer\\p{javaWhitespace}+grammar|tree\\p{javaWhitespace}+grammar)\\p{javaWhitespace}+\\w+\\p{javaWhitespace}*;.*$",
Pattern.CASE_INSENSITIVE|Pattern.CANON_EQ);
The pattern is not aware of the keyword 'parser' that can appear in
parser-only grammar files. Essentially, it checks for lines like:
grammar T;
lexer grammar T;
tree grammar T;
but doesn't check for:
parser grammar T;
The solution is obvious - include 'parser' as a valid keyword in the
pattern.
A workaround lies in the fact that the ant task is using line-oriented
parsing. Change the header of your "parser grammar" from this:
parser grammar T;
options { blah blah blah }
to this:
parser grammar T;
/* Work around bug in Ant task: (word 'grammar' must be at start of
line, modulo whitespace)
grammar T; */
options { blah blah blah }
Making sure that the grammar name (T) is correctly spelled in the comment.
=Austin
More information about the antlr-interest
mailing list