Skip to content

Parse a prefixed frame block named by a macro as one frame block, not a command named frame - #406

Merged
jbearak merged 1 commit into
mainfrom
t3/parse-prefixed-frame-blocks
Nov 6, 2026
Merged

jbearak merged 1 commit into
mainfrom
t3/parse-prefixed-frame-blocks

Conversation

@jbearak

@jbearak jbearak commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

A frame block with prefixes is already one frame statement on 0.17.3: capture noisily frame F { … } parses with prefixes: ["capture", "noisily"], frame: "F", and a body. A prefixed block whose frame name is a macro did not:

program define p
    capture noisily frame `0' {
        replace x = 1
    }
end

Here frame and `0' became a plain command named frame, the { was reported as OPEN_BRACE_ALONE, and the block's body and everything after it were misread. In this example the program swallowed the rest of the file, and Sight reported Missing "end". The one-line form had the same gap: capture noisily frame `f': replace x = 1 came out as a command named frame, so replace was lost. This affects tools that walk prefixed frame blocks through sight parse --json, as well as the editor's diagnostics.

The unprefixed path already accepted a macro as the frame name. The prefixed-block check and the frame name: prefix path now use the same check: a word, or a local or global macro reference.

Checked in StataMP 18 (the fixture frame-blocks.do, run as is):

  • frame F {, capture noisily frame F {, quietly frame F {, noisily quietly capture frame F {, capture noisily frame `f' {, and quietly capture frame $g { all run their bodies in frame F;
  • frame F: cmd and capture noisily frame `f': cmd run one command, with no block;
  • a frame F { inside a foreach loop runs once per iteration.

For a missing }, Stata reports program error: matching close brace not found, both at the end of a file and when a program's end comes first. Sight reports Missing closing brace for frame block at the end of a file. As for every other block type, it ends the program at end and adds no error there (the convention from #369 and #393).

The JSON shape gains no fields. docs/cli.md now says that a frame statement has prefixes, that frame is the name as written (possibly a macro), and how a missing } is reported.

Proof: new parser tests and two sight parse --json golden fixtures (frame-blocks.do, frame-unclosed.do). 7 of these tests fail without the fix. Every fixture form also runs in StataMP 18. Line endings, typecheck, bun test ./tests (9,783 pass, 0 fail), and lint pass.

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

Created with Claude Opus 5.5 in Claude Code (T3 Code).

Summary by CodeRabbit

  • New Features
    • The parser now recognizes frame blocks and frame command prefixes that use macro-based frame names, including abbreviated forms.
    • Frame blocks can be nested and combined with command prefixes. Unclosed frame blocks are reported as syntax errors; a program’s end does not close an open frame block.
  • Documentation
    • Updated CLI parsing documentation to describe frame prefixes, macro-valued names, frame block syntax, and unclosed-block behavior.

`capture frame `f' {` and `cap frame $g {` fell back to a plain command
named `frame`, so the program or file after it was misread, and
`capture frame `f': cmd` lost `cmd`. The unprefixed path already
accepted a macro name; the prefixed block and one-line prefix paths
now use the same check. Stata 18 runs every form.
@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Frame-block and frame-prefix parsing now accepts local or global macro references as frame names. Documentation and tests cover prefixed blocks, one-line frame prefixes, nested blocks, and unclosed-block behavior.

Changes: Frame Block Parsing

Layer / File(s) Summary
Macro-aware frame recognition and parser tests
src/parser/index.ts, tests/unit/prefixed-control-flow.test.ts, docs/cli.md
Frame-block and frame-prefix parsing accepts macro-reference tokens as frame names. Unit tests cover prefixed and nested blocks, one-line prefixes, missing braces, and program termination. The CLI documentation describes the frame statement shape and unclosed-block behavior.
CLI JSON fixture coverage
tests/fixtures/cli-json/project/frame-*.do, tests/fixtures/cli-json/expected/graph.json, tests/fixtures/cli-json/expected/parse.json, tests/unit/cli/json-golden.test.ts
Added CLI fixtures and expected JSON output for literal and macro-named frame blocks, prefixes, nesting, and unclosed blocks. Both fixtures are included in the graph and parse golden tests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

  • jbearak/sight#347: Adds the CLI JSON output and golden tests that this change extends.
  • jbearak/sight#378: Extracts a program signature from a syntax statement inside a frame block.
  • jbearak/sight#369: Changes program termination behavior for end inside a frame block.
Merge Risk: Minimal · up to becd2

Prefixed frame blocks and one-line frame commands that name a frame with a macro are now parsed as frame blocks rather than as a plain command named frame. No concrete merge-blocking risk remains after review.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title accurately describes the main parser fix for prefixed frame blocks with macro names.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 3 files. (5 skipped: 5 unsupported.)

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

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: 95fa2c5c-5c3f-4077-b32f-c56f34d8f791
Commits

Reviewing files that changed from the base of the PR and between e366854 and becd26d.

Files selected for processing: 8

  • docs/cli.md
  • src/parser/index.ts
  • tests/fixtures/cli-json/expected/graph.json
  • tests/fixtures/cli-json/expected/parse.json
  • tests/fixtures/cli-json/project/frame-blocks.do
  • tests/fixtures/cli-json/project/frame-unclosed.do
  • tests/unit/cli/json-golden.test.ts
  • tests/unit/prefixed-control-flow.test.ts

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

@jbearak
jbearak merged commit e6dc503 into main Nov 6, 2026
22 of 23 checks passed
@jbearak
jbearak deleted the t3/parse-prefixed-frame-blocks branch November 6, 2026 21:51
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