Repository navigation
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
Conversation
… 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]>
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 11 minutes. View limit details
|
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.
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
}orend, 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 amata { … }block, which ends with}rather thanend 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 isifblocks in Stata's own_bmapredict_mean_std.ado.The parser now records how each block closed:
closed_by_braceon brace blocks;closed_by_endon a program;is_single_statementon a brace-lesselse, asifalready 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/.adofiles). 202 files differ:mata { }and{-in-a-local cases above. Each now has a regression test that fails on the old detector.else { local i=1 }. StataMP 18 rejects these ("code follows on the same line as open brace", r(198)); they only run under an oldversion. Both detectors' readings there follow error recovery.Typecheck, lint, and
bun test ./testspass (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.