Skip to content

fix: a SQL comment before or after a statement is a parse error (#698) - #713

Open
dpsiderius wants to merge 1 commit into
mainfrom
fix/698-leading-trailing-comments
Open

dpsiderius wants to merge 1 commit into
mainfrom
fix/698-leading-trailing-comments

Conversation

@dpsiderius

Copy link
Copy Markdown
Contributor

What

A leading --//* */ comment, a trailing comment after the terminating
;, and a comment-only input are now accepted. Comments are trivia at
every parser entry point, not just mid-statement.

Oracle-measured before/after

input oracle before after
-- c\nCREATE TABLE t(a); ok FAIL ok
/* c */ CREATE TABLE t(a); ok FAIL ok
CREATE TABLE t(a); -- c ok FAIL ok
CREATE TABLE t(a /* col */); ok ok ok
-- just a comment ok FAIL ok

Test plan

  • tests/corpus/comment_trivia_test.rs — all five rows above, oracle-diffed against the pinned 3.53.4 sqlite3.
  • Regression guard: comments inside string literals stay literal.
  • make test, make lint, make test-corpus, make check-grammar-drift, make check-mvl-limit, make check-mod-files, make assurance all pass.

Refs: 002/Req-1, 013/Req-6, #695
Closes #698

spend: matched estimate

…698)

split_statements already grouped a leading comment with the statement
that follows it, matching sqlite3's own script handling. The failure was
downstream: codegen::dispatch's keyword-sniffing (leading_keywords,
compile_statement) and the exec/query CLI entry points (is_schema_changing,
starts_with_explain) all assumed the first token of a statement's raw text
was a keyword, so a leading -- or /* */ comment broke dispatch.

Adds parser::skip_leading_trivia, which re-tokenizes and returns the slice
starting at the first real token, and threads it through every one of
those raw-text keyword-sniffing sites. split_statements now also drops a
comment-only "statement" so it never reaches the dispatcher as an empty
program.

Covered by tests/corpus/comment_trivia_test.rs (oracle-diffed): leading
line/block comments, trailing comment after `;`, mid-statement comments
(regression guard), comment-only input as a successful no-op, and
comment-like text inside a string literal staying literal.

Refs: 002/Req-1

spend: within the "small" estimate — most of the fix and its tests came
from a prior partial attempt on this branch; this pass reviewed, verified
against the oracle, added the spec Tests: links, and formatted.
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.

bug: a SQL comment before or after a statement is a parse error (oracle accepts all five forms)

1 participant