E0077#
Warning name: lexmatch_longest_match
This warning described an earlier experimental form of longest-match
lexmatch and is not emitted by the current compiler.
Current lexmatch ... with longest is supported for in-memory String and
StringView inputs when its cases use regex constant expressions.
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=.
///|
fn classify(input : String) -> String {
lexmatch input with longest {
re"^(if|[a-z]*)$" as token => token.to_owned()
_ => "other"
}
}
///|
test {
inspect(classify("iff"), content="iff")
}