fix: a SQL comment before or after a statement is a parse error (#698) - #713
Open
dpsiderius wants to merge 1 commit into
Open
dpsiderius wants to merge 1 commit into
dpsiderius wants to merge 1 commit into
Conversation
…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.
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
A leading
--//* */comment, a trailing comment after the terminating;, and a comment-only input are now accepted. Comments are trivia atevery parser entry point, not just mid-statement.
Oracle-measured before/after
-- c\nCREATE TABLE t(a);/* c */ CREATE TABLE t(a);CREATE TABLE t(a); -- cCREATE TABLE t(a /* col */);-- just a commentTest plan
tests/corpus/comment_trivia_test.rs— all five rows above, oracle-diffed against the pinned 3.53.4 sqlite3.make test,make lint,make test-corpus,make check-grammar-drift,make check-mvl-limit,make check-mod-files,make assuranceall pass.Refs: 002/Req-1, 013/Req-6, #695
Closes #698
spend: matched estimate