go: parse.sx scaffold — primary expressions + Go precedence table + 17 tests [consumes-pratt consumes-ast]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s

Starts Phase 2. lib/go/parse.sx defines:
  * go-precedence-table — Go's five operator-precedence levels in the
    (NAME PREC ASSOC) entry shape from lib/guest/pratt.sx, ready for the
    binary-operator iteration to consume via pratt-op-lookup.
  * go-parse(src) — tokenises and parses ONE primary expression: int,
    float, imag, string, rune literals become (ast-literal VALUE);
    identifiers become (ast-var NAME). Built directly on lib/guest/ast.sx
    constructors — no intermediate AST shape.

Conformance.sh extended to load lib/guest/{ast,pratt}.sx and run the
new parse suite. Scoreboard cleanup: drop the "pending" parse row since
the suite is now real.

parse 17/17 (lex still 129/129). Total 146/146.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 07:33:31 +00:00
parent c1baca2e4e
commit 976c6dd0ef
6 changed files with 150 additions and 23 deletions

View File

@@ -154,21 +154,28 @@ Progress-log line → push `origin/loops/go`.
done** — hex floats deferred (rare). Move to Phase 2 next.
### Phase 2 — Parser (`lib/go/parse.sx`) ⬜
- Consume `lib/guest/core/pratt.sx` + `lib/guest/core/ast.sx`. Chisel notes
`consumes-pratt consumes-ast`.
- Grammar coverage:
- Declarations: `package`, `import`, `var`, `const`, `type`, `func`
- Types: basic, slice `[]T`, array `[N]T`, map `map[K]V`, chan `chan T`,
func `func(...)...`, struct, interface, pointer `*T`
- Expressions: literals, identifier, call, index `[]`, slice `[a:b]`,
type assertion `v.(T)`, operators
- Statements: `if`/`else`, `for` (C-style + range), `switch`, `select`,
`return`, `defer`, `go`, `break`/`continue`, assign, short-decl `:=`,
send `ch <- v`, recv `<-ch`
- Output: SX-shaped AST per `lib/guest/core/ast.sx` conventions.
- Tests: round-trip parse of hello world, fibonacci, FizzBuzz, goroutine
ping-pong, struct + method.
- **Acceptance:** parse/ suite at 80+ tests.
- [x] Parser scaffold + Go operator-precedence table (entry shape from
`lib/guest/pratt.sx`) + primary expressions (int/float/imag/string/
rune/ident → ast-literal / ast-var via `lib/guest/ast.sx`).
- [ ] Binary operators (Pratt precedence climbing using
`pratt-op-lookup` + Go precedence table).
- [ ] Unary operators (`!x`, `-x`, `^x`, `*p`, `&v`, `<-ch`).
- [ ] Function calls `f(a, b)` and member access `x.field`.
- [ ] Index `x[i]` and slice `x[a:b]`/`x[a:b:c]`.
- [ ] 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,
pointer `*T`.
- [ ] Composite literals: `T{...}`, `[]T{...}`, `map[K]V{...}`,
`struct{...}{...}`.
- [ ] Declarations: `package`, `import`, `var`, `const`, `type`, `func`
(including methods, parameter lists, return types).
- [ ] 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. Current: 17/17.
### Phase 3 — Bidirectional type checker, MVP (`lib/go/types.sx`) ⬜
- **Independent implementation.** Do NOT use lib/guest/static-types-
@@ -427,6 +434,14 @@ 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 first slice: `lib/go/parse.sx` parser scaffold.
Defines `go-precedence-table` using `lib/guest/pratt.sx` entry shape
`(NAME PREC ASSOC)` — five Go precedence levels, all left-associative
per Go spec § Operator precedence. `go-parse` tokenises via
`go-tokenize`, then `gp-parse-primary` reads one literal / identifier
and emits a canonical AST node via `lib/guest/ast.sx`'s `ast-literal`
/ `ast-var`. parse 17/17, lex still 129/129, total 146/146.
`[consumes-pratt consumes-ast]`.
- 2026-05-27 — **Phase 1 complete.** Operator-set audit: added missing
`~` (Go 1.18+ generics type-set), exhaustive op coverage tests grouped
by category. Two kit gaps observed and logged in Blockers: