Repository navigation
Keep the note after /// when AST formatting instead of joining the lines and dropping it - #362
Merged
Merged
Conversation
Contributor
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. Next included review available in 38 seconds. View limit details
|
jbearak
force-pushed
the
ast-printer-continuation-notes
branch
from
November 5, 2026 01:08
97368d5 to
945b820
Compare
The AST printer joined a continued statement onto one line and dropped
the note after each `///`: `reg y x /// note` then `z` became
`reg y x z`. When a `///` in a statement has a note, the parser now
keeps the statement's lines as written (a block keeps its header
through `{`), and the printer prints them, moving each line with the
statement's indentation. Statements without a noted `///` print as
before.
…inline if After a `///` with no space before it, a line's indentation decides whether it joins the token before (`b///` then `c` is `bc`), so such a line at column 0 stays there and an indented one keeps a space. The comments after a nested inline if belong to its innermost statement; print them too.
A `///` alone on its line keeps a tight chain going only from column 0 and after a tight `///`, as ContinuationTracker reads it. Treating any column-0 `///` as tight made formatting change on a second pass once it was re-indented.
jbearak
force-pushed
the
ast-printer-continuation-notes
branch
from
November 5, 2026 01:19
945b820 to
412d4b6
Compare
jbearak
added a commit
that referenced
this pull request
Nov 5, 2026
Stata 18 reads `//` and `///` as a comment or a line continuation only at the start of a line, after a space or tab, or after the `;` that ends a statement under `#delimit ;`. Otherwise the slashes are text: `local a b///` stores `b///` and runs the next line as its own command, `di 4//2` is r(198), and `use http://...` opens the URL. Sight joined `b///` to the next line (`bc`) and read any `//` as a comment. - Lexer: tight slashes are `/` operators; report CONTINUATION_NO_SPACE at a tight `///` run; drop the 7+ slash "visual separator" rule (Stata continues `b ////////`). - Parser: remove ContinuationTracker and the column-0 join; a line break in a value is always one space. Statements with tight slashes keep their source lines so the AST printer neither spaces nor drops them. - Formatters: remove #362's after_tight_continuation printer rule and #363's find_tight_continuation_lines/keep_tight_join. - CONTINUATION_NO_SPACE is now an always-on warning, not gated by styleWarnings, since it changes what Stata runs. - Send to Stata, the context tracker, and the TextMate grammar use the same rule.
jbearak
added a commit
that referenced
this pull request
Nov 5, 2026
…stead of joining the next line or starting a comment (#367) * Read a // or /// with code right before it as text, as Stata does Stata 18 reads `//` and `///` as a comment or a line continuation only at the start of a line, after a space or tab, or after the `;` that ends a statement under `#delimit ;`. Otherwise the slashes are text: `local a b///` stores `b///` and runs the next line as its own command, `di 4//2` is r(198), and `use http://...` opens the URL. Sight joined `b///` to the next line (`bc`) and read any `//` as a comment. - Lexer: tight slashes are `/` operators; report CONTINUATION_NO_SPACE at a tight `///` run; drop the 7+ slash "visual separator" rule (Stata continues `b ////////`). - Parser: remove ContinuationTracker and the column-0 join; a line break in a value is always one space. Statements with tight slashes keep their source lines so the AST printer neither spaces nor drops them. - Formatters: remove #362's after_tight_continuation printer rule and #363's find_tight_continuation_lines/keep_tight_join. - CONTINUATION_NO_SPACE is now an always-on warning, not gated by styleWarnings, since it changes what Stata runs. - Send to Stata, the context tracker, and the TextMate grammar use the same rule. * Stop file paths at a // after a space in the grammar; simplify parse-json value spacing * Read a // after code as text when checking a program header for plugin
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") dropped the note after///. It joined a continued statement onto one line and lost the comment:reg y x /// outcome firstfollowed byzbecamereg y x z. This happened in commands, options,ifqualifiers,=expressions, macro definitions,syntax, and the headers ofif,foreach,forvaluesandwhileblocks. The source-preserving mode was unaffected.Now, when a
///in a statement has a note after it, the parser keeps that statement's lines as written: a brace block keeps its header through{, and an inlineifkeeps the whole statement. The AST printer prints those lines instead of rebuilding the statement, moving them with the statement's indentation. Statements without a noted///print as before, so a bare///still joins.Re-indenting keeps meaning. After a
///with no space before it, a line at column 0 joins the token before (local a b///thencsetsbc), so such a line stays at column 0 and an indented one keeps at least one space.Proof: reproduced the dropped notes on main; the new tests (both formatter modes, each formatted twice) fail on main and pass here; a throwaway fuzz that inserts
/// noteat every token gap of 28 statements (840 variants, including tight///and nested blocks) loses the note in all 140 base variants on main, and here reparses to the same AST and formats idempotently in all but 2 (if a/// notethendi 1 + 2, which joins into a body-less, brace-lessifthe printer already mangles on main); the four gates pass.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.