Skip to content

parser: a regex literal cannot open a statement or tail expression ('expected expression') #2233

Closed

Description

@ehartford

In a block body, a line that begins with a regex literal is refused:

fn strip(s: &str) -> str:
    var out = s.to_owned()
    /_[0-9]+/.replace(out, "_")      // error: expected expression

The same expression bound with let r = /_[0-9]+/.replace(out, "_") parses. The statement parser sees / and takes it for a binary operator with a missing left operand; a regex literal is only recognized in operand position. §4 names regex literals as primary expressions, so a statement or a tail may start with one — exactly the one-liner spelling ... | with -p 'line = /a/.replace(line, "b")' already relies on in assignment position. Found writing tools/migrate_diff.w (#2230).

Activity

  1. changed the title [-]parser: a regex literal cannot open a statement or tail expression ( is 'expected expression')[/-] [+]parser: a regex literal cannot open a statement or tail expression ('expected expression')[/+] on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions