Repository navigation
Keep syntax statements when AST formatting instead of deleting them - #354
Merged
Merged
Conversation
Contributor
jbearak
force-pushed
the
ast-printer-keep-syntax
branch
2 times, most recently
from
November 5, 2026 00:28
bc9ec70 to
febe968
Compare
The AST printer had no case for the syntax node, so it printed nothing and deleted the statement. The parser now keeps the spec text on the node (continuations joined), and the printer prints it with its prefixes and comments. A block comment inside the spec now reads as whitespace, as in other statements, instead of ending it: `syntax varlist /* c */ [if]` had parsed `[if]` as an if statement. Property generators can emit syntax as a command name again.
A syntax node now keeps interior comments, so a block comment between prefixes before syntax reads as whitespace, as before a plain command: `capture /* c */ noisily syntax varlist` was split into `capture` and `noisily syntax varlist`. Test prefixed syntax in both formatter modes.
jbearak
force-pushed
the
ast-printer-keep-syntax
branch
from
November 5, 2026 00:35
febe968 to
81e54d2
Compare
jbearak
added a commit
that referenced
this pull request
Nov 5, 2026
…en /// between prefixes #354 keeps interior comments on syntax nodes, so the prefix chain no longer needs to stop at a comment before a prefixed syntax. A block comment followed by /// between prefixes (quietly /* c */ ///, then : gen x = 1) already reads as whitespace here; test it.
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.
The AST formatter (
formatting.mode = "ast") deleted everysyntaxstatement.program p/syntax varlist/endbecameprogram p/ blank line /end, and formatting again removed the blank line. The program lost its argument parsing. The printer had no case for thesyntaxnode, so it printed nothing. The source-preserving mode was unaffected.The parser now keeps the spec text after
syntaxon the node (///lines joined, as it already does for macro values and prefix arguments). The printer prints it with its prefixes (capture noisily syntax ...,version 14: syntax ...) and comments. Like commands, a///-continuedsyntaxcomes out on one line in AST mode.A related parser bug: in
syntax varlist /* c */ [if], the parser stopped the spec at the comment and read[if]as anifstatement, which the AST formatter printed asif ] { }. The comment now reads as whitespace, as #349 did for other statements, so the signature includes[if].With prefixes, the same applies: #351 read a comment between prefixes as whitespace except before
syntax, because asyntaxnode didn't keep comments. It does now, socapture /* c */ noisily syntax varliststays one statement instead of splitting intocaptureandnoisily syntax varlist.args,version, andprogram drop/list/diralready printed correctly.#delimitwas fixed in #350.Property generators can emit
syntaxas a command name again (#352 had excluded it to stop the flake).Proof: reproduced the deletion on main; the new tests (both formatter modes, each formatted twice, including
capture,quietly, andcapture noisilybeforesyntax) fail on main and pass here; withsyntaxweighted into the command-name generator, formatting-preservation [ast] and parser-roundtrip fail on main and pass here; the four gates pass, apart from two help-coverage tests that need a local Stata install this machine lacks.Reviewed with sol-loop: 3 rounds with gpt-6.1-sol. Sol verdict: approved
Created with Claude Opus 5.5 in Claude Code (T3 Code); reviewed by GPT-6.1 Sol in Codex.
Summary by CodeRabbit
syntaxas a command name.