E4180

E4180#

Compiler diagnostic name: unsupported_match_strategy.

不支持的 lexmatch 匹配策略。

lexmatch 只支持默认的首次匹配策略,以及显式的 longest 策略。其他策略名会被拒绝。

警告

新代码中已弃用 lexmatch。布尔检查请优先使用 value =~ re"..." 这类正则匹配表达式,基于 case 的扫描请使用 lexscan

错误示例#

下面的示例请求了不支持的 shortest 策略:

///|
fn classify(input : String) -> String {
  lexmatch input with shortest {
    "if" => "keyword"
    _ => "identifier"
  }
}

///|
test {
  ignore(classify)
}

MoonBit 会报告一个错误。

建议#

如果首次匹配行为已经足够,请用正则匹配表达式重写代码;需要最长匹配扫描时,请使用 lexscan ... 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")
}