Commit 3f39c3f
feat(grammar): self expression + inherent impl blocks (Refs #122)
Two pre-existing AffineScript grammar gaps blocked idiomatic OO and
made even stdlib/traits.affine unparseable:
1. SELF_KW had no expression production. The receiver-param productions
already bind a parameter named "self", but the body could never
reference it — `self.field` / `self.method(x)` was always a parse
error. Add `| SELF_KW { ExprVar (mk_ident "self" ...) }` to
expr_primary; it resolves/typechecks as the ordinary "self"
parameter binding (no resolver/typechecker change needed).
2. Inherent `impl Type { ... }` was a parse error at the `{`: the rule
pre-committed to `impl_trait_ref? self_ty` where both alternatives
start with an ident, an unresolved ambiguity. Restructure to parse
one type_expr unconditionally, then an optional `FOR type_expr`;
when `FOR` is present the leading type was the trait
(trait_ref_of_type_expr recovers its name/args). Conflict-free;
trait impls (`impl Trait for Type`) still parse identically.
Verified: `impl Counter { fn bumped(ref self, by: Int) -> Int {
self.start + by } }` compiles; trait-impl + receiver-first probes
still compile; `dune runtest` unchanged (same 2 pre-existing E2E
Node-CJS vscode failures, no new regressions); Deno-ESM suite green.
Residual (separate, tracked): `Self` as a *type annotation* in trait
default methods (stdlib/traits.affine:12 `ref other: Self`) — a narrow
grammar/typecheck item, distinct from `self`-the-expression.
Refs #122.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 76bafec commit 3f39c3f
1 file changed
Lines changed: 30 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
23 | 35 | | |
24 | 36 | | |
25 | 37 | | |
| |||
535 | 547 | | |
536 | 548 | | |
537 | 549 | | |
538 | | - | |
539 | | - | |
| 550 | + | |
| 551 | + | |
540 | 552 | | |
541 | 553 | | |
542 | | - | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
543 | 560 | | |
544 | 561 | | |
545 | 562 | | |
546 | 563 | | |
547 | 564 | | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
| 565 | + | |
| 566 | + | |
552 | 567 | | |
553 | 568 | | |
554 | 569 | | |
| |||
646 | 661 | | |
647 | 662 | | |
648 | 663 | | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
649 | 672 | | |
650 | 673 | | |
651 | 674 | | |
| |||
0 commit comments