Trying to understand Lezer grammar for String

I’m learning how to write Lezer grammars. I need help understanding how the Lezer rule for a string works:

String {
    '"' (![\\\n"] | "\\" _)* '"'? |
    "'" (![\\\n'] | "\\" _)* "'"?
  1. What does the _ before the right parentheses do? Match a single ASCII character?
  2. Why is the optional repetition operator ? used? Isn’t the closing quotation mark required to end a string?
1 Like

A single character in general, not just ascii.

Because these grammars are mostly meant for highlighting, you’ll usually prefer to have an unterminated string tokenized as a string. (That does mean that you can’t use the grammar, with the strict option, to validate a script file, since it’ll also accept nonconforming programs.)

1 Like