go: parse.sx — index x[i] + slice x[a:b]/x[a:b:c] + 12 tests [proposes-ast]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s

Adds the bracket postfix branch:
  a[0] / a[i] / a[i+1] / m["key"]             → (list :index OBJ IDX)
  a[:] / a[1:] / a[:2] / a[1:2] / a[1:2:3]    → (list :slice OBJ LOW HIGH MAX)

LOW/HIGH/MAX are AST nodes or nil for omitted indices. The 4th MAX
slot is only populated by the three-index full-slice form.

Two new lib/guest/ast.sx kit gaps surfaced (logged in plans/go-on-sx.md
Blockers):

  * No :index node — universal across guests with arrays/maps.
  * No :slice node — Python/Rust/Swift/JS/Ruby all need at minimum the
    two-index form. Go's three-index variant is more specialised but
    fits in the same shape with an optional fourth slot.

Parser is permissive on a[1::3] (strict Go rejects, but the type phase
can enforce the grammar; lexer/parser stays loose).

Chained (a[0][1]) and mixed-with-selector (a[0].field) cases work via
the existing left-associative postfix loop.

parse 61/61, total 190/190.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 07:53:10 +00:00
parent e1c5fdae53
commit e64d72f554
5 changed files with 148 additions and 11 deletions

View File

@@ -167,7 +167,10 @@ Progress-log line → push `origin/loops/go`.
`x.field` (Go-specific `(list :select OBJ "field")` — the AST kit
doesn't ship a selector node; this is a sister-plan-static-types
data point about what the canonical AST is missing).
- [ ] Index `x[i]` and slice `x[a:b]`/`x[a:b:c]`.
- [x] Index `x[i]` and slice `x[a:b]`/`x[a:b:c]`. Go-specific
`(list :index OBJ IDX)` and `(list :slice OBJ LOW HIGH MAX)`
(LOW/HIGH/MAX may be nil) — kit lacks both. Permissive parser
accepts `a[1::3]` (strict Go rejects, but type phase can enforce).
- [ ] Type assertion `v.(T)`.
- [ ] Type expressions: basic, slice `[]T`, array `[N]T`, map `map[K]V`,
chan `chan T` / `chan<- T` / `<-chan T`, func, struct, interface,
@@ -181,7 +184,7 @@ Progress-log line → push `origin/loops/go`.
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. Current: 49/49.
- **Acceptance:** parse/ suite at 80+ tests. Current: 61/61.
### Phase 3 — Bidirectional type checker, MVP (`lib/go/types.sx`) ⬜
- **Independent implementation.** Do NOT use lib/guest/static-types-
@@ -428,7 +431,18 @@ Observed from building the Go parser:
a Go-specific tag. Worth promoting once a second consumer hits the
same need (likely immediately — almost every guest needs it).
Minimal repro: see `lib/go/parse.sx#gp-parse-postfix` (`.` branch).
2. **No index / subscript node.** `x[i]` is universal across nearly every
guest with arrays/maps. Rolled `(list :index OBJ IDX)` locally.
3. **No slice node.** Go's two- and three-index slice expressions are
distinctive but the basic two-index `x[a:b]` shape covers Python,
Rust, Swift, JS, Ruby slicing too. Rolled
`(list :slice OBJ LOW HIGH MAX)` (LOW/HIGH/MAX may be nil for
omitted indices). MAX-as-fourth-field is Go-specific; the canonical
kit shape could ship as `(list :slice OBJ LOW HIGH)` for the common
case and a separate `:slice3` or `:full-slice` for the Go variant.
Minimal repro: see `lib/go/parse.sx#gp-parse-postfix` + `gp-parse-bracket`.
### Kit-gap proposals against `lib/guest/lex.sx`
@@ -453,6 +467,15 @@ 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.: index `x[i]` and slice `x[a:b]` /
`x[a:b:c]` postfix forms. New `gp-parse-bracket` + `gp-parse-bracket-expr`
branch off the same postfix loop as calls/selectors. AST: Go-specific
`(list :index OBJ IDX)` and `(list :slice OBJ LOW HIGH MAX)` —
LOW/HIGH/MAX may be nil for omitted indices. Two more kit gaps logged
(no `:index`, no `:slice` in canonical AST). Permissive on `a[1::3]`.
Covers: literal idx, var idx, expr idx, string idx, chained `a[0][1]`,
mixed `a[0].field`, full slice with three indices. +12 tests, parse
61/61, total 190/190. `[proposes-ast]`.
- 2026-05-27 — Phase 2 cont.: postfix forms — function calls `f(a, b)`
via canonical `ast-app`, and member access `x.field` via Go-specific
`(list :select OBJ "field")`. The AST kit has no selector node;