Repository navigation
fix: stop stripping backslashes from BQL string literals - #1798
Merged
Merged
Conversation
The chumsky string-literal parser treated backslash as a C-style
escape introducer and DROPPED it (`just('\\').ignore_then(any())`),
so subst('[ ,]*\)$', ...) reached the regex engine as `[ ,]*)$` —
"unopened group" on a regex that works in beanquery.
Upstream's grammar is quote-stripping only:
string = /\"[^\"]*\"|\'(?:[^\']|\'\')*\'/ (bql.ebnf)
def string(value): return value[1:-1] (semantics)
A backslash is an ordinary byte; the only structural escape is the
SQL-style doubled '' in single-quoted strings, which continues the
string but stays VERBATIM in the value (pinned by upstream's own
parser_test.py: 'rainy''day' -> rainy''day). Both string_literal()
and the paren-nesting pre-scan (whose string lexing must agree, per
the canonical-discipline drift rule) now implement exactly that.
No existing test relied on the invented escapes (full query + LSP
suites pass unchanged). New regression tests: the issue's minimal
repro, the full real-world Obsidian-plugin template, backslash-as-
literal in both quote styles including a lone trailing backslash,
the upstream '' pin, and a scan/parser lexing agreement guard.
Closes #1797
Co-Authored-By: Claude Fable 5 <[email protected]>
Contributor
📊 Benchmark Results
vs main branch (2026-07-15)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes BQL string literal parsing in rustledger-query to match upstream beanquery semantics (quote stripping only): backslashes are treated as ordinary bytes, and single-quoted strings support SQL-style '' continuation without interpreting it.
Changes:
- Reimplemented
string_literal()to stop consuming backslashes as escapes and to preserve''verbatim in single-quoted strings. - Updated the parenthesis nesting pre-scan (
nesting_exceeds_limit) to lex string literals consistently with the parser (avoiding scan/parser drift). - Added regression tests covering the reported
subst()regex case, real-world nested templates, and scan/parser agreement.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/rustledger-query/src/parser.rs | Aligns parser + nesting pre-scan with upstream beanquery string-literal semantics (no backslash escapes; '' continues single-quoted strings). |
| crates/rustledger-query/tests/string_literal_escapes_test.rs | Adds targeted regressions for #1797 and drift-guard coverage for scan/parser agreement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Review comment: the ''-continuation parser allocated a String per character. The value is verbatim anyway, so match the body with ignored() pieces and take one to_slice() of the input. Co-Authored-By: Claude Fable 5 <[email protected]>
The review caught the drift guard being decoration: the pre-scan's
only observable is the MAX_NESTING_DEPTH rejection, and the guard
inputs never approached it — the OLD divergent scanner passed all
three asserts. Replaced with straddling guards: 150 real parens
after a trailing-backslash string must hit the nesting cap (a
scanner regressing to backslash-escaping swallows them — and on
wasm32 the pre-scan is the only stack protection), and 150 parens
inside a ''-continued string must NOT (a scanner ending the string
at the first quote falsely rejects the query).
Also from the review: pins for the quote-run edge family of the
upstream regex ('' empty, four-quotes, trailing '' before the
close, three-quotes rejected); tokenize_bql documented as a
DELIBERATELY divergent heuristic tokenizer with cross-references at
both sites; the double-quoted arm uses to_slice like the
single-quoted one.
Co-Authored-By: Claude Fable 5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Jul 16, 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.
What
subst('[ ,]*\)$', ...)failed with "unopened group" because the BQL string-literal parser treated\as a C-style escape introducer and dropped it (just('\\').ignore_then(any())) — the regex engine received[ ,]*)$. Reported with a real-world query template from the mkshp Obsidian plugin that works against beanquery 0.2.0.The upstream contract
beanquery's grammar is quote-stripping ONLY:
A backslash is an ordinary byte. The only structural escape is SQL-style
''in single-quoted strings — which continues the string but stays verbatim in the value (upstream's ownparser_test.pypins'rainy''day'→rainy''day). Double-quoted strings have no escapes at all.Changes
string_literal()reimplements exactly that grammar, with the upstream rules quoted in its doc comment.nesting_exceeds_limit) lexed strings with the OLD backslash rule — its lexing must agree with the parser's (canonical-discipline drift rule), so it now uses the same semantics, and a drift-guard test pins the historically-breaking shape (a lone trailing backslash used to make the scan swallow the closing quote and desynchronize its paren count)."..."at the first quote, so it becomes more consistent, not less.Compatibility
Strictly compat-improving: no existing test relied on the invented escapes (full query + LSP suites pass unchanged), and
\"-style escapes never worked in beanquery either, so no real query used them.Tests
The issue's minimal repro; the full 3-level Obsidian template; backslash-as-literal in both quote styles including lone trailing backslash; the upstream
''verbatim pin; scan/parser lexing agreement.Closes #1797
🤖 Generated with Claude Code