Repository navigation
fix(query): report BQL syntax errors where they are, read dot-edge decimals and stacked signs, and use bean-query's postings wildcard - #2865
Merged
Conversation
…cimals and stacked signs, and use bean-query's postings wildcard A syntax error at a statement's first token was reported as the last statement alternative's keyword error, position 0, "unexpected token 'SELECT'". The parser now re-runs the statement the keyword names and reports its error where it is. Number literals may start or end with a dot, and unary signs stack, bounded by MAX_NESTING_DEPTH. A trailing "; text" stays an error (#2403). SELECT * over the postings is bean-query's PostingsTable.wildcard_columns (date, flag, payee, narration, position) for the default FROM and FROM #postings alike. Closes #2829 Closes #2830 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s, and name an unclosed delimiter Review follow-up. A + takes a bare atom only, as bean-query's uplus: '+' atom, so ++6, +-6 and +(1) are syntax errors. A run of minus signs counts toward the same nesting bound as the brackets around it, so the two cannot multiply into a stack overflow. A bracket or quote left open is reported at the end as the missing closer. SELECT * FROM #postings no longer tracks a running balance its wildcard does not show. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-and-wildcard # Conflicts: # CHANGELOG.md
…n cost A unary + took primary_expr, which includes the * wildcard, so SELECT +*, count(+*) and WHERE +* parsed (the last gave no rows). bean-query has no * atom and refuses all three; so does main. The atom after + now excludes * as it excludes a bracket or a sign. bean-query also accepts +(1, 2) and IN +(...) through its list-constant atom. rledger has no list constant outside IN (SELECT (1, 2) is refused too), so every +( stays refused: the CHANGELOG now names that gap instead of claiming parity, and a test pins it. The nesting-scan comment said a binary minus costs one level at most. It costs one for every bracket after a minus, so a - (b - (... reaches the limit at half the depth. The comment says so, and a test pins it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Only the + path excluded *, so a run of minus signs still took it:
SELECT --*, count(--*) and SELECT - -* parsed and failed on a row
("negation requires numeric value"), and WHERE --* over no rows gave
nothing. Main refused --* but accepted a single -*. bean-query refuses
all of them: * is no atom of its grammar.
The unary parser now checks the operand after any + or run of -, and a
wildcard there is reported at the * itself ("* is not a value, so a sign
cannot apply to it") instead of at the sign as "expected identifier, or
*", which suggested a * was accepted there.
The nesting test is pinned exactly: 128 "+ (" parse and 129 do not,
64 "- (" parse and 65 do not.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-and-wildcard # Conflicts: # CHANGELOG.md
robcohen
enabled auto-merge (squash)
November 5, 2026 11:31
robcohen
added a commit
that referenced
this pull request
Nov 6, 2026
…ument (#2878) BQL read `*` as an ordinary operand, so `SELECT 1 + *` gave blank rows, `count(1 + *)` gave 0 and `SELECT date WHERE 1 + *` gave no rows and no error, where bean-query 0.2.0 refuses each as a syntax error. Its grammar takes `*` only as the whole target list (`select: ... targets:(target+ | asterisk)`) and as a call's only argument (`function: fname '(' asterisk ')'`). - `target` reads a bare `*` before an expression, unless an operator, `.` or `[` follows it. rledger's `SELECT *, account` extension keeps working. - `function_args` reads a `*` alone before `)`. - Any other `*` reaches the `*` atom in `primary_expr`, which refuses it by name at the `*` ("'*' is not a value: ..."): `1 + *`, `2 * *`, `count(1 + *)`, `count(*, 1)`, `WHERE 1 + *`, `(*)`, `*.x`, `-(*)`, `-*.x`, `GROUP BY *`, `ORDER BY *`. This replaces the sign-only check from #2865, which caught only a bare signed `*`. - That refusal is reported as written when the query also fails further in (``SELECT -*, `x` ``, `SELECT -* FROM`), instead of "unexpected token '*'". - A sign after a unary `+` (`++6`, `+-6`, `+-*`) is refused at that sign by name, instead of "found '+' expected identifier, or '*'". The plus check now runs before the atom rather than as `atom.and_is(..)`, whose rewind dropped the `*` atom's error, so `SELECT +*` parsed. `-1 * 2`, `2*3`, `count(*)`, `count( * )`, `sum(*)` (parsed, then checked like any call, as in bean-query) and `SELECT * FROM (SELECT *)` are unchanged. Closes #2871 Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
What
Two BQL compatibility fixes reported against
@rustledger/wasm0.24.0, each checked row by row against beanquery 0.2.0 / beancount 3.2.3 (therustledger-compatcontainer).#2830, parse errors, dot-edge decimals, stacked signs
PRINT) at position 0, which surfaced asunexpected token 'SELECT'. When the failure is at the first keyword, the parser now re-runs the one statement that keyword names (statement_errors) and reports that statement's error. A word that names no statement (FETCH x) is still reported at position 0..5,5.,-.5), as in bean-query's grammar.--6,-- 6,---6), and may be followed by a+(-+6). A+takes a bare atom only, as in bean-query's grammar (uplus: '+' atom), so++6,+-6,+(1),+date.yearare syntax errors on both sides, and so is any sign before*(+*,-*,--*), reported at the*. One gap: bean-query also accepts+(1, 2)and'a' IN +('a', 'b')through its list-constant atom; rledger refuses every+((see Review round 2).MAX_NESTING_DEPTHas the brackets around it, in the up-frontnesting_exceeds_limitscan. Signs and brackets therefore cannot multiply into a stack overflow (20 brackets each behind 128 signs is a parse error, not a crash).SELECT (1,SELECT 'abc) is reported at the end as the missing closer (expected ')' to close the '(' at position 7). Before, the narrowed error named the opener as the offending character.#2829,
SELECT *over the postingsSELECT *gives bean-query'sPostingsTable.wildcard_columns(date, flag, payee, narration, position) for the default FROM,FROM postingsandFROM #postingsalike, and through a subquery orCREATE TABLE AS. Before, the default form addedaccount, andFROM #postingsgave all 31 visible columns. Every column is still selectable by name.#postingsuses a newTable::with_wildcard, which hides the non-wildcard columns from*only, and no longer computesbalance/account_balance/metajust because the query says*.Why
syntax error at position 0: unexpected token 'SELECT', which was wrong in both position and token.SELECT *saw a different shape from bean-query's.bean-query comparison, per row
SELECT `payee` FROM postingsunexpected token 'SELECT'found '`'SELECT [payee] FROM postings(also@,$,?)found '['SELECT .5 LIMIT 10.50.5SELECT 5. LIMIT 155SELECT -.5 LIMIT 1-0.5-0.5SELECT -- 6 LIMIT 166SELECT ---6 LIMIT 1-6-6SELECT -+6 LIMIT 1-6-6SELECT +-6,++6,+(1)SELECT (1expected ')'at the endSELECT 2 LIMIT 1; garbage2SELECT * LIMIT 1date, flag, payee, narration, positionaccountSELECT * FROM postings LIMIT 1Deliberate deviation, kept: a trailing
; textstays a syntax error (#2403). bean-query treats;as the start of an end-of-line comment, soSELECT 1;2silently runsSELECT 1.test_parse_still_refuses_text_after_a_semicolonpins this. The compat suite has no such query, so nothing goes inKNOWN_RUST_DIVERGENCES.Not fixed here (pre-existing on main): an optional clause whose body fails is still reported at its keyword, e.g.
SELECT 1 WHERE `x`givesunexpected token 'WHERE'. That is the same chumsky alternative-error pattern, one level down, and would need the same narrowing per clause.The narrowed error lists only what the first failing rule expected (
found '`' expected identifier, or '*'), not every alternative an expression could start with.Only
SELECTchanges here.JOURNAL,BALANCES,PRINTandCREATE TABLE ... AS SELECTalready reported the right position on main.SELECT * FROM #postingsno longer keeps a running inventory for abalancecolumn its wildcard does not show (#1080). ASELECT *over a user table that has abalancecolumn still does.The CHANGELOG lists the
SELECT *change under Breaking, because a positional consumer of the default wildcard loses theaccountcolumn. The parse fix is listed under Fixed. The parser's output for already-valid queries is unchanged, so the parse cache is not bumped.Review round 2
Merged origin/main (#2862, #2864, #2869); the CHANGELOG conflict kept both sides. This PR bumps no parse-cache version.
+no longer takes the*wildcard. The atom after+came fromprimary_expr, which includes*, soSELECT +*,count(+*)andWHERE +*parsed, the last giving no rows. bean-query 0.2.0 refuses all three withsyntax error, as it doesSELECT + *andSELECT -+*; main refused them too. The guard is nowone_of("(-+*").test_parse_refuses_unary_plus_before_the_wildcardpins all five and thatcount(*)still counts.+(before a list: documented gap, not implemented. Checked against bean-query 0.2.0: its atom includes a list constant, soSELECT +(1, 2)gives[1, 2],+(1,)gives[1], and'a' IN +('a', 'b')gives TRUE;+(account, 'x')is a syntax error there, since list elements must be constants. Matching it is not just a parser change: rledger has no list constant outsideINat all (SELECT (1, 2)is refused, where bean-query gives[1, 2]), and rledger's set renders as1, 2, not[1, 2]. Accepting only+(...)would add a form that the bare list still lacks. So every+(stays refused. The CHANGELOG now names the gap instead of claiming parity with bean-query's grammar, the parser comment says the same, andtest_parse_refuses_unary_plus_before_a_listpins it (the unsignedIN ('a', 'b')still answers TRUE). Bare list constants would be their own change.-costs. The scan cannot tell a binary-from a unary one, so a bracket right after any-costs two levels:a - (b - (...reaches the 128 bound at half the bracketsa + (b + (...does. The comment says so, andtest_parse_counts_a_bracket_after_a_binary_minus_twicepins it (100+ (parse, 60- (parse, 70- (are refused).Review round 3
Merged origin/main again, now with #2867; the CHANGELOG conflict kept both entries.
*wildcard (regression fixed). Round 2 guarded only the+path; a run of-still tookprimary, which includes*, soSELECT --*,SELECT -- *,SELECT - -*andcount(--*)parsed and failed on a row ("negation requires numeric value"), andSELECT date FROM year = 1999 WHERE --*silently gave no rows. Main refused--*but accepted a single-*. bean-query 0.2.0 refuses every one withsyntax error(checked:-*,--*,- -*,count(--*),WHERE --*, theyear = 1999query). The unary parser now checks the operand after a+or any run of-, so-*is refused too.*. It wassyntax error at position 7: found '+' expected identifier, or '*', at the sign, as if a*were what the target list wanted. It is nowsyntax error at position 8: '*' is not a value, so a sign cannot apply to it, at the*(avalidateon the unary parser, which keeps the parse and reports there).test_parse_refuses_a_sign_before_the_wildcard(renamed from round 2's plus-only test) pins the exact position and message for 12 queries:+*,+ *,count(+*),WHERE +*,-+*,-*,--*,-- *,- -*,count(--*),WHERE --*and theFROM year = 1999 WHERE --*query, pluscount(*)andSELECT *still working.test_parse_counts_a_bracket_after_a_binary_minus_twicenow asserts 128+ (parse and 129 do not, 64- (parse and 65 do not.*as an operand of a binary operator (1 + *,2 * *,WHERE 1 + *) is also wrong on main and is left for a separate issue.How to test
The new
bql_literals_and_wildcard_test.rshas 10 tests. Run against an origin/main build (separate worktree and target dir, at c5e94c5), 8 of them fail. Two pass there: the;pin, because that behavior is unchanged, andtest_parse_refuses_unary_plus_before_a_list, because main also refuses every+((it pins the documented gap). A main-vs-branch run of all 68 queries indocs/onexample.beancountdiffers on 4. Two are the wildcard (SELECT *,SELECT * WHERE ... IN links), and two are the bare-syntax fragmentsSELECTandSELECT ..., whose error messages changed. All four are intended.Existing tests that asserted the old wildcard shape now name their columns (
SELECT *, account ..., or explicit lists).Closes #2829
Closes #2830
🤖 Generated with Claude Code