E4185#
Compiler diagnostic name: invalid_lex_pattern.
此诊断描述的是早期字符串片段形式的 lexmatch 模式,当前编译器不会发出该诊断。
当前的词法分支包含一个正则常量表达式,并可选择使用所选匹配模式支持的 as、before= 和 after= 绑定。
错误示例#
下面的模式包含了过多的顶层部分:
///|
fn classify(input : String) -> String {
lexmatch input with longest {
("a", before, "b", after) => before.to_owned() + after.to_owned()
_ => "none"
}
}
///|
test {
ignore(classify)
}
当前代码应改用正则分支语法。
建议#
请使用当前的 lexmatch 分支模式;如果只需要布尔结果,则使用正则匹配表达式:
///|
fn classify(input : String) -> String {
if input =~ (re"a" + re"b", before~, after~) {
before.to_owned() + after.to_owned()
} else {
"none"
}
}
///|
test {
inspect(classify("xabz"), content="xz")
}