Skip to content

one-liners: a regex literal starting with = lexes as the /= operator (/=> x/.replace(...) is "expected expression") #2525

Closed

Description

@ehartford

A regex literal whose first character is = is lexed as the /= operator:

with -p 'line = /=> Some\((.*)\)\s*$/.replace(line, "=> $1")'
error: expected expression
 --> <cli -p #1>:3:9
3 |  line = /=> Some\((.*)\)\s*$/.replace(line, "=> $1")
  |         ^^

Workaround: /[=]> Some…/. A regex literal in expression position should start wherever / cannot be a binary operator (after =, (, ,, a keyword), as the Lexer already decides for /pat/ vs division; the /= token is the one case it gets wrong. Found 2026-10-21 doing the D103 Some( sweep.

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced.

    $ echo 'a => Some(x)' | with -p 'line = /=> Some\((.*)\)\s*$/.replace(line, "=> $1")'
    error: expected expression
     --> <cli -p #1>:1:8
    

    pre-release: one-liners are a stated priority, and the lexer already knows the positions where / cannot be an operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions