Repository navigation
Report an end that closes nothing from the parsed program structure, not a separate line scan - #398
Merged
Merged
Conversation
… a program only at an end that begins its line The context tracker found a stray `end` by scanning raw lines with its own program and input tracking, which disagreed with the parser and with Stata. It missed a second `end;` under #delimit ;, `end foo`, and the program's own `end` after input data in a program (whose `end` Stata takes as the program's), and it reported mata blocks ending programs that `mata : x` one-liners never opened. UNEXPECTED_END and EMBEDDED_BLOCK_ENDS_PROGRAM now come from the AST, in providers/end-diagnostics.ts, and the raw scan is gone. The parser now ends a program only at an `end` that begins its line, as the lexer and Stata do, so `} end while` in old ado-files no longer cuts a program short. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 19 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.
Unexpected endcame from the context tracker, which re-derived program and block structure from raw lines with its own regexes, separately from the parser. The two disagreed. On Stata's 3,780 base ados the tracker reported 57endlines that Stata accepts: theendofinputdata inside a program, a program'sendafter code that the tracker misread as opening a block, and lines past a top-levelexit, which Stata never reads.Now the check reads the parsed statements (
src/providers/end-diagnostics.ts):UNEXPECTED_ENDis a top-levelendstatement that closes nothing.end mataandend pythonare excluded, since the context tracker still checks those.EMBEDDED_BLOCK_ENDS_PROGRAMcomes from the program node's existingends_at_embedded_block.exit, but not atcapture exit, which Stata reads past.The parser now ends a program only at an
endthat begins its line, meaning only whitespace, a/* */comment or;comes before it. Legacy ados write} end whileto label a closing brace, and that no longer ends the program. The tracker's line-based copies of this logic are removed.Proof: base ados vs main: 57
UNEXPECTED_ENDfalse positives removed, 2 added. Both new ones (export.ado:171,import.ado:261) come from an existing lexer bug:mata : x(with a space) is one-line Mata in Stata, but the lexer opens a Mata block there. That fix changes ~400 unrelated diagnostics, so it's a separate change. Checked in StataMP 18: a strayend,end fooand an extraend;are r(199). Typecheck, lint, andbun test ./testspass (9661 tests).Reviewed with sol-loop: 2 rounds with gpt-6.1-sol. Sol verdict: approved
Created with Claude Opus 5.5 in T3 Code.