E4182

E4182#

Compiler diagnostic name: regex_constant_ref_in_lex_is_not_supported.

此诊断描述的是早期词法模式形式的一项限制,当前编译器不会发出该诊断。

当前的 lexmatchlexscan 分支接受正则常量表达式,包括具名 const 值。

错误示例#

以下历史示例使用了旧模式形式:

///|
const WORD = re"[A-Za-z]+"

///|
pub fn match_word(input : String) -> Unit {
  lexmatch input with longest {
    (WORD, _) => ()
    _ => ()
  }
}

当前代码应改为将正则常量用作分支模式。

建议#

直接将正则常量用作分支模式:

///|
const WORD = re"^[A-Za-z]+$"

///|
pub fn match_word(input : String) -> Unit {
  lexmatch input with longest {
    WORD => ()
    _ => ()
  }
}