[antlr-interest] Non-greedy lexer rule in ANTLR4
parrt at cs.usfca.edu
Fri Oct 12 15:50:03 PDT 2012
would '<<' .* '>>' work?
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:
>> : '<<' ( ~( '>>' | '\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:
> : '<<' ( ~( '>' | '\r' | '\n' ) | '>' ~'>' )* '>>'
> 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