go: parse.sx — multi-form file parsing + 7 e2e tests; PHASE 2 COMPLETE [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s
Final Phase 2 sub-deliverable. go-parse now handles whole Go files:
- Empty source → nil
- Single top-level form → that form (backward-compatible with ~169
existing single-stmt / single-decl tests)
- Multiple forms → (list :file FORMS), the canonical Go file shape
Implementation: gp-parse-all loops gp-parse-top until eof, tolerating
ASI semis between forms, then returns based on form count.
End-to-end test set (asserts the top-level decl-tag sequence via a
new decl-tags helper, not the full AST tree — that'd be unwieldy):
- hello-world :package :import :func-decl
- recursive fibonacci :package :func-decl
- FizzBuzz :package :import :func-decl
- goroutine ping-pong :package :func-decl :func-decl
- struct + method :package :type-decl :method-decl :func-decl
- interface + method :package :type-decl :type-decl :method-decl
- defer + select + range :package :func-decl
Type-switch (`switch v := x.(type) { ... }`) is the one syntactic
shape still deferred from Phase 2; doesn't gate Phase 3.
**Phase 2 (parser) is complete.** parse 176/176, total 305/305. Next:
Phase 3 — bidirectional type checker. The sister-plan diary for
static-types-bidirectional already has the :field binding-group
insight; Phase 3 will add the synth/check shape that emerges.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1127,6 +1127,66 @@
|
||||
(list (ast-var "a")))
|
||||
(list :default (list (ast-var "b"))))))
|
||||
|
||||
(define
|
||||
decl-tags
|
||||
(fn
|
||||
(parsed)
|
||||
(cond
|
||||
(and (list? parsed) (= (first parsed) :file))
|
||||
(map (fn (d) (first d)) (nth parsed 1))
|
||||
(list? parsed)
|
||||
(list (first parsed))
|
||||
:else (list))))
|
||||
|
||||
(go-parse-test
|
||||
"e2e: hello-world top-level tags"
|
||||
(decl-tags
|
||||
(go-parse
|
||||
"package main\nimport \"fmt\"\nfunc main() { fmt.Println(\"hello, world\") }"))
|
||||
(list :package :import :func-decl))
|
||||
|
||||
(go-parse-test
|
||||
"e2e: recursive fibonacci"
|
||||
(decl-tags
|
||||
(go-parse
|
||||
"package main\nfunc fib(n int) int {\n if n < 2 { return n }\n return fib(n-1) + fib(n-2)\n}"))
|
||||
(list :package :func-decl))
|
||||
|
||||
(go-parse-test
|
||||
"e2e: FizzBuzz with for + if-else chain"
|
||||
(decl-tags
|
||||
(go-parse
|
||||
"package main\nimport \"fmt\"\nfunc fizzbuzz(n int) {\n for i := 1; i <= n; i++ {\n if i % 15 == 0 { fmt.Println(\"FizzBuzz\") } else if i % 3 == 0 { fmt.Println(\"Fizz\") } else if i % 5 == 0 { fmt.Println(\"Buzz\") } else { fmt.Println(i) }\n }\n}"))
|
||||
(list :package :import :func-decl))
|
||||
|
||||
(go-parse-test
|
||||
"e2e: goroutine ping-pong (channels)"
|
||||
(decl-tags
|
||||
(go-parse
|
||||
"package main\nfunc sender(ch chan int) { ch <- 1 }\nfunc main() {\n ch := make(chan int)\n go sender(ch)\n x := <-ch\n print(x)\n}"))
|
||||
(list :package :func-decl :func-decl))
|
||||
|
||||
(go-parse-test
|
||||
"e2e: struct + method"
|
||||
(decl-tags
|
||||
(go-parse
|
||||
"package main\ntype Point struct { x, y int }\nfunc (p Point) Sum() int { return p.x + p.y }\nfunc main() {\n p := Point{1, 2}\n print(p.Sum())\n}"))
|
||||
(list :package :type-decl :method-decl :func-decl))
|
||||
|
||||
(go-parse-test
|
||||
"e2e: interface + structural satisfaction setup"
|
||||
(decl-tags
|
||||
(go-parse
|
||||
"package main\ntype Stringer interface { String() string }\ntype T struct { v int }\nfunc (t T) String() string { return \"t\" }"))
|
||||
(list :package :type-decl :type-decl :method-decl))
|
||||
|
||||
(go-parse-test
|
||||
"e2e: defer + select + range"
|
||||
(decl-tags
|
||||
(go-parse
|
||||
"package main\nfunc worker(jobs chan int, results chan int) {\n defer close(results)\n for j := range jobs {\n select {\n case results <- j * 2:\n default:\n return\n }\n }\n}"))
|
||||
(list :package :func-decl))
|
||||
|
||||
(go-parse-test "non-primary: '+'" (go-parse "+") nil)
|
||||
|
||||
(go-parse-test "non-primary: empty" (go-parse "") nil)
|
||||
|
||||
Reference in New Issue
Block a user