go: parse.sx — package/import/var/const/type declarations + 10 tests [consumes-ast]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 33s

First slice of Phase 2 declarations:
  package main                      →  (list :package "main")
  import "fmt"                      →  (ast-import "fmt")    [from kit]
  var x int                         →  var-decl + :field binding
  var x = 5                         →  init only (type inferred)
  var x int = 5                     →  both type and init
  var x, y int = 1, 2               →  multi-name shared type
  const Pi = 3.14                   →  const-decl
  const C int = 42                  →  typed const
  type T int                        →  named alias
  type Point struct { x, y int }    →  named struct

New gp-parse-top dispatches on the leading keyword: routes
package/import/var/const/type to gp-parse-decl; everything else
still goes through gp-parse-expr. Existing expression tests are
unaffected (cur won't be a decl keyword at expression start).

var/const decls use the (:field NAMES TYPE) shape from the
ast-binding-group proposal — first concrete cross-deliverable use:
struct fields, var decls, const decls all envelope through the
same node. That's the smell test for whether the kit shape is
right; so far it's clean.

import uses the canonical ast-import from lib/guest/ast.sx — first
direct use of a kit constructor for a declaration shape.

Grouped/parenthesized decls (var (...), import (...), const (...),
type (...)) and func decls (with method receivers + named params)
deferred to subsequent iterations.

parse 124/124, total 253/253.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 19:44:24 +00:00
parent 632e06d3cf
commit 4922b6e987
5 changed files with 202 additions and 9 deletions

View File

@@ -188,15 +188,20 @@ 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`, `func`
(including methods, parameter lists, return types).
- [/] 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.
- [ ] 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:
114/114.** Remaining sub-items (decls, stmts, e2e) keep Phase 2 open ⬜.
124/124.** Remaining sub-items (func decls, 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-
@@ -513,6 +518,18 @@ 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.: declarations — `package N`, `import "p"`,
`var name [TYPE] [= EXPRS]`, `const name [TYPE] [= EXPRS]`,
`type NAME TYPE`. New `gp-parse-top` dispatcher routes the five
decl keywords to `gp-parse-decl` while preserving expression parsing
for everything else. `var` and `const` reuse the `:field` binding-
group shape from Blockers — **first cross-deliverable use of the
proposed kit shape**: struct fields, func params, and now var/const
decls all share the same `(list :field NAMES TYPE)` envelope. `import`
uses canonical `ast-import` directly. Grouped forms (`var (...)`)
and `func` decls deferred. +10 tests, parse 124/124, total 253/253.
`[consumes-ast]` — first concrete use of `ast-import` from the kit;
also validates the `:field` shape across three contexts.
- 2026-05-27 — Phase 2 cont.: composite literals. `T{}`, `T{1, 2}`,
`T{X: 1, Y: 2}`, `[]T{...}`, `[N]T{...}`, `map[K]V{...}`,
`pkg.T{...}`, nested composites. AST shape