E4185

E4185#

Compiler diagnostic name: invalid_lex_pattern.

This diagnostic described the earlier string-piece lexmatch pattern shape and is not emitted by the current compiler.

Current lexical cases contain one regex constant expression, optionally with as, before=, and after= bindings supported by the selected matching mode.

Erroneous example#

The following pattern has too many top-level pieces:

///|
fn classify(input : String) -> String {
  lexmatch input with longest {
    ("a", before, "b", after) => before.to_owned() + after.to_owned()
    _ => "none"
  }
}

///|
test {
  ignore(classify)
}

Current code should use the regex-case syntax instead.

Suggestion#

Use a current lexmatch case pattern, or a regex match expression when only a boolean result is needed:

///|
fn classify(input : String) -> String {
  if input =~ (re"a" + re"b", before~, after~) {
    before.to_owned() + after.to_owned()
  } else {
    "none"
  }
}

///|
test {
  inspect(classify("xabz"), content="xz")
}