go: parse.sx — binary operators via Pratt precedence climbing + 9 tests [consumes-pratt]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 39s

gp-parse-expr / gp-pratt-loop implement classic Pratt climbing
against go-precedence-table (entry shape from lib/guest/pratt.sx).
The kit gives us pratt-op-lookup + accessors; the climbing loop
itself stays per-language (per kit header — Lua and Prolog have
opposite conventions).

Left-associative ops raise the right-recursion min by 1; right-
associative would keep prec. All Go binary operators are left-assoc.

AST shape: a binary node is emitted as
  (ast-app (ast-var OP) [LHS RHS])
— canonical ast-app rather than a Go-specific binary node, since a
future evaluator can recognise operator-named apps without losing
information.

Coverage: equal-prec left-to-right, * tighter than +, && tighter
than ||, comparison tighter than &&, long left-assoc chains, mixed
literal+ident operands.

parse 26/26, total 155/155.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 07:39:03 +00:00
parent 976c6dd0ef
commit 750035d543
5 changed files with 143 additions and 21 deletions

View File

@@ -157,8 +157,9 @@ Progress-log line → push `origin/loops/go`.
- [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).
- [x] Binary operators (Pratt precedence climbing using `pratt-op-lookup`
+ Go precedence table). Operator app emitted as
`(ast-app (ast-var OP) [LHS RHS])`; left-assoc raises right-min by 1.
- [ ] 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]`.
@@ -175,7 +176,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: 17/17.
- **Acceptance:** parse/ suite at 80+ tests. Current: 26/26.
### Phase 3 — Bidirectional type checker, MVP (`lib/go/types.sx`) ⬜
- **Independent implementation.** Do NOT use lib/guest/static-types-
@@ -434,6 +435,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 cont.: binary operators via Pratt precedence
climbing. `gp-pratt-loop` consumes `pratt-op-lookup` against
`go-precedence-table`; left-assoc bumps right-min by 1, right-assoc
keeps prec. Binary op nodes are `(ast-app (ast-var OP) [LHS RHS])` —
uses the canonical `ast-app` shape rather than inventing a Go-specific
binary node. Covers: equal-prec left-to-right, `*` tighter than `+`,
`&&` tighter than `||`, comparison tighter than `&&`, long chains.
+9 tests, parse 26/26, total 155/155. `[consumes-pratt]`.
- 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