[antlr-interest] changed 'x' to "x" for v3
Terence Parr
parrt at cs.usfca.edu
Sat Nov 26 14:44:26 PST 2005
Next time you grab a release of ANTLR v3, you'll note that all char
literals must be string literals. All unit tests and examples have
changed. So, you'll now do
INT : "0".."9"+ ;
instead of
INT : '0'..'9'+ ;
I thought a lot about this and I just can't justify wasting single
quotes on char literals; it's actually easier to say that all
literals matched are in double quotes. Made a number of routines
easier in ANTLR.
The only negative so far is that all the unit tests have grammars
that are String literals in the Java program and so the grammars have
to have the double quote escaped. This is hideous, but I'm not sure
we have a choice. Here's a taste:
public void testParserCharLiteralWithEscape() throws Exception {
Grammar g = new Grammar(
"grammar t;\n"+
"a : \"\\n\";\n");
Set literals = g.getStringLiterals();
// must store literals how they appear in the antlr grammar
assertEqual(literals.toArray()[0], "\"\\n\"");
}
Ter
More information about the antlr-interest
mailing list