[antlr-interest] Grammar handling of whitespaces

Johannes Luber jaluber at gmx.de
Thu Feb 7 07:20:32 PST 2008


Erik Kratochvil schrieb:
> Aha.
> 
> First, make a new lexer lexer rule
> ARROW : '=>';
> and then use it in the parser rule arrow
> arrow : ARROW ...whatever here...;
> 
> Does this solve your problem?

Well, the way he asks, he doesn't want to create a lexer rule for these 
special situations. So your approach is probably the wrong one.

Johannes
> 
> On 2/7/08, Johannes Luber <jaluber at gmx.de> wrote:
>> Shawn Poulson schrieb:
>>> Hello all,
>>>
>>> I've had success so far with generating my grammar for my C# target,
>>> with help from several individuals here.  One of the tips I've used is
>>> to use a lexer rule to skip whitespaces using a rule like:
>>>
>>> WS : (' '|'\r'|'\t'|'\n') { $channel=HIDDEN; }
>>>
>>> This is very helpful for most parser rules, so I don't have to
>>> explicitly put whitespaces throughout my parser rules.  But, there are
>>> times where I don't want whitespaces between certain elements.  Is
>>> there a way to handle this?
>> Untested yet, but this should work:
>>
>> arrow
>>         :       first=ASSIGNMENT second=GT {$first.index + 1 == $second.index}? //
>> Nothing between the tokens?
>>         ;
>>
>> Johannes
>>
> 
> 



More information about the antlr-interest mailing list