[antlr-interest] Need help regarding lexer

Gavin Lambert antlr at mirality.co.nz
Wed Mar 19 11:51:48 PDT 2008


At 05:08 20/03/2008, elango m wrote:
>I am just curious why STR_LITERAL : '\'' ('\'\'')* ~('\'')* '\'' 
>; didn't worked???

Because order is significant.  If you expand out each element of 
that rule and see what it means:

   '\''     : match a single quote
   ('\'\')* : match zero or more sets of two single quotes
   ~('\'')* : this is actually illegal, but in theory it's "match 
zero or more characters that aren't single quotes".
   '\''     : match a single quote

Follow that through in order, and it's obvious why it can't 
possibly match input such as "'a''bc'".  It could, however, match 
something like "'''''''''abcd'.



More information about the antlr-interest mailing list