Repository navigation
End a * comment where Stata does, and read * after unab's colon and Mata's :* as code - #360
Merged
Merged
Conversation
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 14 minutes. View limit details
|
jbearak
force-pushed
the
lexer-star-comments
branch
from
November 5, 2026 00:47
f932b8d to
0ea5417
Compare
…ata's :* as code Under `#delimit ;`, a `*` comment ran to the end of its line, so `* comment` then `gen q = 9;` lexed `gen q` as code, and `gen y = a; * c; gen z = 2;` hid `gen z`. Stata 18 ends the comment at the next `;`, across lines, or at the end of the file. A `;` inside "...", a block comment, or after a `//` that follows a space or tab doesn't count. In cr mode, a ` ///` in a `*` comment joins the next line into the comment. A `*` after any colon was a comment, so `unab x : *` lost its wildcard and `mata: z = x :* y` lost `:* y`. The lexer now tracks where a command starts. After a colon, `*` is a comment only where a command starts (`capture:`, `quietly:`, `version 18:`, `frame f:`, `xi:`). The same rule applies to a line-start `*` under `#delimit ;` and after a `///` line in cr mode (`gen r = a ///` then `* b` multiplies), and to a `*` after capture, quietly, or noisily (`gen r = quietly * 2` multiplies). In a Mata block, `:*` is never a comment. The parser's prefix-command maps move to utils/stata-prefix-commands.ts so the lexer uses the same lists.
jbearak
force-pushed
the
lexer-star-comments
branch
from
November 5, 2026 00:55
0ea5417 to
2597c23
Compare
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.
Sight disagreed with Stata about where a
*comment ends, so it misread which code runs:#delimit ;, a*comment ran only to the end of its line. Stata 18 runs it to the next;. After* commentthengen q = 9;, Stata never creates q, but Sight readgen q = 9as code. On one line,gen y = a; * c; gen z = 2;runsgen zin Stata, but Sight's comment swallowed it.*after any colon was a comment, sounab x : *lost its wildcard and Mata'sx :* ylost:* y.* note ///joins the next line into the comment in Stata. Sight read that line as code.The lexer now ends a
*comment where Stata does. Under#delimit ;it runs to the next;, across lines, or to the end of the file, past any#delimit cr. A;doesn't count inside"...", inside/* */, or after a//or///that follows a space or tab. In cr mode, a///in the comment continues it onto the next line.The lexer also tracks where a command starts:
*is a comment only aftercapture/quietly/noisily,version 18:,frame f:andxi:.unab x :,local m :,gettoken,by g:,svy:andbootstrap:it is code. Afterby,svyandbootstrap, Stata 18 reads*as the command name and fails.*in both modes, sogen r = a ///then* bmultiplies. It also coversgen r = quietly * 2, which multiplies a variable named quietly (the case Read a /* */ comment around a colon as whitespace, and a mid-statement * under #delimit ; as multiplication #351 left open).:*is never a comment.The parser's prefix-command maps move to
src/utils/stata-prefix-commands.ts, unchanged, so the lexer uses the same lists.Four test fixtures from #350/#356 used
#delimit ;comments without a;(* keepthen};,* cthenend;). In Stata those comments hide the}orend, so the fixtures now end each comment with;.Proof: I ran every rule on StataMP 18, including a fixture whose undefined-macro warnings from
sight checknow match Stata's output (main got all three wrong). The new lexer tests fail on main (9 of them) and pass here. The new formatter tests, including*comments between#delimit ;statements on top of #358, pass and are idempotent in both modes. Thesight parse --jsongoldens pass with no schema change. All four gates pass.Reviewed with sol-loop: 2 rounds with gpt-6.1-sol. Sol verdict: approved
Created with Claude Opus 5.5 in Claude Code (T3 Code); reviewed by GPT-6.1 Sol in Codex.