I’ve got a rule like,
charGroup
: '[' .+ ']';
But I’m guessing that’ll match something like [abc\]. Assuming I want it to match only unescaped ]s, how do I do that? In a regular expression I’d use a negative look-behind.
Edit: I’d also like it to be ungreedy/lazy if possible. So as to match only [a] in [a][b].
You probably wanted to do something like:
where
~('\\' | ']')matches a single character other than\and]. Note that you can only negate single characters! There’s no such thing as~('ab'). Another mistake often made is that negating inside parser rules does not negate a character, but a token instead. An example might be in order:Now parser rule
foomatches either tokenBor tokenC(so only the characters'b'and'c') while lexer ruleDmatches any character other than'a'.