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.
Warning
lexmatch is deprecated for new code. Prefer regex match expressions such as
value =~ re"..." for boolean checks, or lexscan for case-based scanning.
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 first-match behavior is
enough, or use lexscan ... with longest for longest-match scanning:
///|
fn classify(input : String) -> String {
if input =~ re"^if$" {
"keyword"
} else {
"identifier"
}
}
///|
test {
inspect(classify("if"), content="keyword")
inspect(classify("gift"), content="identifier")
}