Repository navigation
Read a ///-continued mata: line as Mata, keep prefix options from macros, and open the Mata block of if 1 mata - #418
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 29 minutes. View limit details
|
…ros, and open the block of if 1 mata
- mata: /// then x = 2 runs x = 2 in Mata (StataMP 18); the parser
made it a Stata command, and AST formatting printed V = X' after
mata: /// note as V = X
- svy, `opts': mean income keeps `opts' (and $g, ${h}, `o'(x))
when AST formatting prints the prefix
- if 1 mata has condition 1, and its command opens the Mata block
through end
jbearak
force-pushed
the
t3/fix-parser-inline-mata-prefix-options
branch
from
November 19, 2026 14:53
5089bc9 to
61a6a30
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.
Stacked on #417. Review that first; this PR's own change is the top commit.
Three cases where code added since v0.15.1 misreads Stata. Each was checked against StataMP 18:
mata: ///thenx = 2runsx = 2in Mata. The parser stopped the inline statement at the physical line break, sox = 2became a Stata command namedx. Worse, AST formatting printedmata: /// transposethenV = X'asV = X, silently dropping the transpose. The inline statement now follows///, and its content is the joined Mata code (x = 2). AST formatting no longer loses the transpose in either mode. A bare///with no note is joined onto one line, as for commands. Stata log:mata: /// transpose/V = X'/mata: Vprints the 2×1 transpose.svy, `opts': mean incomelost`opts'(for example asubpop()) when AST formatting printed the prefix, because the prefix-option parser skipped anything that wasn't a word. Macro options (`opts',$g,${h},`o'(x)) are now options. No token there is dropped any more.if 1 matahas condition1, and its command opens the Mata block throughend(alsoif … python,else mata). Before: condition1 mata, an empty body, and{ required. Stata log:if 1 mataopens the Mata prompt, andy = 5is set.One intended divergence: the context tracker's
inline_embedded_statement_end(src/utils/statement-span.ts) still ends a///-continued inline statement on the opener line. Changing it to match the parser made source-preserving formatting leave the continued line as written (tabs and all) instead of moving it with its statement, which brokeformatter-embedded-continuation.test.ts. That is formatter territory, sostatement-span.test.tsnow records the difference.Proof:
tests/unit/parser-inline-mata-prefix-options.test.ts(10 of its cases fail without this commit's parser change, all pass here), the audit repros before/after, andcheck:line-endings,typecheck,bun test ./tests(9985 pass, 0 fail) andlint, each run separately on this branch.Created with Claude Opus 5.5 in Claude Code.