go: parse.sx — func + method declarations + 8 tests [shapes-static-types-bidirectional]
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
Adds Go func and method declarations:
func main() {}
func add(x, y int) int { return x + y }
func mix(x int, y string) {}
func divmod(a, b int) (int, int) {}
func sig(x int) int (no body)
func (p *Point) String() string { ... } (method, pointer recv)
func (s Stack) Len() int { ... } (method, value recv)
func nested() { if true { x := 1; { y := 2 } } } (nested braces)
New gp-parse-decl-param-group implements named-greedy disambiguation:
collects consecutive 'ident [, ident]*' then parses a type. Anonymous
mixed lists like 'func(int, string)' are a known limitation (parser
treats first ident as a name); flagged in plan.
gp-skip-block! brace-balances over the body; the AST stores ':body'
as a sentinel until statement parsing lands. Methods use the receiver
parameter shape directly.
AST:
(list :func-decl NAME PARAMS RESULTS BODY)
(list :method-decl RECV NAME PARAMS RESULTS BODY)
**All five `:field` binding-group consumers now exist** across the
parser: struct fields, var, const, func params, method receivers.
That's strong cross-deliverable validation of the ast-binding-group
proposal from Blockers — five different declaration contexts, one
shared shape.
This is the chisel-relevant insight for sister plan static-types-
bidirectional: an entry has been appended to its design diary
describing how `:field` will be the load-bearing input shape for
the bidirectional checker's `check Γ e T` judgment across these
contexts.
parse 132/132, total 261/261.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -775,6 +775,74 @@
|
||||
(list
|
||||
:ty-struct (list (list :field (list "x" "y") (list :ty-name "int"))))))
|
||||
|
||||
(go-parse-test
|
||||
"fdecl: func main() {}"
|
||||
(go-parse "func main() {}")
|
||||
(list :func-decl "main" (list) (list) :body))
|
||||
|
||||
(go-parse-test
|
||||
"fdecl: func add(x, y int) int { return x + y }"
|
||||
(go-parse "func add(x, y int) int { return x + y }")
|
||||
(list
|
||||
:func-decl "add"
|
||||
(list (list :field (list "x" "y") (list :ty-name "int")))
|
||||
(list (list :ty-name "int"))
|
||||
:body))
|
||||
|
||||
(go-parse-test
|
||||
"fdecl: func with multi-group params"
|
||||
(go-parse "func mix(x int, y string) {}")
|
||||
(list
|
||||
:func-decl "mix"
|
||||
(list
|
||||
(list :field (list "x") (list :ty-name "int"))
|
||||
(list :field (list "y") (list :ty-name "string")))
|
||||
(list)
|
||||
:body))
|
||||
|
||||
(go-parse-test
|
||||
"fdecl: func with multi-return"
|
||||
(go-parse "func divmod(a, b int) (int, int) {}")
|
||||
(list
|
||||
:func-decl "divmod"
|
||||
(list (list :field (list "a" "b") (list :ty-name "int")))
|
||||
(list (list :ty-name "int") (list :ty-name "int"))
|
||||
:body))
|
||||
|
||||
(go-parse-test
|
||||
"fdecl: func with no body (signature only)"
|
||||
(go-parse "func sig(x int) int")
|
||||
(list
|
||||
:func-decl "sig"
|
||||
(list (list :field (list "x") (list :ty-name "int")))
|
||||
(list (list :ty-name "int"))
|
||||
nil))
|
||||
|
||||
(go-parse-test
|
||||
"mdecl: method on pointer receiver"
|
||||
(go-parse "func (p *Point) String() string { return p.x }")
|
||||
(list
|
||||
:method-decl (list :field (list "p") (list :ty-ptr (list :ty-name "Point")))
|
||||
"String"
|
||||
(list)
|
||||
(list (list :ty-name "string"))
|
||||
:body))
|
||||
|
||||
(go-parse-test
|
||||
"mdecl: method on value receiver"
|
||||
(go-parse "func (s Stack) Len() int { return 0 }")
|
||||
(list
|
||||
:method-decl (list :field (list "s") (list :ty-name "Stack"))
|
||||
"Len"
|
||||
(list)
|
||||
(list (list :ty-name "int"))
|
||||
:body))
|
||||
|
||||
(go-parse-test
|
||||
"fdecl: nested braces in body (skipped opaquely)"
|
||||
(go-parse "func nested() { if true { x := 1; { y := 2 } } }")
|
||||
(list :func-decl "nested" (list) (list) :body))
|
||||
|
||||
(go-parse-test "non-primary: '+'" (go-parse "+") nil)
|
||||
|
||||
(go-parse-test "non-primary: empty" (go-parse "") nil)
|
||||
|
||||
Reference in New Issue
Block a user