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

修改建议#

使用 lexscan 和正则字面量模式。对于动态正则匹配,请构造正则值并改用正则匹配表达式。

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