go: parse.sx scaffold — primary expressions + Go precedence table + 17 tests [consumes-pratt consumes-ast]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Starts Phase 2. lib/go/parse.sx defines:
* go-precedence-table — Go's five operator-precedence levels in the
(NAME PREC ASSOC) entry shape from lib/guest/pratt.sx, ready for the
binary-operator iteration to consume via pratt-op-lookup.
* go-parse(src) — tokenises and parses ONE primary expression: int,
float, imag, string, rune literals become (ast-literal VALUE);
identifiers become (ast-var NAME). Built directly on lib/guest/ast.sx
constructors — no intermediate AST shape.
Conformance.sh extended to load lib/guest/{ast,pratt}.sx and run the
new parse suite. Scoreboard cleanup: drop the "pending" parse row since
the suite is now real.
parse 17/17 (lex still 129/129). Total 146/146.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
43
lib/go/tests/parse.sx
Normal file
43
lib/go/tests/parse.sx
Normal file
@@ -0,0 +1,43 @@
|
||||
;; Go parser tests.
|
||||
|
||||
(define go-parse-test-count 0)
|
||||
(define go-parse-test-pass 0)
|
||||
(define go-parse-test-fails (list))
|
||||
|
||||
(define
|
||||
go-parse-test
|
||||
(fn
|
||||
(name actual expected)
|
||||
(set! go-parse-test-count (+ go-parse-test-count 1))
|
||||
(if
|
||||
(= actual expected)
|
||||
(set! go-parse-test-pass (+ go-parse-test-pass 1))
|
||||
(append! go-parse-test-fails {:name name :expected expected :actual actual}))))
|
||||
|
||||
;; ── primary: literals ─────────────────────────────────────────────
|
||||
(go-parse-test "int literal" (go-parse "42") (ast-literal "42"))
|
||||
(go-parse-test "zero literal" (go-parse "0") (ast-literal "0"))
|
||||
(go-parse-test "hex literal" (go-parse "0xFF") (ast-literal "0xFF"))
|
||||
(go-parse-test "float literal" (go-parse "3.14") (ast-literal "3.14"))
|
||||
(go-parse-test "leading-dot float" (go-parse ".5") (ast-literal ".5"))
|
||||
(go-parse-test "exponent float" (go-parse "1e10") (ast-literal "1e10"))
|
||||
(go-parse-test "imag literal" (go-parse "2i") (ast-literal "2i"))
|
||||
(go-parse-test "string literal" (go-parse "\"hi\"") (ast-literal "hi"))
|
||||
(go-parse-test "empty string" (go-parse "\"\"") (ast-literal ""))
|
||||
(go-parse-test "raw string" (go-parse "`a\nb`") (ast-literal "a\nb"))
|
||||
(go-parse-test "rune literal" (go-parse "'a'") (ast-literal "a"))
|
||||
|
||||
;; ── primary: identifiers ──────────────────────────────────────────
|
||||
(go-parse-test "ident: simple" (go-parse "x") (ast-var "x"))
|
||||
(go-parse-test "ident: underscore" (go-parse "_foo") (ast-var "_foo"))
|
||||
(go-parse-test "ident: mixed case" (go-parse "fooBar") (ast-var "fooBar"))
|
||||
(go-parse-test "ident: with digit" (go-parse "x123") (ast-var "x123"))
|
||||
|
||||
;; ── primary: non-primary returns nil ──────────────────────────────
|
||||
(go-parse-test "non-primary: '+'" (go-parse "+") nil)
|
||||
(go-parse-test "non-primary: empty" (go-parse "") nil)
|
||||
|
||||
;; ── report ────────────────────────────────────────────────────────
|
||||
(define
|
||||
go-parse-test-summary
|
||||
(str "parse " go-parse-test-pass "/" go-parse-test-count))
|
||||
Reference in New Issue
Block a user