E4181#

Compiler diagnostic name: named_capture_in_regex_literal_used_in_lex_is_not_supported.

lexmatch または lexscan で使う正規表現リテラルでは、名前付きキャプチャグループはサポートされません。

lexmatchlexscan は、MoonBit の as 構文でマッチしたテキストを束縛します。正規表現自体の名前付きキャプチャグループは、この束縛モデルには含まれません。

Erroneous example#

///|
pub fn match_text(text : String) -> Unit {
  lexmatch text with longest {
    re"^(?<word>abc)$" => ()
    _ => ()
  }
}

The regex contains the named capture group (?<word>...).

Suggestion#

通常の正規表現グループを使い、マッチしたテキストを as で束縛してください。

///|
pub fn match_text(text : String) -> Unit {
  lexmatch text with longest {
    (re"^(abc)$" as word) => ignore(word)
    _ => ()
  }
}