Skip to content

Include column in parse error messages - #73

Merged
wtholliday merged 2 commits into
mainfrom
parse-error-columns
Oct 14, 2026
Merged

wtholliday merged 2 commits into
mainfrom
parse-error-columns

Conversation

@wtholliday

@wtholliday wtholliday commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Parse errors were formatted as file:line: message in compiler.rs, while type and safety errors went through format_error and included the column. Parse errors now use the shared helper, so every message surfaced by the CLI and lyte_compiler_get_error has the file:line:col form documented in lyte.h.
  • The Endl token is now located at the newline it terminates. Previously the line counter was bumped as soon as the newline was consumed, so an error like expected Rparen, got Endl pointed at the next line, column 1. The line advances when the token after the newline is lexed. The parser's one backtracking site saves and restores full lexer state, so it is unaffected.
  • Removed a stray println! in expect_id that echoed a quoted copy of the error to stdout.
  • 13 golden tests updated. Twelve only gained a column; partial_function.lyte moved from line 6 to 5:5, which is where the unclosed foo( actually is.

Before:

node.lyte:22: Expected declaration, got Rbrace

After:

node.lyte:22:3: Expected declaration, got Rbrace

Test plan

  • cargo test --workspace passes (unit tests plus all four golden runners)
  • Spot-checked reported columns against source for the const-suffix and zero-size-array cases

🤖 Generated with Claude Code

wtholliday and others added 2 commits October 13, 2026 20:41
Parse errors were formatted as file:line only, while type and safety
errors went through format_error and included the column. Use the
shared helper so every error reported via the CLI and
lyte_compiler_get_error has the file:line:col form the C header
documents.

Also locate the Endl token at the newline it terminates rather than
the start of the following line, so errors such as "expected Rparen,
got Endl" point at the end of the offending line instead of the next
one. The line counter now advances when the token after the newline
is lexed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
It printed a quoted copy of the error to stdout before the real
diagnostic was recorded.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@wtholliday
wtholliday merged commit 952944c into main Oct 14, 2026
8 checks passed
@wtholliday wtholliday mentioned this pull request Oct 14, 2026
2 tasks done
wtholliday added a commit that referenced this pull request Oct 14, 2026
* Test token locations and fix stale lexer doc comment

The comment on Lexer::loc said the column was computed on demand, but
it has been set eagerly for every token. Add a unit test pinning the
Endl location and the deferred line advance introduced in #73.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Count raw newlines inside string literals

The lexer only advanced the line counter for whitespace and comment
newlines, so every token after a multi-line string literal reported
the wrong line and a column measured from an earlier line.

Replace the "previous token was Endl" check with a pending_lines
counter that both the newline handler and the string scanner bump.
The line advances when the next token is lexed, so the string token
keeps the line of its opening quote. The parser's struct-literal
backtrack now saves and restores the counter along with the rest of
the lexer state.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant