[antlr-interest] Whitespace matching
Bart Kiers
bkiers at gmail.com
Thu Apr 12 14:06:24 PDT 2012
Hi Jason,
Then there's something other than what you've posted going wrong, since the
parser generated from:
start : program EOF;
program : WHITESPACE line+ WHITESPACE (query WHITESPACE)*;
line : 'L';
query : 'Q';
WHITESPACE : (' ' | '\t' | '\r' | '\n')+;
parses the input "\r\nL\r\n" just fine.
Regards,
Bart.
On Thu, Apr 12, 2012 at 10:48 PM, Jason Jones <jmjones5 at gmail.com> wrote:
> 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