[antlr-interest] Whitespace matching

Jason Jones jmjones5 at gmail.com
Thu Apr 12 13:48:39 PDT 2012


Hi Bart,

Thanks for the suggestion, although it doesn't work either... The skip
option does work but since I'll be doing something with the whitespace
later I don't want to take this option. Is there something else we're
missing?

Jason.

On 12 April 2012 19:10, Bart Kiers <bkiers at gmail.com> wrote:

> Hi Jason,
>
> On Thu, Apr 12, 2012 at 6:43 PM, Jason Jones <jmjones5 at gmail.com> wrote:
>
>> ...
>>
>>
>> start : program ;
>> program : WHITESPACE line+ WHITESPACE (query WHITESPACE)*;
>>
>> WHITESPACE  : (' ' | '\t' | '\r' | '\n')* ; //currently only used in
>> string
>>
>>
> A lexer rule must always match something: if it can match zero chars, it
> can/will go in an infinite loop.
>
> Do something like this:
>
> start : program ;
> program : WHITESPACE? line+ WHITESPACE? (query WHITESPACE?)*;
> WHITESPACE  : (' ' | '\t' | '\r' | '\n')+ ;
>
> or simply skip spaces like this:
>
> start : program ;
> program : line+ query*;
> WHITESPACE  : (' ' | '\t' | '\r' | '\n')+ {skip();} ;
>
> Regards,
>
> Bart.
>


More information about the antlr-interest mailing list