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#
Use a normal regex group and bind the matched rest through the surrounding lex pattern when needed.
///|
pub fn match_text(text : String) -> Unit {
lexmatch text with longest {
("abc", _) => ()
_ => ()
}
}