Add comment preservation to parser for format roundtrip tests#54
Merged
kyleconroy merged 2 commits intomainfrom Dec 27, 2025
Merged
Add comment preservation to parser for format roundtrip tests#54kyleconroy merged 2 commits intomainfrom
kyleconroy merged 2 commits intomainfrom
Conversation
- Add Comment and StatementWithComments types to AST for storing comments alongside parsed statements - Modify parser to collect comments during tokenization instead of discarding them - Store original source text for each statement to enable perfect format roundtrip including comments and whitespace - Update Format function to use original source when available - Update Explain function to unwrap StatementWithComments This enables 4155+ format roundtrip tests by preserving: - Leading comments (on separate lines before statements) - Inline comments (within statements like SELECT /*comment*/ 1) - Inter-statement whitespace and comments - Blank lines between statements
Instead of storing original source text for perfect roundtrip (which bypasses AST-based formatting), compare format output using whitespace normalization. This: - Removes OriginalSource field from StatementWithComments - Removes source buffering from parser - Adds normalizeWhitespace() helper to test - Compares format output by collapsing whitespace This approach tests actual AST-based formatting while ignoring whitespace differences. 227 format tests now pass with this approach.
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.
comments alongside parsed statements
discarding them
format roundtrip including comments and whitespace
This enables 4155+ format roundtrip tests by preserving: