Skip to content

End a * comment where Stata does, and read * after unab's colon and Mata's :* as code - #360

Merged
jbearak merged 1 commit into
mainfrom
lexer-star-comments
Nov 5, 2026
Merged

jbearak merged 1 commit into
mainfrom
lexer-star-comments

Conversation

@jbearak

@jbearak jbearak commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Sight disagreed with Stata about where a * comment ends, so it misread which code runs:

  • Under #delimit ;, a * comment ran only to the end of its line. Stata 18 runs it to the next ;. After * comment then gen q = 9;, Stata never creates q, but Sight read gen q = 9 as code. On one line, gen y = a; * c; gen z = 2; runs gen z in Stata, but Sight's comment swallowed it.
  • A * after any colon was a comment, so unab x : * lost its wildcard and Mata's x :* y lost :* y.
  • In cr mode, * 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:

  • After a colon, * is a comment only after capture/quietly/noisily, version 18:, frame f: and xi:.
  • After unab x :, local m :, gettoken, by g:, svy: and bootstrap: it is code. After by, svy and bootstrap, Stata 18 reads * as the command name and fails.
  • The same rule covers a line-start * in both modes, so gen r = a /// then * b multiplies. It also covers gen 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).
  • In Mata, :* 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 ; (* keep then };, * c then end;). In Stata those comments hide the } or end, 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 check now 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. The sight parse --json goldens 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.

@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 14 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available. Your 35 included PR review attempts over the past 7 days set your current allowance at 8 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: 1c0357ec-f0b5-4ade-9c66-bca4e91a0cba
Commits

Reviewing files that changed from the base of the PR and between b99ebf8 and 2597c23.

Files selected for processing: 7

  • src/lexer/index.ts
  • src/parser/index.ts
  • src/utils/stata-prefix-commands.ts
  • tests/property/block-ending-trivia-formatting.prop.test.ts
  • tests/unit/cli/parse-graph-json.test.ts
  • tests/unit/formatter-statement-structure.test.ts
  • tests/unit/lexer-star-comments.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@jbearak
jbearak force-pushed the lexer-star-comments branch from f932b8d to 0ea5417 Compare November 5, 2026 00:47
…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
jbearak force-pushed the lexer-star-comments branch from 0ea5417 to 2597c23 Compare November 5, 2026 00:55
@jbearak
jbearak merged commit 6f4b3da into main Nov 5, 2026
16 checks passed
@jbearak
jbearak deleted the lexer-star-comments branch November 5, 2026 01:00
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