Repository navigation
fix(query): a string-literal header echoes the quote the query wrote - #2229
Conversation
`SELECT "dq"` headed `'dq'`. bean-query names such a column by reproducing the literal as typed, quote character included. Closes #2176. `Literal::String` did not record which quote the source used, so the header had to guess: single quotes unless the value contained one. It now carries a `QuotedString`, and the header echoes what was written. Verified against beanquery 0.2.0 -- `'plain'`, `"dq"`, `"o'clock"`, `'it''s'`, `'say "hi"'`, and the same inside a call like `length('abc')`, all agree. The body is reproduced VERBATIM, as bean-query does: `'it''s'` heads `'it''s'`, the doubled quote left as written rather than re-escaped. That matches the value semantics already pinned in `string_literal_escapes_test.rs`, where `''` stays in the value. Quote style is source provenance, not part of the value, so `QuotedString` implements `PartialEq` and `Hash` on the text alone -- `'x'` and `"x"` are the same string, and AST equality must not depend on typing style. Same reasoning as `Spanned`, which keeps equality on its value rather than its span. Pinned, including the Hash/Eq agreement a `HashMap` keyed on literals would need. `quote` is `None` for a literal built in code rather than parsed, which has no style to echo; those keep the #2175 fallback, so that fix is untouched. `Display` echoes the source quote too, which makes a parsed literal round-trip as written -- the issue notes this may matter more than the header does -- and still falls back to double quotes. `string_literal` now delegates to the new `quoted_string_literal` instead of restating the grammar. The two arms were about to be duplicated, and a fix applied to one and not the other would make a literal parse differently depending on which caller reached it. The header and `Display` paths are controlled separately: making either ignore the recorded style fails tests, and the equality test fails if `PartialEq` starts comparing it.
There was a problem hiding this comment.
🟢 Approval recommended
The functional changes are well-scoped and backed by targeted tests, with only a minor formatting/convention nit noted.
Pull request overview
Fixes BQL column header rendering so string-literal targets preserve the original quote character used in the query (matching bean-query behavior), by carrying quote provenance through the AST and using it when rendering headers and Display.
Changes:
- Introduces
QuotedString+QuoteStyleand changesLiteral::Stringto store quote provenance without affectingEq/Hashsemantics. - Updates the parser to produce style-carrying string literals (and centralizes string-literal grammar via
quoted_string_literal). - Updates executor evaluation/parity harness to use the literal’s underlying string value, and adds regression tests covering headers,
Displayround-tripping, andEq/Hashbehavior.
File summaries
| File | Description |
|---|---|
| crates/rustledger-query/src/ast.rs | Adds QuoteStyle/QuotedString, switches Literal::String payload, and updates header + Display rendering to echo parsed quote style with a fallback for synthetic literals. |
| crates/rustledger-query/src/parser.rs | Parses string literals into QuotedString at the literal-expression site and reuses that grammar for string_literal() callers that only need the text. |
| crates/rustledger-query/src/executor/evaluation.rs | Adjusts evaluation to extract the underlying string value from QuotedString. |
| crates/rustledger-query/src/executor/dual_eval_parity.rs | Updates the parity harness to construct synthetic string literals using QuotedString. |
| crates/rustledger-query/tests/literal_quote_style_test.rs | Adds regression coverage for header quoting, verbatim body reproduction, nested literal rendering, and Eq/Hash invariants for quote provenance. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📊 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?
|
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
|
Checked this rather than adjusting it, and the formatting is rustfmt's own output — I tried the suggested one-line signature to be sure: So the leading Leaving it as rustfmt writes it — changing it would fail the formatting gate in CI. Commits on this repo run rustfmt through the |
SELECT "dq"headed'dq'. bean-query names such a column by reproducing the literal as typed, quote character included. Closes #2176.Literal::Stringdid not record which quote the source used, so the header had to guess — single quotes unless the value contained one. It now carries aQuotedString, and the header echoes what was written. Verified against beanquery 0.2.0:SELECT 'plain''plain''plain''plain'SELECT "dq""dq"'dq'"dq"SELECT "o'clock""o'clock""o'clock""o'clock"SELECT 'it''s''it''s'"it''s"'it''s'SELECT 'say "hi"''say "hi"''say "hi"''say "hi"'SELECT length('abc')length('abc')length('abc')length('abc')The body is reproduced verbatim, as bean-query does:
'it''s'heads'it''s', the doubled quote left as written rather than re-escaped or collapsed. That is consistent with the value semantics already pinned instring_literal_escapes_test.rs, where''stays in the value.Provenance is not part of the value
QuotedStringimplementsPartialEqandHashon the text alone.'x'and"x"are the same string, and AST equality must not depend on typing style — same reasoning asSpanned, which keeps equality on its value rather than its span. The test pins the Hash/Eq agreement too, since aHashMapkeyed on literals would split otherwise.quoteisNonefor a literal built in code rather than parsed, which has no style to echo. Those keep the #2175 fallback (single quotes, switching to double when the value contains a single quote and no double), so that fix is untouched and still covered.Displayechoes the source quote as well, which makes a parsed literal round-trip as written — the issue notes this may matter more than the header does — and still falls back to double quotes when there is no style.Parser
string_literalnow delegates to the newquoted_string_literalrather than restating the grammar. Writing the style-carrying version alongside the old one would have duplicated both quote arms, and a fix applied to one and not the other would make a literal parse differently depending on which caller reached it. Two callers want only the text and stay on the plain wrapper.Verification
Header and
Displayare separately controlled: making either ignore the recorded style fails tests (3 integration + 1 unit for the header, 1 forDisplay), and the equality test fails ifPartialEqstarts comparing the style. The fallback rule has its own unit test, placed there becauseheader_nameispub(crate)and a synthetic literal cannot be reached throughparse— everything parsed carries a style.4703 workspace tests green, clippy clean on 1.97.0, typos clean. BQL compat harness over 71 files / 1349 runs: no regression against baseline. The corpus does not exercise string-literal targets, so the oracle comparisons above are what carries this.