Skip to content

Read a ///-continued mata: line as Mata, keep prefix options from macros, and open the Mata block of if 1 mata - #418

Merged
jbearak merged 1 commit into
mainfrom
t3/fix-parser-inline-mata-prefix-options
Nov 19, 2026
Merged

jbearak merged 1 commit into
mainfrom
t3/fix-parser-inline-mata-prefix-options

Conversation

@jbearak

@jbearak jbearak commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Stacked on #417. Review that first; this PR's own change is the top commit.

Three cases where code added since v0.15.1 misreads Stata. Each was checked against StataMP 18:

  1. mata: /// then x = 2 runs x = 2 in Mata. The parser stopped the inline statement at the physical line break, so x = 2 became a Stata command named x. Worse, AST formatting printed mata: /// transpose then V = X' as V = X, silently dropping the transpose. The inline statement now follows ///, and its content is the joined Mata code (x = 2). AST formatting no longer loses the transpose in either mode. A bare /// with no note is joined onto one line, as for commands. Stata log: mata: /// transpose / V = X' / mata: V prints the 2×1 transpose.
  2. svy, `opts': mean income lost `opts' (for example a subpop()) when AST formatting printed the prefix, because the prefix-option parser skipped anything that wasn't a word. Macro options (`opts', $g, ${h}, `o'(x)) are now options. No token there is dropped any more.
  3. if 1 mata has condition 1, and its command opens the Mata block through end (also if … python, else mata). Before: condition 1 mata, an empty body, and { required. Stata log: if 1 mata opens the Mata prompt, and y = 5 is set.

One intended divergence: the context tracker's inline_embedded_statement_end (src/utils/statement-span.ts) still ends a ///-continued inline statement on the opener line. Changing it to match the parser made source-preserving formatting leave the continued line as written (tabs and all) instead of moving it with its statement, which broke formatter-embedded-continuation.test.ts. That is formatter territory, so statement-span.test.ts now records the difference.

Proof: tests/unit/parser-inline-mata-prefix-options.test.ts (10 of its cases fail without this commit's parser change, all pass here), the audit repros before/after, and check:line-endings, typecheck, bun test ./tests (9985 pass, 0 fail) and lint, each run separately on this branch.

Created with Claude Opus 5.5 in Claude Code.

@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 29 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: 36474ed5-a35e-4895-93e6-958c0c8fc450
Commits

Reviewing files that changed from the base of the PR and between b8819dc and 61a6a30.

Files selected for processing: 3

  • src/parser/index.ts
  • tests/unit/parser-inline-mata-prefix-options.test.ts
  • tests/unit/statement-span.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Base automatically changed from t3/fix-parser-regressions to main November 19, 2026 14:50
…ros, and open the block of if 1 mata

- mata: /// then x = 2 runs x = 2 in Mata (StataMP 18); the parser
  made it a Stata command, and AST formatting printed V = X' after
  mata: /// note as V = X
- svy, `opts': mean income keeps `opts' (and $g, ${h}, `o'(x))
  when AST formatting prints the prefix
- if 1 mata has condition 1, and its command opens the Mata block
  through end
@jbearak
jbearak force-pushed the t3/fix-parser-inline-mata-prefix-options branch from 5089bc9 to 61a6a30 Compare November 19, 2026 14:53
@jbearak
jbearak merged commit 661ffb8 into main Nov 19, 2026
16 checks passed
@jbearak
jbearak deleted the t3/fix-parser-inline-mata-prefix-options branch November 19, 2026 15:01
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