Repository navigation
fix(parser): blame the opener for unclosed tables and empty bracket lists - #365
Merged
Merged
Conversation
…ists
Two delimiter constructs did not follow the opener convention that calls,
indexes and parenthesised lists already use:
* An unclosed table `{` that ran off the end of input emitted a bare
"Expected ',' or '}', got :eof" pinned to the end of the file instead
of pointing at the opening brace.
* A bracket delimiter opened immediately before <eof> (e.g. `g(` at the
end of input) reported "Expected expression" at the file end rather
than blaming the opener.
Both now report an unclosed-delimiter error at the opening token, so the
innermost opener wins in nested constructs (table -> function -> call).
Expand test/lua/parser/error_position_test.exs into a golden corpus that
pins both line and column for every error shape — openers, lexer-origin,
missing-end, concrete offending tokens, deep nested propagation, and
statement-level. Each case asserts the structured position and the
rendered banner/message together. Drop the luac differential block: our
convention, not a reference compiler, is the bar.
The lexer always terminates the token stream with {:eof, pos}, so
peek/1 returns {:eof, _} (never nil) inside an unclosed table or
bracket list. Drop the dead nil branches; the {:eof, _} clause is
the only reachable one.
This was referenced Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Parser error positions were sometimes reported at the wrong place,
especially in nested constructs. The motivating report was:
This one turns out to be reported correctly —
functionused as astatement requires a name, so the genuine first syntax error is the
(on line 1 (col 9), not the
foo.bar(on line 2. Rather than chase anon-bug, this PR builds a broad golden corpus that pins line and
column for many error shapes and fixes the cases that genuinely diverge
from our position convention.
We do not use
luacas the bar — its messages are poor and we wantour own opinionated positions/messages. The corpus encodes that convention.
The convention
shallower recovery boundary. A deep error inside the Nth call argument
wins over the outer call terminator.
(,[,{, string, long string/comment)— blamed at the opening delimiter, with an "add a closing X" suggestion.
end(function/if/while/for/do) —reported where
endwas expected.Fixes (
lib/lua/parser.ex)Two delimiter constructs didn't follow the opener convention that calls,
indexes, and parenthesised lists already used:
{at EOF emitted a bare"Expected ',' or '}', got :eof"pinned to the end of the file instead of pointing at the openingbrace. → now
Unclosed opening brace '{'at the opener.<eof>(e.g.g(at end ofinput) reported
"Expected expression"at the file end. → now blamesthe opener, matching the args-then-EOF path. The innermost opener wins
in nested constructs (
table -> function -> call).The nested concrete-token propagation cases were already correct; the
corpus now locks them in.
Tests (
test/lua/parser/error_position_test.exs)Expanded from 8 to 39 golden cases, grouped by failure shape (openers,
lexer-origin, missing-end, concrete offending tokens, deep nested
propagation, statement-level). Each case asserts the exact
{line, column}via
parse_structured/1and the renderedat line L, column Cbannerplus a message substring via
parse/1. Dropped the luac differential block.Verification
mix format --check-formatted: clean