Skip to content

Record on each block whether its own } or end closed it, and let Send to Stata read that instead of pairing braces itself - #393

Merged
jbearak merged 1 commit into
mainfrom
refactor/block-closers
Nov 5, 2026
Merged

jbearak merged 1 commit into
mainfrom
refactor/block-closers

Conversation

@jbearak

@jbearak jbearak commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Send to Stata sends a whole block when the cursor is on its header or closer. To decide whether a block was closed by its own } or end, it paired { and } tokens itself, because the parser knew the answer but didn't record it. The token pairing had two failure modes. It lost track after a mata { … } block, which ends with } rather than end mata. It also counted a { inside a local's value as an opener. In both cases every block after that point stopped being found. One example is if blocks in Stata's own _bmapredict_mean_std.ado.

The parser now records how each block closed:

  • closed_by_brace on brace blocks;
  • closed_by_end on a program;
  • is_single_statement on a brace-less else, as if already has.

The detector reads these fields, and its brace pairing is deleted (−216/+114 lines). The six identical copies of the parser's code for closing a brace block are now one helper.

Proof: I ran the old and new detector over 3,858 files (Stata's 3,780 base ados plus the repo's .do/.ado files). 202 files differ:

  • 2 files have no parse errors, and the new reading is correct in both. These are the mata { } and {-in-a-local cases above. Each now has a regression test that fails on the old detector.
  • 200 files use one-line braces such as else { local i=1 }. StataMP 18 rejects these ("code follows on the same line as open brace", r(198)); they only run under an old version. Both detectors' readings there follow error recovery.

Typecheck, lint, and bun test ./tests pass (9672 tests).

Reviewed with sol-loop: 1 round with gpt-6.1-sol. Sol verdict: approved

Created with Claude Opus 5.5 in T3 Code.

… to Stata read that instead of pairing braces itself

The parser knew which `}` or `end` closed each block but didn't say,
so Send to Stata paired brace tokens itself to work it out. That
pairing lost track after a `mata {` block, which ends with `}`, and
after a `{` in a local's value, and then missed every block that
followed. Blocks now carry closed_by_brace (a program, closed_by_end;
a brace-less else, is_single_statement), the six copies of the parser's
brace-closing code are one helper, and the detector's token pairing
is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 5, 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 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 65 included PR review attempts over the past 7 days set your current allowance at 2 reviews 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: a47ca5af-ea50-4e9b-8fda-f5485eb2ff4e
Commits

Reviewing files that changed from the base of the PR and between 630bd4d and 148d3f0.

Files selected for processing: 4

  • client/src/send-to-stata/statement-detector.ts
  • src/parser/index.ts
  • src/types/index.ts
  • tests/unit/send-to-stata/statement-detector.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@jbearak
jbearak merged commit 13ad965 into main Nov 5, 2026
16 checks passed
@jbearak
jbearak deleted the refactor/block-closers branch November 5, 2026 21:37
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