Skip to content

Make CR-only source line endings consistent across lexer tracking and literals #598

Closed

Description

@LunaStev

The lexer recognizes carriage return (\\r) as whitespace, but only line feed (\\n) advances the logical source line.

In skip_whitespace, \\r is consumed together with ordinary horizontal whitespace, while \\n increments line and updates line_start.

The literal scanner also treats only \\n as a raw source newline terminating a string. A lone \\r can therefore be consumed as content even though the same character is treated as source whitespace outside the literal.

This creates inconsistent behavior for CR-only source files:

  • token line numbers do not advance at \\r,
  • columns continue from the previous physical line,
  • raw CR inside a string does not take the same newline path as LF,
  • diagnostics can disagree with the physical source layout.

CRLF must remain a single newline rather than becoming two logical lines.

Code evidence:

  • front/lexer/src/trivia.rs — skip_whitespace
  • front/lexer/src/literals.rs — string literal newline handling
  • lexer diagnostic line/column tracking

Acceptance:

  • Define source newline handling for LF, CRLF, and lone CR.
  • Count CRLF as exactly one logical newline.
  • Handle lone CR consistently in token tracking, comments, and literals.
  • Add lexer tests comparing equivalent LF, CRLF, and CR-only sources.
  • Verify diagnostic line and column locations under all three encodings.
  • Avoid changing escape-sequence \\r semantics inside string/char literals.

Activity

  1. added
    bug
    help wanted
    needs testing
    cross-platform
    on Sep 12, 2026
  2. self-assigned this
    on Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugcross-platformhelp wantedneeds testing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions