Skip to content

fix(query): name trailing tokens instead of mislabeling as EOF - #1453

Merged
robcohen merged 5 commits into
mainfrom
fix/query-trailing-token-error
Jun 20, 2026
Merged

robcohen merged 5 commits into
mainfrom
fix/query-trailing-token-error

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

The query parser reported "unexpected end of input" for any trailing tokens after a valid prefix:

$ rledger query main.beancount "SELECT account, sum(position) GROUP BY account WHERE number > 0"
syntax error at position 47: unexpected end of input        # 47 is the WHERE token
$ rledger query main.beancount "SELECT account FOOBAR"
syntax error: unexpected end of input                       # at FOOBAR

The classifier used e.found().is_none() to mean EOF — but chumsky's end() combinator (which rejects leftover tokens) also reports found() == None, so trailing tokens were mislabeled even though the error span pointed straight at them.

How

Classify by the error span position instead: a position at or past the end of the input is a genuine EOF; otherwise name the unexpected token at that position.

syntax error at position 47: unexpected token 'WHERE'
syntax error at position 15: unexpected token 'FOOBAR'

Verify

rledger query f.beancount "SELECT account, sum(position) GROUP BY account WHERE number > 0"   # names WHERE@47
rledger query f.beancount "SELECT account FOOBAR"                                              # names FOOBAR@15

Test trailing_tokens_are_named_not_mislabeled_eof; full rustledger-query suite, clippy, fmt green.

🤖 Generated with Claude Code

…input as EOF

The query parser classified a parse error as "unexpected end of input"
whenever `found()` was `None`. But chumsky's `end()` combinator — which
rejects leftover tokens after a valid prefix — also reports `found() ==
None`, so `SELECT … GROUP BY account WHERE …` and `SELECT account FOOBAR`
were both labeled EOF even though the error span pointed at the real
offending token (WHERE / FOOBAR).

Classify by the error span instead: a position at or past the end of the
input is a genuine EOF; otherwise name the unexpected token at that
position.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner June 20, 2026 14:50
Copilot AI review requested due to automatic review settings June 20, 2026 14:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates rustledger-query’s query parser error classification so trailing tokens after a valid query prefix are reported as unexpected tokens (e.g., WHERE, FOOBAR) instead of being mislabeled as an unexpected EOF, and adds a regression test for the behavior.

Changes:

  • Adjusts EOF vs trailing-token detection by using the error span position relative to input length.
  • Introduces a regression test asserting trailing tokens are named and that the error span points at the trailing token.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/rustledger-query/src/parser.rs Resolved
Comment thread crates/rustledger-query/src/parser.rs Resolved
@codecov

codecov Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-query/src/parser.rs 91.66% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 38.9ms ± 3.6ms 24.4 MB
beancount 761.5ms ± 12.7ms 50.7 MB
Comparison 19.6x faster 2.1x less

vs main branch (2026-06-20)

Metric main this PR Change
Time 41.3ms 38.9ms -5.8% 🟢
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@github-actions

github-actions Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 792
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

robcohen and others added 3 commits June 20, 2026 15:05
CI clippy (--all-targets) flagged clippy::match_wildcard_for_single_variants
in the new test; use a refutable let-else instead of a wildcard match arm.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Addresses Copilot on #1453:
- Only disambiguate EOF-vs-trailing-token in the found()==None case; when
  chumsky reports a concrete token, keep its richer message (e.to_string()).
- Rename the test to the test_ prefix used by the rest of the module.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@robcohen

Copy link
Copy Markdown
Member Author

Addressed both: the classifier now only special-cases the ambiguous found() == None situation (EOF vs end()-trailing-tokens) and keeps chumsky's richer message when a concrete token is found; renamed the test to the test_ prefix.

@robcohen
robcohen merged commit 968d1d8 into main Jun 20, 2026
44 checks passed
@robcohen
robcohen deleted the fix/query-trailing-token-error branch June 20, 2026 15:38
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.

2 participants