E4218#
Compiler diagnostic name: lexscan_pattern_not_anchored.
字句用の正規表現パターンが、必要な位置に固定されていません。
lexscan で使うパターン(メモリ内の @lexbuf.StringScanner をスキャンする場合を含む)と、longest 戦略を使う lexmatch のパターンは、現在の入力位置から始まる必要があります。そのような正規表現はそれぞれ ^ でアンカーしてください。
Erroneous example#
///|
pub fn classify(input : String) -> String {
lexmatch input with longest {
re"[a-z]+" => "word"
_ => "other"
}
}
Suggestion#
Add ^ to the start of the regex. Add $ as well only when the case must
consume the whole input.
///|
pub fn classify(input : String) -> String {
lexmatch input with longest {
(re"^[a-z]+", after=_) => "word"
_ => "other"
}
}