E4222

E4222#

Compiler diagnostic name: invalid_lexscan_target.

Invalid lexical matching target.

lexmatch accepts an in-memory String or StringView. lexscan accepts an in-memory @lexbuf.StringScanner, a synchronous @lexbuf.Lexbuf, or an asynchronous @lexbuf.AsyncLexbuf. A String or StringView value is not a valid lexscan target; use lexmatch for one in-memory match, or construct a StringScanner to maintain a cursor between scans. Other values, such as numbers or user-defined lexbuf-like types, cannot be matched by these expressions.

Erroneous example#

///|
pub fn scan_text(text : String) -> Unit {
  lexscan text with longest {
    _ => ()
  }
}

Suggestion#

Use lexmatch with a string-like value, or create a StringScanner, Lexbuf, or AsyncLexbuf for lexscan.

///|
pub fn match_text(text : String) -> Unit {
  lexmatch text with longest {
    _ => ()
  }
}