go: parse.sx — switch + select + 8 tests; stmts done [shapes-scheduler]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 32s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 32s
Adds Go's switch and select statements:
switch TAG { case V1, V2: a; case V3: b; default: c }
switch { case cond: ... } — tagless
select { case x := <-ch: a; case ch <- v: b; default: c }
AST shapes:
(list :switch TAG CASES) — TAG nil for tagless
(list :case VALUES BODY) — VALUES is expr-list
(list :select CASES)
(list :select-case COMM-STMT BODY) — COMM-STMT is send/recv-assign/bare-recv
(list :default BODY)
gp-parse-case-body reads stmts until the next case/default/}/eof
without consuming the terminator — used by both switch and select.
select-case parsing reuses gp-parse-stmt for the comm-stmt, so all
four shapes (send, x := <-ch, x = <-ch, bare <-ch) fall out from the
existing stmt parser. Composite-lit suppression is engaged for the
switch tag expression.
Type-switch (`switch v := x.(type) { case int: ... }`) is the one
deferred shape; needs the `.(type)` pseudo-syntax recognised in the
expression layer. Phase 2 statement coverage is otherwise complete.
This is also a chiselling iteration for scheduler sister kit. Diary
updated with select-case design insights:
* All four select-case shapes share (list :select-case STMT BODY)
— kit primitive sched-select accepts a uniform list of cases.
* Default vs no-default determines blocking semantics. Erlang's
`receive ... after Timeout -> ...` is the analogue — both fit
"non-blocking fallback case" in the kit API.
parse 169/169, total 298/298.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -196,17 +196,18 @@ 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: return, short-decl, assign, compound assign, expr stmt,
|
||||
- [x] Statements: return, short-decl, assign, compound assign, expr stmt,
|
||||
block, if/else (chained), for (4 shapes incl. range), break,
|
||||
continue, inc-dec, **`go EXPR`, `defer EXPR`, send `ch <- v`,
|
||||
`for k, v := range coll`** all done. Composite-literal `{`
|
||||
suppression active in control-flow conditions. `switch` and
|
||||
`select` deferred.
|
||||
continue, inc-dec, go, defer, send, **switch (tagged / tagless,
|
||||
multi-value cases, default), select (recv-into-var / send /
|
||||
bare-recv / default)** all done. Composite-literal `{` suppression
|
||||
active in control-flow conditions. Type-switch (`switch v :=
|
||||
x.(type)`) deferred to a follow-up.
|
||||
- [ ] End-to-end: hello-world, fibonacci, FizzBuzz, goroutine ping-pong,
|
||||
struct + method.
|
||||
- **Acceptance:** parse/ suite at 80+ tests. **Acceptance bar crossed:
|
||||
161/161.** Remaining sub-items (switch/select, end-to-end programs)
|
||||
keep Phase 2 open ⬜.
|
||||
169/169.** Remaining sub-item (end-to-end programs) keeps Phase 2
|
||||
open ⬜.
|
||||
|
||||
### Phase 3 — Bidirectional type checker, MVP (`lib/go/types.sx`) ⬜
|
||||
- **Independent implementation.** Do NOT use lib/guest/static-types-
|
||||
@@ -523,6 +524,24 @@ 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.: `switch` and `select` statements.
|
||||
Tagged + tagless switch, multi-value cases, `default`, and select
|
||||
with recv-into-var / send / bare-recv / default cases. New
|
||||
`gp-parse-case-body` reads stmts until the next `case`/`default`/`}`
|
||||
without consuming the terminator. AST shapes:
|
||||
`(list :switch TAG CASES)`,
|
||||
`(list :case VALUES BODY)`,
|
||||
`(list :select CASES)`,
|
||||
`(list :select-case COMM-STMT BODY)`,
|
||||
`(list :default BODY)`. With this, **Phase 2 statement coverage
|
||||
is complete** — type-switch is the one remaining shape (deferred).
|
||||
+8 tests, parse 169/169, total 298/298. `[shapes-scheduler]` —
|
||||
sister-plan diary updated with the `:select-case` uniform shape
|
||||
insight (single kit primitive covers all four Go case kinds; default
|
||||
vs no-default determines blocking semantics; cross-references to
|
||||
Erlang's `receive ... after`).
|
||||
|
||||
Sister-plan diary update follows.
|
||||
- 2026-05-27 — Phase 2 cont.: concurrency + iteration statements.
|
||||
`go EXPR`, `defer EXPR`, channel send `ch <- v`, and the four
|
||||
`for ... range` shapes (no-kv / k-only / k,v / assign-form). New
|
||||
|
||||
Reference in New Issue
Block a user