E4181#
Compiler diagnostic name: named_capture_in_regex_literal_used_in_lex_is_not_supported.
Named capture groups are not supported in regex literals used by lexmatch.
lexmatch can bind parts of a regex pattern through positional binders in the
lex pattern. Named capture groups inside the regex itself are rejected because
they are not part of the supported lex pattern binding model.
Erroneous example#
///|
pub fn match_text(text : String) -> Unit {
lexmatch text with longest {
("(?<word>abc)", _) => ()
_ => ()
}
}
The regex contains the named capture group (?<word>...).
Suggestion#
With lexscan, use a normal regex group and bind the matched suffix with
after= when needed.
///|
pub fn match_text(text : String) -> Unit {
lexscan text with longest {
(re"^abc", after=_) => ()
_ => ()
}
}