Repository navigation
Parse include using/…, program name', and glued stem'using as Stata does, and keep label text and program-header comments when formatting - #417
Merged
Conversation
…] as Stata does, and keep label/note text and program-header comments when formatting 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
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 minutes. View limit details
|
jbearak
added a commit
that referenced
this pull request
Nov 19, 2026
…ritten when formatting, and read abbreviated weights and foreach list types in parse --json (#419) * Keep embedded strings, option arguments, call parens and blank input 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. * Parse include using/…, program `name', glued using and price[`weight'] 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 * Keep Stata console sends from being lost at --more--, while connecting, 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 * Read input data, prefixed mata: and python: openers, and #delimit ; star 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]> * Print no stray ; for an input with no records under #delimit ; 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. --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Several things that parsed correctly in v0.15.1 broke since:
include using/setup.dolooked for a file namedusing, a program named by a macro left itsendunmatched, a glued`stem'usingcut an expression in half, and AST formatting reordered label text and dropped comments. Each case below was checked against StataMP 18 first; the parser now reads them as Stata does.Fixed (all in
src/parser/):include using/setup.do(alsodo,run) takes the pathusing/setup.do.use using fkeepsusingas the keyword. Before:Cannot read file: using, then the included local was reported undefined.program `cmdname'(as in Stata'sdtaverify_115.ado) is a program definition closed by itsend.program drop `x'stays a subcommand. Before:Unexpected "end" command.#delimit ;,program // header commentand thendefine p;definep. Before:Unexpected "end" command.`stem'using,`stem'inand`stem'ifare one name in expressions and varlists. Stata log:generate copy =stem'using + 1listscopy = 8(housing + 1). A keyword glued to a *following* macro (`` ifc' ``) is left a keyword, since the macro may start with a blank.price[`weight']is a subscript (Stata:x = 10in both rows).regress y x [`weight'`exp']is still a weight.label variable/data/define(down tola var,la da,la de),char, andnote …:text keeps itsif/in/usingwords in the AST, and AST formatting prints those statements as written. Stata log:la var income insets the labelin,label define fpl 1 inlists1 in,char income[note] Change in income using wandnote income: three in 1/2keep their text.notes drop income in 1andlabel save … using fkeep their qualifiers. Note: the brief's literal inputlabel variable income Change in income using weightsisinvalid syntax(r(198)) in Stata, since unquoted multi-word labels are not allowed. AST formatting still reordered it, and the same reordering hit the valid forms above.prog def report // note, and also the fullprogram definespelling on main) and a///note before an inlinemata:(capture /// note+mata: …). The AST has no place for either, so the parser now records the statement inunprintable_rangesand AST formatting leaves the file as written. AST mode is opt-in, but this does turn it off for any file whose program headers carry comments. Printing them in place needs a printer change (follow-up).//comments inside a#delimit ;statement made N lookahead scans, which is quadratic.bench.ts: 15/62/248/987 ms → 0/0/1/1 ms for N = 2k/4k/8k/16k. The new test counts token reads through a Proxy and requires 4× the comments to stay under 5× the reads.Follow-ups not in this PR: completion and symbols may now list
`cmdname'as a program name, and the lexer's program-header check (src/utils/program-definition.ts) still reads only a word there.Proof:
tests/unit/parser-release-audit-regressions.test.ts(33 of its cases fail on main, all pass here), the repro commands from the audit before/after as above, andcheck:line-endings,typecheck,bun test ./tests(9965 pass, 0 fail) andlint, each run separately.Created with Claude Opus 5.5 in Claude Code.