Skip to content

Parse include using/…, program name', and glued stem'using as Stata does, and keep label text and program-header comments when formatting - #417

Merged
jbearak merged 2 commits into
mainfrom
t3/fix-parser-regressions
Nov 19, 2026

Conversation

@jbearak

@jbearak jbearak commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Several things that parsed correctly in v0.15.1 broke since: include using/setup.do looked for a file named using, a program named by a macro left its end unmatched, a glued `stem'using cut 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/):

  1. include using/setup.do (also do, run) takes the path using/setup.do. use using f keeps using as the keyword. Before: Cannot read file: using, then the included local was reported undefined.
  2. program `cmdname' (as in Stata's dtaverify_115.ado) is a program definition closed by its end. program drop `x' stays a subcommand. Before: Unexpected "end" command.
  3. Under #delimit ;, program // header comment and then define p; define p. Before: Unexpected "end" command.
  4. `stem'using, `stem'in and `stem'if are 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.
  5. price[`weight'] is a subscript (Stata: x = 10 in both rows). regress y x [`weight'`exp'] is still a weight.
  6. label variable/data/define (down to la var, la da, la de), char, and note …: text keeps its if/in/using words in the AST, and AST formatting prints those statements as written. Stata log: la var income in sets the label in, label define fpl 1 in lists 1 in, char income[note] Change in income using w and note income: three in 1/2 keep their text. notes drop income in 1 and label save … using f keep their qualifiers. Note: the brief's literal input label variable income Change in income using weights is invalid 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.
  7. AST formatting dropped a comment in any program header (prog def report // note, and also the full program define spelling on main) and a /// note before an inline mata: (capture /// note + mata: …). The AST has no place for either, so the parser now records the statement in unprintable_ranges and 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).
  8. A run of N // 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, and check:line-endings, typecheck, bun test ./tests (9965 pass, 0 fail) and lint, each run separately.

Created with Claude Opus 5.5 in Claude Code.

…] 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
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 38 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 86 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 6aa9bc52-c497-423b-8238-b52027d12891
Commits

Reviewing files that changed from the base of the PR and between 49213d6 and c365114.

Files selected for processing: 2

  • src/parser/index.ts
  • tests/unit/parser-release-audit-regressions.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@jbearak
jbearak merged commit b8819dc into main Nov 19, 2026
16 checks passed
@jbearak
jbearak deleted the t3/fix-parser-regressions branch November 19, 2026 14:50
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant