E4222

E4222#

编译器诊断名称:invalid_lexscan_target。

无效的词法匹配目标。

lexmatch 接受内存中的 String、StringView、Bytes 或 BytesView。lexscan 接受内存中的 @lexbuf.StringScanner、同步的 @lexbuf.Lexbuf 或异步的 @lexbuf.AsyncLexbuf。String 或 StringView 不是合法的 lexscan 目标;单次内存匹配使用 lexmatch,需要在多次扫描间维护游标时则构造 StringScanner。这些表达式不接受数字或用户定义的类似 lexbuf 的类型等其他值。

错误示例#

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

建议#

对文本或字节使用 lexmatch,或构造 StringScanner、Lexbuf、AsyncLexbuf 供 lexscan 使用。

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