[antlr-interest] Quoted Strings in ANTLR 3.0.1 and 3.1.1

Gavin Lambert antlr at mirality.co.nz
Thu Oct 23 01:05:41 PDT 2008


At 18:43 23/10/2008, Fromm, Stefan wrote:
 >QUOTED_STRING
 >	:	'\'' ( '\'\'' | ~('\'') )* '\'';

This could be a little tricky, since your single termination 
character is also permitted within the content, and ANTLR 
sometimes only uses single-character lookahead.  It might be a 
good idea to force explicit lookahead:

QUOTED_STRING
   : '\''
     ( ('\'\'') => '\'\''
     | ~'\''
     )*
     '\''
   ;

 >value_expr
 >  :	QUOTED_STRING | NUMBER;

Note that this by itself will only match one quoted string or 
number.  If you want to match more than one you'll need to wrap it 
in a * or + block (or call it from another rule that does so).

Also, your top-level rule should end with EOF if you want parsing 
to fail if it cannot match the complete input.



More information about the antlr-interest mailing list