[antlr-interest] changed 'x' to "x" for v3

Ric Klaren ric.klaren at gmail.com
Sat Nov 26 16:04:33 PST 2005


On 11/26/05, Terence Parr <parrt at cs.usfca.edu> wrote:
> 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\"");
>         }

Just a thought: Isn't it easier then to use single quotes in stead of
double quotes for everything ? Assuming that double quotes are used
more often.

Ric


More information about the antlr-interest mailing list