Repository navigation
Keep strings, option arguments, call parens and blank input rows as written when formatting, and read abbreviated weights and foreach list types in parse --json - #419
Merged
Conversation
…rows as written, and read abbreviated weights and foreach list types in parse --json
Formatter (both modes unless noted):
- An inline python:/mata: statement whose string holds a ; before a
comment marker ("a;\t//b") comes back byte for byte. Only a ; that
ends the statement (a #delimit ; terminator, or a ; before ///) is
kept outside the placeholder.
- Under #delimit ;, a /// after the ; that ends a statement no longer
makes the next statement a continuation line, so one format reaches
the fixed point and the indentation diagnostic agrees.
- AST mode prints option arguments as written instead of respacing
them as expressions, which turned using(plugins/my.plugin) into
using(plugins / my.plugin), format(%9.0g) into format(9.0g), eq(#2)
into eq(2) and c:\data\x.gph into c : data x.gph.
- AST mode keeps the () of a call with no arguments (display
runiform()) and a blank data row between input and end.
- Embedded-block placeholders are applied in one pass with line
offsets computed once (1,000 mata: lines: 11.3 ms to 2.3 ms for
indentation diagnostics).
sight parse --json:
- Weight words and abbreviations Stata 18 accepts: w..weight,
fw..fweight, freq..frequency, aw..aweight, cell..cellsize,
pw..pweight, iw..iweight.
- foreach ... of var/new/num/loc/glo (three letters or more) report the
full list type.
- else /* c */ if reports else_if: true.
- syntax Level(integer 95) reports default "95"; hover shows it as
Level(integer 95).
- display runiform() reports runiform() as its argument.
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 23 minutes. View limit details
|
jbearak
force-pushed
the
t3/fix-formatter-json-parse-bugs
branch
from
November 19, 2026 14:45
1f88e50 to
4dda092
Compare
…] as Stata does, and keep label/note text and program-header comments when formatting (#417) Fixes parser regressions since v0.15.1, each checked against StataMP 18: - include/do/run using/setup.do takes the path, not the using keyword - program `cmdname' defines a program closed by its end - #delimit ; program // note, then define p; defines p - `stem'using, `stem'in and `stem'if are one name - price[`weight'] is a subscript, not a weight clause - label variable/data/define, char and note ...: text keeps its if/in/using words, and AST formatting prints it as written - a comment in a program header, or a /// note before an inline mata:, makes AST formatting leave the file as written instead of dropping it - a run of // comments in a #delimit ; statement parses in linear time
…g, or behind a long command, and keep polling after a huge burst of output (#416) * Keep the Stata console polling after a huge burst of output, and keep editor sends from being lost at --more--, while connecting, or behind a long command - Automation backend: append a poll's lines without spreading them (a burst of ~200k lines overflowed the stack and stopped polling for good), consume held lines by index, and keep polling after a poll throws, saying so once. - Editor sends go through a new send_line entry (console API v3): at --more-- they wait for the prompt instead of being taken as pager keys; typed keys still answer --more--. - A Stata pane holds each typed send's temp file until its console gives the line to Stata, then deletes it after the usual delay; it deletes it at once if the line is dropped or the pane ends. - The active-terminal commands send to a Stata pane through its queue, so a send made while the pane connects isn't dropped. * Don't let a hand-off's cleanup delete a send's file soon after the pane releases it
…tar comments as Stata does (#414) * Read input data, prefixed embedded openers, and #delimit ; star comments as Stata does Co-Authored-By: Claude Opus 5.5 <[email protected]> * Bound the program-header check to the input data region Co-Authored-By: Claude Opus 5.5 <[email protected]> * Test formatting of prefixed mata: lines and #delimit ; input records Co-Authored-By: Claude Opus 5.5 <[email protected]> * Test a * comment after an abbreviated #d ; Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
The blank-row check compared line numbers, which under #delimit ; is true for an empty block because the data starts on the input line. Caught by input-data-edge-cases.test.ts once main's #414 was merged in.
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.
Auditing
v0.15.1..mainbefore a stable release turned up two formatter regressions against v0.15.1, three bugs in the experimental AST formatter, and wrong structure in the newsight parse --json. Each one reproduces on main.Default (source-preserving) formatter, regressions vs v0.15.1
python: text = "a;<TAB>//b": the tab in the string became three spaces. The formatter took the;and//inside the string as Stata syntax and left them outside the embedded-code placeholder. Now it splits there only at a;the lexer reads as ending the statement (a#delimit ;terminator, or a;before///), so embedded text comes back byte for byte.#delimit ;,mpg; /// second modelfollowed by a two-lineregress: the first pass indentedweight;and the indentation diagnostic flagged it, and the second pass moved it to column 0. A///after the;was making the next statement a continuation line. Under#delimit ;the formatter now ignores///when deciding continuations. The;-mode statement runs (Indent the later lines of a #delimit ; statement like the lines after ///, instead of putting them at column 0 #363) already cover the lines that really continue. One pass now givesregress mpg/weight;, with no diagnostic.AST formatter
program define plug, plugin using(plugins/my.plugin)becameusing(plugins / my.plugin). Option arguments went through expression spacing, which also damaged other arguments that aren't expressions. On the 3,780 base ados it producedformat(%9.0g)→format(9.0g),eq(#2)→eq(2),jars(libstata-plugin.jar)→jars(libstata - plugin.jar)andrspec(--&&-)→rspec(- - & & -), andsaving(c:\data\x.gph)→saving(c : data x.gph). Option arguments are now printed as written. In exchange the formatter no longer adds spaces inside expression-like arguments, soeq(1,2)stays as it is.display runiform()printed asdisplay runiform, because the parser dropped empty()groups. It now keeps them. See the parser note below.input x/ blank row /endlost the blank row on the second pass. The printer couldn't tell one blank row from no rows, since both have empty content. It now checks whetherendcomes after the line where the data starts.sight parse --jsonsummarize price [w=population]: weight words now include every abbreviation Stata 18 accepts, checked in Stata 18:weight≥w,fweight≥fw,frequency≥freq,aweight≥aw,cellsize≥cell,pweight≥pw,iweight≥iw. Matching is exact-case.[f=x],[fre=x],[cel=x]and[W=x]are r(198) in Stata and are not treated as weights.foreach v of var mpg price:list_typeis nowvarlist, with itemsmpg,price. Stata 18 accepts three letters or more ofvarlist,newlist,numlist,localandglobal.of vaandof loare r(198).else /* note */ if 1 display 2:else_ifis now true. It comes from the parser'sis_else_ifflag instead of the second raw token.syntax [, Level(integer 95)]:defaultis now"95". Anintegerorrealoption's default is the number after its type. Hover showsLevel(integer 95)instead ofLevel(integer default(95)).display runiform():args[0].textis nowruniform().Performance: formatting with inline
mata:/python:lines recomputed line offsets and rebuilt the whole string for every placeholder. It now computes offsets once and makes the replacements in one pass. Indentation diagnostics on 1,000 lines ofmata: x = 1went from 11.3 ms to 2.3 ms.Outside the formatter/CLI files: two small
src/parser/index.tschanges, the empty()group and the integer/realsyntaxdefault. They invert two existing tests that asserted empty groups are dropped (tests/unit/parser.test.ts,tests/property/parenthesized-group-parsing.prop.test.ts). The hover option signature insrc/providers/hover.tschanges too.Proof: new tests in
tests/unit/formatter-preserves-written-text.test.ts(both formatter modes, with a second-pass check) andtests/unit/cli/parse-graph-json.test.ts, plus anabbreviations.dogolden fixture. All 11 fail on main and pass here.sight checkover the 3,780 base ados gives the same diagnostics as main. Source-preserving output on those files is byte-identical to main. In AST mode 398 files change, all from the two fixes above, and the set of files that change on a second format is unchanged.check:line-endings,typecheck,bun test ./tests(9,957 pass, 0 fail) andlinteach pass when run separately.Created with Claude Opus 5.5 in Claude Code.