Skip to content

feat(grammar): a statement if/match ends at its closing brace (Rust rule) - #863

Draft
hyperpolymath wants to merge 1 commit into
mainfrom
claude/gifted-lamport-k0mc5l-stmt-ends
Draft

hyperpolymath wants to merge 1 commit into
mainfrom
claude/gifted-lamport-k0mc5l-stmt-ends

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Owner ruling 2026-12-01 ("Rust rule: statement ends"), superseding the #644 continuation rule.

What changes

A statement-position if or match ends at its own closing }, as in Rust:

Source Before After
if c { .. } then (a, b) on the next line a call on the if's Unit (type error) a statement, then a tuple
match o { .. } -1; one subtraction the match, then -1;
{ let x = 1; if c { x } else { 2 } } Int Int (unchanged)
{ match x { .. } } the match's value the match's value (unchanged)
if c { .. }; (trailing ;) accepted accepted (unchanged)

How

  • The continuation came from two reduce/reduce conflicts: statement against expression if/match, on *, -, (, [, &, | and }. Menhir resolves those in favour of the production that appears first.
  • stmt now sits before expr_primary, so the statement reading wins. Each statement also reports whether it is block-like and ended without ;.
  • block_of_stmts makes a trailing block-like statement the block's value, as Rust's trailing-expression rule does. That keeps blocks ending in if/match valued.
  • The conflict counts are unchanged (2 reduce/reduce states); only their resolution flips.

Measured before changing

  • I diffed the old parser (main 4a55253) against the new one across 611 .affine files: the affinescript stdlib, tests, examples and tools, plus consent-aware-inspector/src/core. 0 print a different AST.
  • 85 of those files parse under neither compiler (other faces, negative fixtures).
  • Not measured: other estate repos with .affine sources that are not cloned here.

Tests

  • test_match_statement_self_terminates now pins the new rule:
    • a match followed by -1; gives two statements;
    • an if followed by a tuple gives a statement and a tuple value;
    • a trailing if, a trailing match and a lone match keep the block's value.
  • dune runtest: 849 pass. run_codegen_bun_tests.sh: pass. check-soundness-ledger.sh: 5/5. dune build @fmt: exit 0. Governance: PASS.

Docs and ledger

Interplay with #862

#862 adds StatementContinued, an error that names the old rule. With this PR, the shapes it targets no longer produce an error. Whichever merges second should drop StatementContinued and keep #862's located NotAFunction and char_to_string. I'll do that in the second PR once the first lands.


Generated by Claude Code

…ule)

Owner ruling 2026-12-01. It supersedes the #644 continuation rule, under
which a statement `if`/`match` followed by `(`, `[`, `*`, `-`, `&` or `|`
continued the expression. So `if c { .. }` followed on the next line by
`(a, b)` was a call on Unit, and `match o { .. } -1;` subtracted.

How: the continuation came from two reduce/reduce conflicts (statement
vs expression `if`/`match`, on those six tokens and `}`). Menhir resolves
those in favour of the production that appears first.
- `stmt` now appears before `expr_primary`, so the statement reading wins.
- Each statement also reports whether it is block-like and ended without
  `;`.
- `block_of_stmts` makes a trailing one the block's value. That is Rust's
  trailing-expression rule, and it keeps `{ ..; if c { a } else { b } }`
  and `{ match x { .. } }` valued.

Measured before changing:
- The old (main 4a55253) and new parser print identical ASTs for all 611
  .affine files available locally: the affinescript stdlib, tests,
  examples and tools, plus consent-aware-inspector's src/core.
- 85 of those parse under neither compiler (other faces, negative
  fixtures).
- Other estate repos with .affine code were not measured.

Tests: test_match_statement_self_terminates now pins the new rule (match
then `-1;`; if then a tuple; a trailing if/match and a lone match keep
the value). dune runtest: 849 pass. Bun harnesses pass.

docs/ON-RAMP.adoc "Statements and `;`" restated. The ledger part of #856
is ported again, because main is red on property 3, and the stamp is
advanced to 4a55253.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDiosfvobXq67wbduuK
@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

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: ASSERTIVE
  • Plan: Advanced
  • Run ID: 138bcc34-6442-470d-922b-e5324ac8f696
Commits

Reviewing files that changed from the base of the PR and between 4a55253 and 5437e18.

Files selected for processing: 5

  • docs/ON-RAMP.adoc
  • docs/SOUNDNESS.adoc
  • lib/parser.mly
  • test/test_e2e.ml
  • tools/soundness-anchors.sha256
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@gitnotebooks

gitnotebooks Bot commented Dec 1, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Dec 1, 2026

Copy link
Copy Markdown

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.

2 participants