E4180#
Compiler diagnostic name: unsupported_match_strategy.
Unsupported lexmatch match strategy.
lexmatch only supports the default first-match strategy and the explicit
longest strategy. Other strategy names are rejected.
Erroneous example#
The following example asks for an unsupported shortest strategy:
///|
fn classify(input : String) -> String {
lexmatch input with shortest {
"if" => "keyword"
_ => "identifier"
}
}
///|
test {
ignore(classify)
}
MoonBit will report an error.
Suggestion#
1 回の真偽値チェックで十分な場合は正規表現マッチ式に書き換え、最長一致でケースを選択する場合は 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")
}