E4183

E4183#

Compiler diagnostic name: regex_interpolation_is_not_supported.

lexmatch 模式不支持正则插值。

lexmatch 模式会作为匹配的一部分被编译。它们必须是已知的正则字面量模式,而不能通过字符串或正则插值构造。

错误示例#

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

该正则模式尝试插入 part

修改建议#

lexmatch 分支中使用字面量模式。对于动态正则匹配,请构造正则值,并使用正则匹配表达式,而不是 lexmatch

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