go: parse.sx — func + method declarations + 8 tests [shapes-static-types-bidirectional]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s
Adds Go func and method declarations:
func main() {}
func add(x, y int) int { return x + y }
func mix(x int, y string) {}
func divmod(a, b int) (int, int) {}
func sig(x int) int (no body)
func (p *Point) String() string { ... } (method, pointer recv)
func (s Stack) Len() int { ... } (method, value recv)
func nested() { if true { x := 1; { y := 2 } } } (nested braces)
New gp-parse-decl-param-group implements named-greedy disambiguation:
collects consecutive 'ident [, ident]*' then parses a type. Anonymous
mixed lists like 'func(int, string)' are a known limitation (parser
treats first ident as a name); flagged in plan.
gp-skip-block! brace-balances over the body; the AST stores ':body'
as a sentinel until statement parsing lands. Methods use the receiver
parameter shape directly.
AST:
(list :func-decl NAME PARAMS RESULTS BODY)
(list :method-decl RECV NAME PARAMS RESULTS BODY)
**All five `:field` binding-group consumers now exist** across the
parser: struct fields, var, const, func params, method receivers.
That's strong cross-deliverable validation of the ast-binding-group
proposal from Blockers — five different declaration contexts, one
shared shape.
This is the chisel-relevant insight for sister plan static-types-
bidirectional: an entry has been appended to its design diary
describing how `:field` will be the load-bearing input shape for
the bidirectional checker's `check Γ e T` judgment across these
contexts.
parse 132/132, total 261/261.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -188,20 +188,21 @@ Progress-log line → push `origin/loops/go`.
|
||||
context (e.g. `if cond { ... }`) my parser would WRONGLY treat
|
||||
the body as a composite; statement parsing will need a "no-
|
||||
composite-here" mode flag — to be added when statements arrive.
|
||||
- [/] Declarations: `package` / `import` / `var` / `const` / `type` all
|
||||
done (single-decl, ungrouped forms). `var`/`const` use the
|
||||
`:field` binding-group shape from Blockers — first cross-deliverable
|
||||
use of the proposed `ast-binding-group`. `func` decls (with method
|
||||
receivers + named params) and parenthesized grouped decls
|
||||
(`var (...)`, `import (...)`) deferred.
|
||||
- [x] Declarations: `package`, `import`, `var`, `const`, `type`, `func`
|
||||
(with named-greedy params + method receivers + body skipped
|
||||
opaquely until statement parsing arrives). All five `:field`
|
||||
consumers now exist (struct fields, var, const, func params, method
|
||||
receivers) — strong signal that `ast-binding-group` belongs in the
|
||||
canonical AST kit. Grouped/parenthesized decls (`var (...)`, etc.)
|
||||
and variadic params deferred. Anonymous param-list disambiguation
|
||||
(`func(int, string)`) is a known parser-greedy limitation, flagged.
|
||||
- [ ] Statements: `if`/`else`, `for` (C-style + range), `switch` (expr +
|
||||
type), `select`, `return`, `defer`, `go`, `break`/`continue`,
|
||||
assign, short-decl `:=`, send `ch <- v`, recv `<-ch`.
|
||||
- [ ] End-to-end: hello-world, fibonacci, FizzBuzz, goroutine ping-pong,
|
||||
struct + method.
|
||||
- **Acceptance:** parse/ suite at 80+ tests. **Acceptance bar crossed:
|
||||
124/124.** Remaining sub-items (func decls, stmts, e2e) keep
|
||||
Phase 2 open ⬜.
|
||||
132/132.** Remaining sub-items (stmts, e2e) keep Phase 2 open ⬜.
|
||||
|
||||
### Phase 3 — Bidirectional type checker, MVP (`lib/go/types.sx`) ⬜
|
||||
- **Independent implementation.** Do NOT use lib/guest/static-types-
|
||||
@@ -518,6 +519,23 @@ Minimal repro: see `lib/go/lex.sx#gl-oct-digit?` and `#gl-match-op`.
|
||||
|
||||
_Newest first. Append one dated entry per commit._
|
||||
|
||||
- 2026-05-27 — Phase 2 cont.: func declarations. `func f() {}`,
|
||||
`func add(x, y int) int { ... }`, multi-group params, multi-return,
|
||||
signature-only (no body), pointer-receiver and value-receiver methods,
|
||||
nested-brace body. New `gp-parse-decl-param-group` uses a named-greedy
|
||||
algorithm: collects consecutive `ident [, ident]*` then parses a
|
||||
type. `gp-skip-block!` brace-balances over the body opaquely; the AST
|
||||
stores `:body` as a sentinel pending statement parsing. With this,
|
||||
**all five `:field` binding-group consumers now exist** (struct
|
||||
fields, var, const, func params, method receivers) — strong cross-
|
||||
deliverable validation of the `ast-binding-group` kit proposal.
|
||||
Anonymous-param-list disambiguation (`func(int, string)`) is a known
|
||||
greedy-parser limitation flagged in plan. +8 tests, parse 132/132,
|
||||
total 261/261. `[shapes-static-types-bidirectional]` — the consistent
|
||||
use of `:field` across decls is what the sister kit's bidirectional
|
||||
checker will use to propagate types from declarations to bindings.
|
||||
|
||||
Sister-plan diary update follows.
|
||||
- 2026-05-27 — Phase 2 cont.: declarations — `package N`, `import "p"`,
|
||||
`var name [TYPE] [= EXPRS]`, `const name [TYPE] [= EXPRS]`,
|
||||
`type NAME TYPE`. New `gp-parse-top` dispatcher routes the five
|
||||
|
||||
@@ -282,6 +282,25 @@ The kits compose; design accordingly.
|
||||
|
||||
_Newest first. Append one dated entry per milestone landed._
|
||||
|
||||
- 2026-05-27 — From Go-on-SX Phase 2 (func decls landing): parser-side
|
||||
observation that's load-bearing for any bidirectional checker. Go's
|
||||
parser ended up with a single shape — `(list :field NAMES TYPE)` —
|
||||
that recurs in five contexts: struct fields, var decls, const decls,
|
||||
func params, and method receivers. Each represents "these names are
|
||||
bound to this type" — exactly the input shape `check` would consume
|
||||
to seed the context with typed bindings.
|
||||
|
||||
**Design insight**: the canonical bidirectional checker should accept
|
||||
`:field`-shaped AST nodes uniformly across these contexts rather than
|
||||
each context defining a bespoke shape. The kit's `check Γ e T`
|
||||
judgment can dispatch on the enclosing form (struct vs var vs
|
||||
func-param vs ...) but the local per-binding shape stays identical.
|
||||
This is what statically-typed guest #2 should also produce — if it
|
||||
does, the kit can ship a `field-bindings → context-extension` helper
|
||||
that all consumers reuse. Cross-ref Go-on-SX plan's Blockers entry on
|
||||
`ast-binding-group` for the parallel AST-kit proposal that supports
|
||||
this. Source: Go-on-SX commit `parse.sx — func declarations`.
|
||||
|
||||
- 2026-05-26 — Plan drafted as design diary. Phase 0 unstarted. Gated on
|
||||
Go-on-SX (first consumer) and a TBD second consumer (recommendation:
|
||||
TypeScript). No code yet — kit cannot exist before two consumers do.
|
||||
|
||||
Reference in New Issue
Block a user