go: parse.sx — function calls + member access + 12 tests [consumes-ast proposes-ast]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s
Adds postfix expression forms per Go spec: f() f(x) f(x, y, z) — function calls x.y x.y.z obj.method(x) — selector / member access gp-parse-postfix sits between gp-parse-unary and gp-parse-primary, so calls and selectors bind tighter than any unary prefix — `-f(x)` parses as `-(f(x))`, not `(-f)(x)`. Postfix is left-associative (`x.y.z` = `(x.y).z`), so the loop iterates rather than recurses on the LHS. AST shapes: Call: (ast-app FN ARGS) — canonical Selector: (list :select OBJ "field") — Go-specific tag The selector shape is a kit gap — lib/guest/ast.sx ships ast-app but no ast-select, despite `obj.field` being universal across Go, Rust, Swift, TS, JS, Python, Ruby, Java, C#. Logged in Blockers; tagging [proposes-ast]. Worth promoting on the next nominally-typed guest. parse 49/49, total 178/178. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -172,6 +172,76 @@
|
||||
(ast-var "+")
|
||||
(list (ast-var "a") (ast-app (ast-var "-") (list (ast-var "b"))))))
|
||||
|
||||
(go-parse-test
|
||||
"call: f() (no args)"
|
||||
(go-parse "f()")
|
||||
(ast-app (ast-var "f") (list)))
|
||||
|
||||
(go-parse-test
|
||||
"call: f(x)"
|
||||
(go-parse "f(x)")
|
||||
(ast-app (ast-var "f") (list (ast-var "x"))))
|
||||
|
||||
(go-parse-test
|
||||
"call: f(x, y, z)"
|
||||
(go-parse "f(x, y, z)")
|
||||
(ast-app (ast-var "f") (list (ast-var "x") (ast-var "y") (ast-var "z"))))
|
||||
|
||||
(go-parse-test
|
||||
"call: f(1, 2)"
|
||||
(go-parse "f(1, 2)")
|
||||
(ast-app (ast-var "f") (list (ast-literal "1") (ast-literal "2"))))
|
||||
|
||||
(go-parse-test
|
||||
"call: f(a + b) — arg can be a binary expr"
|
||||
(go-parse "f(a + b)")
|
||||
(ast-app
|
||||
(ast-var "f")
|
||||
(list (ast-app (ast-var "+") (list (ast-var "a") (ast-var "b"))))))
|
||||
|
||||
(go-parse-test
|
||||
"call: f(g(x)) — nested"
|
||||
(go-parse "f(g(x))")
|
||||
(ast-app
|
||||
(ast-var "f")
|
||||
(list (ast-app (ast-var "g") (list (ast-var "x"))))))
|
||||
|
||||
(go-parse-test
|
||||
"select: x.y"
|
||||
(go-parse "x.y")
|
||||
(list :select (ast-var "x") "y"))
|
||||
|
||||
(go-parse-test
|
||||
"select: x.y.z (chained left-assoc)"
|
||||
(go-parse "x.y.z")
|
||||
(list :select (list :select (ast-var "x") "y") "z"))
|
||||
|
||||
(go-parse-test
|
||||
"method: obj.method()"
|
||||
(go-parse "obj.method()")
|
||||
(ast-app (list :select (ast-var "obj") "method") (list)))
|
||||
|
||||
(go-parse-test
|
||||
"method: obj.method(x, y)"
|
||||
(go-parse "obj.method(x, y)")
|
||||
(ast-app
|
||||
(list :select (ast-var "obj") "method")
|
||||
(list (ast-var "x") (ast-var "y"))))
|
||||
|
||||
(go-parse-test
|
||||
"postfix: -f(x) → unary applies after call"
|
||||
(go-parse "-f(x)")
|
||||
(ast-app
|
||||
(ast-var "-")
|
||||
(list (ast-app (ast-var "f") (list (ast-var "x"))))))
|
||||
|
||||
(go-parse-test
|
||||
"postfix: f(x) + 1 → call binds tighter than binary +"
|
||||
(go-parse "f(x) + 1")
|
||||
(ast-app
|
||||
(ast-var "+")
|
||||
(list (ast-app (ast-var "f") (list (ast-var "x"))) (ast-literal "1"))))
|
||||
|
||||
(go-parse-test "non-primary: '+'" (go-parse "+") nil)
|
||||
|
||||
(go-parse-test "non-primary: empty" (go-parse "") nil)
|
||||
|
||||
Reference in New Issue
Block a user