Skip to content

Lexer: support \r and explicit byte escapes in string and bytes literals #249

Closed

Description

@flyingrobots

Problem

Edict's lexer accepts only \", \\, \n, and \t inside string and bytes literals (crates/edict-syntax/src/token.rs, string-literal scanner; main e60411fc). b"\r" fails with Lex / invalid string escape, and there is no explicit byte escape such as \xNN.

The language spec already anticipates this: "Non-ASCII source characters inside bytes-lit are rejected unless escaped as explicit byte escapes", and lists "Bytes literal escapes … have canonical fixtures" as a lexical conformance item to pin before parser freeze (docs/SPEC_edict-language-v1.md, lexical grammar notes). Neither the escape set nor the fixtures exist yet.

Reproduction

Jim's Buffer-decoder probe (flyingrobots/jedit#302, edict/replace-range-probes/buffer-decoder/Decimal.edict) refuses at lex on b"\r" at the public application build boundary, rebuilt today against main e60411fc.

Proposed scope

  • Pin the escape set in the spec: at least \r, \0, and \xHH for bytes literals; decide whether \u{…} applies to string literals.
  • Add canonical lexical fixtures (accept and reject) and keep decoding canonical (one spelling per byte value is not required, but the decoded payload must be).
  • Keep the change lexical; no new language semantics.

Small, generic, independent of any application. Refs flyingrobots/jedit#296, flyingrobots/jedit#302.

Activity

  1. flyingrobots commented on Oct 16, 2026

    @flyingrobots
    OwnerAuthor

    Correction to the scope above, checked against main e60411fc by building through the public application boundary:

    Bytes literals are not lexed at all. b"ab" is read as the identifier b followed by a string literal, so both len(b"ab") (ExpectedToken: expected RParen, found Str("ab")) and let w: Bytes<max=2> = b"ab"; (expected Semi, found Str("ab")) fail to parse. The Jim Buffer-decoder probe hit the \r escape error first only because lexing runs before parsing.

    So this issue covers two things: (1) lex b"…" as a bytes literal per the spec grammar (bytes-lit = "b" , string-lit), and (2) the escape set, including \r and explicit byte escapes. Both remain lexical; no new semantics.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions