[antlr-interest] Non-greedy lexer rule in ANTLR4
Terence Parr
parrt at cs.usfca.edu
Fri Oct 12 15:56:58 PDT 2012
oh. if no newline and such what Bart suggests might be best. maybe '<<' (~[\r\n] | .)* '>>' which is nongreedy
T
On Oct 12, 2012, at 3:50 PM, Terence Parr wrote:
> would '<<' .* '>>' work?
> Ter
> On Oct 12, 2012, at 10:17 AM, Bart Kiers wrote:
>
>>> Is it possible to write a non-greedy lexer rule that does not contain a
>>> dot in ANTLR4? For example:
>>>
>>> ANCHOR
>>> : '<<' ( ~( '>>' | '\r' | '\n' ) )* '>>'
>>> ;
>>>
>>
>> Hi Michel,
>>
>> You can't negate two (or more) characters: negation only works for
>> char-sets that match a single character.
>>
>>
>>
>>> I'm using 4.0b2 and the above seems to be greedy.
>>>
>>> Alternatively, would it be possible to rewrite this rule so it includes
>>> everything from '<<' to the first '>>' but not more?
>>>
>>
>> Try something like this:
>>
>> ANCHOR
>> : '<<' ( ~( '>' | '\r' | '\n' ) | '>' ~'>' )* '>>'
>> ;
>>
>> regards,
>>
>> Bart.
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list