E0077#
Warning name: lexmatch_longest_match
Using lexmatch with longest-match semantics is deprecated.
This warning is emitted for lexmatch ... with longest. Regex match expressions
do not provide longest-match semantics; use lexscan ... with longest for
lexer-style longest matching.
Erroneous example#
///|
fn classify(input : String) -> String {
lexmatch input with longest {
("if|[a-z]*" as token) => token.to_owned()
_ => "other"
}
}
///|
test {
inspect(classify("iff"), content="iff")
}
Suggestion#
Convert each legacy string pattern to a regex literal. Anchor it at ^, and at
$ as well when the case must consume the whole input. Replace a trailing rest
binder with after=. Longest-match lexscan does not support leading rest
binders or case guards, so those cases require manual refactoring.
///|
fn classify(input : String) -> String {
lexscan input with longest {
re"^(if|[a-z]*)$" as token => token.to_owned()
_ => "other"
}
}
///|
test {
inspect(classify("iff"), content="iff")
}