E4180#
Compiler diagnostic name: unsupported_match_strategy.
不支持的 lexmatch 匹配策略。
lexmatch 只支持默认的首次匹配策略,以及显式的 longest 策略。其他策略名会被拒绝。
错误示例#
下面的示例请求了不支持的 shortest 策略:
///|
fn classify(input : String) -> String {
lexmatch input with shortest {
"if" => "keyword"
_ => "identifier"
}
}
///|
test {
ignore(classify)
}
MoonBit 会报告一个错误。
建议#
如果单个布尔检查就足够,请使用正则匹配表达式重写代码;如果需要按最长匹配选择分支,则使用 lexmatch ... with longest:
///|
fn classify(input : String) -> String {
if input =~ re"^if$" {
"keyword"
} else {
"identifier"
}
}
///|
test {
inspect(classify("if"), content="keyword")
inspect(classify("gift"), content="identifier")
}