# 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

```{literalinclude} /sources/error_codes/4222_error/top.mbt
:language: moonbit
```

## Suggestion

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

```{literalinclude} /sources/error_codes/4222_fixed/top.mbt
:language: moonbit
```
