Skip to content

fix: do not treat semicolons inside comments as statement terminators - #843

Merged
tconbeer merged 3 commits into
tconbeer:mainfrom
Sanjays2402:fix/semicolon-in-unsupported-ddl-comment
Aug 3, 2026
Merged

fix: do not treat semicolons inside comments as statement terminators#843
tconbeer merged 3 commits into
tconbeer:mainfrom
Sanjays2402:fix/semicolon-in-unsupported-ddl-comment

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Closes #838

A comment inside an unsupported DDL statement was truncated at the first semicolon: unsupported_line matched greedily up to ; or a newline, consuming the comment marker and part of its text as DATA, so the rest of the comment was lexed as SQL and raised a parsing/bracket error.

unsupported_line now stops at the start of a comment (--, #, //, /*) via lookahead, letting the higher-priority comment rule take the whole comment. Regression test covers all four comment styles and fails on main.

sqlfmt raised "Could not parse SQL at position N" when a comment inside
an unsupported DDL statement contained a semicolon, e.g.

    create TABLE a (
        A text --test; it's a comment
    )

The unsupported_line rule matched greedily up to the first `;` or
newline, so it consumed the comment marker and the comment text up to
the semicolon as DATA. The remainder of the comment was then lexed as
SQL, producing a parsing or bracket error.

Stop unsupported_line at the start of a comment (--, #, //, /*) with a
lookahead, so the higher-priority comment rule lexes the whole comment
including any semicolons it contains.

Adds a parametrized regression test covering all four comment styles and
a CHANGELOG entry.
@tconbeer
tconbeer force-pushed the fix/semicolon-in-unsupported-ddl-comment branch from a812eae to e416385 Compare August 3, 2026 15:23
@tconbeer

tconbeer commented Aug 3, 2026

Copy link
Copy Markdown
Owner

fantastic, thank you very much!

@tconbeer
tconbeer merged commit ac31f67 into tconbeer:main Aug 3, 2026
17 checks passed
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.

Semicolon inside comment can break sqlfmt

2 participants