go: parse.sx — composite literals + 8 tests [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
Adds Go composite literals:
T{} empty
T{1, 2} positional
T{X: 1, Y: 2} keyed
[]int{1, 2, 3} slice
[3]int{1, 2, 3} array
map[string]int{"a": 1} map
pkg.Point{1, 2} qualified
[]Point{Point{1,2}, Point{3,4}} nested
AST: (list :composite TYPE-OR-EXPR ELEMS). Each element is an
expression or (list :kv KEY VALUE).
Two parser entry points feed the same AST:
* gp-parse-primary picks up type-prefixed composites by seeing
a literal-type starter ([, map, struct) and parsing a type
first, then optionally a '{' body.
* The postfix loop picks up ident-prefixed composites — after
any base expression, '{' wraps it as a composite literal.
Known limitation flagged in plan: when statement parsing arrives,
the postfix '{' branch will misread `if cond { ... }` as a composite
literal. Standard fix: parser-mode flag suppressing composite-lit
disambiguation in control-flow expression positions. Added to plan.
Elided types in nested composites (`[][]int{{1,2},{3,4}}` with the
inner `{1,2}` typed implicitly) deferred.
parse 114/114, total 243/243.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -181,8 +181,13 @@ Progress-log line → push `origin/loops/go`.
|
||||
with methods + embedded interfaces (named and qualified)** all
|
||||
done — kit has no type primitives. Field tags, struct embeds,
|
||||
variadic, named func-params, Go 1.18 type sets, generics deferred.
|
||||
- [ ] Composite literals: `T{...}`, `[]T{...}`, `map[K]V{...}`,
|
||||
`struct{...}{...}`.
|
||||
- [x] Composite literals: `T{...}`, `[]T{...}`, `[N]T{...}`,
|
||||
`map[K]V{...}`, `pkg.T{...}`, nested. Positional and keyed
|
||||
(`X: 1, Y: 2`) elements. AST `(list :composite TYPE-OR-EXPR ELEMS)`;
|
||||
elements are exprs or `(list :kv KEY VALUE)`. Note: in statement
|
||||
context (e.g. `if cond { ... }`) my parser would WRONGLY treat
|
||||
the body as a composite; statement parsing will need a "no-
|
||||
composite-here" mode flag — to be added when statements arrive.
|
||||
- [ ] Declarations: `package`, `import`, `var`, `const`, `type`, `func`
|
||||
(including methods, parameter lists, return types).
|
||||
- [ ] Statements: `if`/`else`, `for` (C-style + range), `switch` (expr +
|
||||
@@ -191,8 +196,7 @@ Progress-log line → push `origin/loops/go`.
|
||||
- [ ] End-to-end: hello-world, fibonacci, FizzBuzz, goroutine ping-pong,
|
||||
struct + method.
|
||||
- **Acceptance:** parse/ suite at 80+ tests. **Acceptance bar crossed:
|
||||
106/106.** Remaining sub-items (composite literals, decls, stmts,
|
||||
e2e) still keep Phase 2 open ⬜.
|
||||
114/114.** Remaining sub-items (decls, 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-
|
||||
@@ -509,6 +513,17 @@ 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.: composite literals. `T{}`, `T{1, 2}`,
|
||||
`T{X: 1, Y: 2}`, `[]T{...}`, `[N]T{...}`, `map[K]V{...}`,
|
||||
`pkg.T{...}`, nested composites. AST shape
|
||||
`(list :composite TYPE-OR-EXPR ELEMS)`; each element is an expression
|
||||
or `(list :kv KEY VALUE)`. Two parser entry points: type-prefixed
|
||||
(`gp-parse-primary` adds `[`/`map`/`struct` branches) and
|
||||
ident-prefixed (postfix loop adds `{` branch). **Known limitation
|
||||
flagged in plan:** when statement parsing arrives, the postfix `{`
|
||||
branch will misread `if cond { ... }` as composite literal — needs a
|
||||
"no-composite-here" parser-mode flag. +8 tests, parse 114/114, total
|
||||
243/243. `[nothing]` — pure Go parser shape work.
|
||||
- 2026-05-27 — Phase 2 cont.: interface-type expressions. `interface {}`,
|
||||
`interface { Close() }`, `interface { String() string }`,
|
||||
`interface { Read([]byte) (int, error) }`, plus embedded interfaces
|
||||
|
||||
Reference in New Issue
Block a user