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#
Rewrite the code with a regex match expression when a single boolean check is
enough, or use lexmatch ... with longest for longest-match case selection:
///|
fn classify(input : String) -> String {
if input =~ re"^if$" {
"keyword"
} else {
"identifier"
}
}
///|
test {
inspect(classify("if"), content="keyword")
inspect(classify("gift"), content="identifier")
}