go: parse.sx — unary prefix operators + 11 tests [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 34s

Adds Go unary prefix operators per Go spec § Operators:
  +x  -x  !x  ^x  *p  &v  <-ch

gp-parse-unary is recursive (so !!x and -^x chain correctly) and
sits between gp-parse-expr and gp-parse-primary — unary therefore
always binds tighter than any binary op without needing a unary
entry in the precedence table.

Symbols +, -, *, &, ^ are shared between unary and binary forms;
the positional split (expression-start sees unary, mid-expression
sees binary) disambiguates them cleanly with no lookback.

Unary nodes are single-arg ast-app:
  (ast-app (ast-var OP) (list OPERAND))

parse 37/37, total 166/166.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 07:43:34 +00:00
parent 750035d543
commit 728a91e49f
5 changed files with 99 additions and 8 deletions

View File

@@ -64,11 +64,32 @@
(= ty "ident")
(do (gp-advance!) (ast-var v))
:else nil))))
(define
gp-unary-ops
;; Go spec § Operators: prefix unary, all higher precedence than
;; any binary operator. <- is the channel receive form (send is a
;; statement, not an expression, so never appears here as binary).
(list "+" "-" "!" "^" "*" "&" "<-"))
(define
gp-parse-unary
(fn
()
(let ((tok (gp-cur)))
(cond
(and (= (get tok :type) "op")
(some (fn (u) (= u (get tok :value))) gp-unary-ops))
(do
(gp-advance!)
(let ((operand (gp-parse-unary)))
(cond
(= operand nil) nil
:else (ast-app (ast-var (get tok :value)) (list operand)))))
:else (gp-parse-primary)))))
(define
gp-parse-expr
(fn
(min-prec)
(let ((left (gp-parse-primary))) (gp-pratt-loop left min-prec))))
(let ((left (gp-parse-unary))) (gp-pratt-loop left min-prec))))
(define
gp-pratt-loop
(fn