go: parse.sx — statements (return / short-decl / assign / block) + 9 tests [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 31s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 31s
First slice of Phase 2 statements. Replaces the func-decl ':body'
sentinel with real (:block STMTS) parsing.
gp-parse-stmt dispatches on the leading token:
return [exprs] — (list :return EXPRS)
{ ... } — nested block (recurses into block-body)
lhs := exprs — (list :short-decl LHS-LIST EXPRS)
lhs = exprs — (list :assign LHS-LIST EXPRS)
lhs OP= expr — (list :assign-op OP LHS-LIST [EXPR])
expr — bare expression statement
var/const/type/func keywords — fall through to gp-parse-decl
LHS may be a comma-separated list. Compound-assign covers all 11 Go
forms (+= -= *= /= %= &= |= ^= <<= >>= &^=).
gp-parse-block-body iterates: skips semis, terminates on '}', and for
non-trivial tokens calls gp-parse-stmt. **Two progress guards** added
to avoid infinite loops on unsupported syntax:
* gp-block-body-loop force-advances one token if gp-parse-stmt
returns nil without consuming.
* gp-parse-composite-elems does the same when its expr parser
returns nil — fixes a hang on '`if true {`x := 1`}`' where the
parser was misreading `if true{...}` as a composite literal then
spinning on `:=` inside the brace body.
Existing func/method decl tests updated from the ':body' sentinel to
the new (:block STMTS) shape. Old `gp-skip-block!` left as dead code
(removed once control-flow stmts make the misinterpretation issue
moot).
Control-flow stmts (if/for/switch/select/defer/go/break/continue) and
channel send (`ch <- v`) deferred to subsequent iterations.
parse 141/141, total 270/270.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -196,13 +196,17 @@ Progress-log line → push `origin/loops/go`.
|
||||
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`.
|
||||
- [/] Statements: `return`, short-decl `:=`, assign `=`, compound assign
|
||||
(`+=` etc.), expression stmt, block `{...}` all done. `gp-parse-stmt`
|
||||
replaces the func-body `:body` stub with real `(:block STMTS)`.
|
||||
Progress guards added to block-body and composite-elems loops.
|
||||
`if`/`for`/`switch`/`select`/`defer`/`go`/`break`/`continue`/send
|
||||
deferred to next slice.
|
||||
- [ ] End-to-end: hello-world, fibonacci, FizzBuzz, goroutine ping-pong,
|
||||
struct + method.
|
||||
- **Acceptance:** parse/ suite at 80+ tests. **Acceptance bar crossed:
|
||||
132/132.** Remaining sub-items (stmts, e2e) keep Phase 2 open ⬜.
|
||||
141/141.** Remaining sub-items (control-flow 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-
|
||||
@@ -519,6 +523,20 @@ 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.: statements. First slice covers
|
||||
`return [exprs]`, short-decl `lhs := exprs`, assignment `lhs = exprs`,
|
||||
compound assignment (`+= -= *= /= %= &= |= ^= <<= >>= &^=`), bare
|
||||
expression statements, and nested blocks `{ ... }`. New `gp-parse-stmt`
|
||||
dispatches on the leading token; `gp-parse-block-body` replaces the
|
||||
func-decl `:body` sentinel with real `(:block STMTS)`. Existing
|
||||
func/method tests updated to the new body shape. **Progress guards**
|
||||
added to `gp-block-body-loop` and `gp-parse-composite-elems` —
|
||||
unsupported syntax (`if`, `for`, etc.) now advances one token instead
|
||||
of spinning. `gp-skip-block!` left as dead code; will be deleted once
|
||||
control-flow stmts land. +9 tests, parse 141/141, total 270/270.
|
||||
`[nothing]` — pure Go parser work; the cross-language statement
|
||||
shapes will become a chiselling target once a second statically-typed
|
||||
guest hits them.
|
||||
- 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,
|
||||
|
||||
Reference in New Issue
Block a user