go: parse.sx — func type expressions (anonymous params) + 9 tests [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 20s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 20s
Adds Go func-type parsing to gp-parse-type:
func() → (list :ty-func () ())
func() int → (list :ty-func () [int])
func(int, string) → (list :ty-func [int string] ())
func(int) string → (list :ty-func [int] [string])
func() (int, error) → (list :ty-func () [int error])
gp-parse-func-type-params handles the param list inside (...);
gp-parse-func-type-results dispatches between bare single-return,
multi-return parenthesised list, or no return.
Anonymous-only — named params (`func(a int, b string)`) require a
different shape and are mainly needed for func DECLARATIONS, not for
pure func-type expressions in type position. Variadic ('...T')
deferred.
Covers nested cases: func returning func, chan of func, func with
pointer/slice operands.
parse 90/90, total 219/219.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -436,6 +436,77 @@
|
||||
:assert (ast-var "v")
|
||||
(list :ty-ptr (list :ty-slice (list :ty-name "int")))))
|
||||
|
||||
(go-parse-test
|
||||
"ty: func() (no params, no return)"
|
||||
(go-parse "v.(func())")
|
||||
(list :assert (ast-var "v") (list :ty-func (list) (list))))
|
||||
|
||||
(go-parse-test
|
||||
"ty: func() int (no params, one return)"
|
||||
(go-parse "v.(func() int)")
|
||||
(list
|
||||
:assert (ast-var "v")
|
||||
(list :ty-func (list) (list (list :ty-name "int")))))
|
||||
|
||||
(go-parse-test
|
||||
"ty: func(int)"
|
||||
(go-parse "v.(func(int))")
|
||||
(list
|
||||
:assert (ast-var "v")
|
||||
(list :ty-func (list (list :ty-name "int")) (list))))
|
||||
|
||||
(go-parse-test
|
||||
"ty: func(int, string)"
|
||||
(go-parse "v.(func(int, string))")
|
||||
(list
|
||||
:assert (ast-var "v")
|
||||
(list
|
||||
:ty-func (list (list :ty-name "int") (list :ty-name "string"))
|
||||
(list))))
|
||||
|
||||
(go-parse-test
|
||||
"ty: func(int) string"
|
||||
(go-parse "v.(func(int) string)")
|
||||
(list
|
||||
:assert (ast-var "v")
|
||||
(list
|
||||
:ty-func (list (list :ty-name "int"))
|
||||
(list (list :ty-name "string")))))
|
||||
|
||||
(go-parse-test
|
||||
"ty: func() (int, error) (multi return)"
|
||||
(go-parse "v.(func() (int, error))")
|
||||
(list
|
||||
:assert (ast-var "v")
|
||||
(list
|
||||
:ty-func (list)
|
||||
(list (list :ty-name "int") (list :ty-name "error")))))
|
||||
|
||||
(go-parse-test
|
||||
"ty: func(*T) []int (pointer param, slice return)"
|
||||
(go-parse "v.(func(*T) []int)")
|
||||
(list
|
||||
:assert (ast-var "v")
|
||||
(list
|
||||
:ty-func (list (list :ty-ptr (list :ty-name "T")))
|
||||
(list (list :ty-slice (list :ty-name "int"))))))
|
||||
|
||||
(go-parse-test
|
||||
"ty: func() func() (nested func type as return)"
|
||||
(go-parse "v.(func() func())")
|
||||
(list
|
||||
:assert (ast-var "v")
|
||||
(list :ty-func (list) (list (list :ty-func (list) (list))))))
|
||||
|
||||
(go-parse-test
|
||||
"ty: chan func() int (chan of func type)"
|
||||
(go-parse "v.(chan func() int)")
|
||||
(list
|
||||
:assert (ast-var "v")
|
||||
(list
|
||||
:ty-chan :both
|
||||
(list :ty-func (list) (list (list :ty-name "int"))))))
|
||||
|
||||
(go-parse-test "non-primary: '+'" (go-parse "+") nil)
|
||||
|
||||
(go-parse-test "non-primary: empty" (go-parse "") nil)
|
||||
|
||||
Reference in New Issue
Block a user