go: parse.sx — if/else, for, break/continue, inc-dec + 11 tests [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s

Adds the most-used control-flow forms:
  if COND { ... } [else { ... } | else if ...]
  for { ... }                          — infinite
  for COND { ... }                     — while-like
  for INIT; COND; POST { ... }         — C-style
  break / continue                     — keyword stmts (no labels yet)
  x++ / x--                            — Go statement inc-dec

AST shapes:
  (list :if COND THEN ELSE)              — ELSE nil / :if / :block
  (list :for INIT COND POST BODY)        — any of INIT/COND/POST may be nil
  (list :break LABEL)  (list :continue LABEL)
  (list :inc-dec OP EXPR)                — OP is "++" / "--"

**Closes the parser-mode caveat** logged when composite literals
landed. `gp-no-comp-lit` is a re-entrant counter on the parser state;
control-flow constructs increment it before parsing their condition
and decrement after, suppressing the postfix `{` → composite-lit
interpretation so that `if Foo { ... }` correctly reads `{ ... }` as
the body, not as `Foo{}` composite literal. Verified by the test:

  (go-parse "if Foo {}")  →  (:if (:var "Foo") (:block ()) nil)

gp-parse-control-cond is the single helper that bracket-wraps the
flag bump so future control-flow forms (switch, select, range) can't
forget to engage suppression.

switch / select / defer / go / for-range / channel-send still deferred.

parse 152/152, total 281/281.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 20:17:40 +00:00
parent 5f6d62f45b
commit ba41f8a580
5 changed files with 186 additions and 14 deletions

View File

@@ -197,16 +197,18 @@ Progress-log line → push `origin/loops/go`.
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
(`+=` 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.
(`+=` etc.), expression stmt, block `{...}`, **if/else (with chained
else-if), for (infinite / while-like / C-style), break, continue,
inc-dec (`x++` / `x--`)** all done. **Composite-literal `{`
suppression** active in control-flow conditions via
`gp-no-comp-lit` counter — closes the parser-mode caveat flagged
when composite literals landed. `switch`/`select`/`defer`/`go`/
`for...range`/send `ch<-v` deferred.
- [ ] End-to-end: hello-world, fibonacci, FizzBuzz, goroutine ping-pong,
struct + method.
- **Acceptance:** parse/ suite at 80+ tests. **Acceptance bar crossed:
141/141.** Remaining sub-items (control-flow stmts, e2e) keep Phase 2
open ⬜.
152/152.** Remaining sub-items (switch/select/defer/go/range,
end-to-end programs) keep Phase 2 open ⬜.
### Phase 3 — Bidirectional type checker, MVP (`lib/go/types.sx`) ⬜
- **Independent implementation.** Do NOT use lib/guest/static-types-
@@ -523,6 +525,18 @@ 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.: control-flow statements. `if cond { } [else
{ }]` with chained else-if, `for { }` (infinite), `for cond { }`
(while-like), `for init; cond; post { }` (C-style), `break`,
`continue`, plus `x++` / `x--` inc-dec statements. **Closed the
parser-mode caveat** flagged when composite literals landed:
`gp-no-comp-lit` is a re-entrant counter that suppresses the postfix
`{...}` → composite-lit interpretation inside control-flow condition
positions, matching Go spec § Composite literals. `gp-parse-control-
cond` wraps the increment/decrement so callers can't forget. +11
tests, parse 152/152, total 281/281. `[nothing]` — pure Go parser
shape work; the bidirectional-checker-relevant shapes (cond/body) are
already covered by the earlier `:field` insight.
- 2026-05-27 — Phase 2 cont.: statements. First slice covers
`return [exprs]`, short-decl `lhs := exprs`, assignment `lhs = exprs`,
compound assignment (`+= -= *= /= %= &= |= ^= <<= >>= &^=`), bare