1
0
forked from alex-eg/sex

parenthesise a conditional without a helper to do it for

This commit is contained in:
2026-10-14 20:09:17 +03:00
parent 8f152c2593
commit f87e9faa8f

View File

@@ -909,24 +909,23 @@
;; It groups to the right, so its else arm is written at ;; It groups to the right, so its else arm is written at
;; `conditional-else', just looser: a chain there stays bare, ;; `conditional-else', just looser: a chain there stays bare,
;; `a ? x : b ? y : z', and an assignment does not. ;; `a ? x : b ? y : z', and an assignment does not.
(define (c-if/expr . args) (define (c-if/expr c p . rest)
(c-maybe-paren '? (apply c-if/expr/aux args))) (c-maybe-paren
'?
(define (c-if/expr/aux c p . rest) (let lp ((c c) (p p) (ls rest))
(let lp ((c c) (p p) (ls rest)) (cond
(cond ((or (eq? c 'else) (eq? c #t))
((or (eq? c 'else) (eq? c #t)) (if (not (null? ls))
(if (not (null? ls)) (error "forms after else clause in IF" c p ls)
(error "forms after else clause in IF" c p ls) (c-expr p)))
(c-expr p))) ((pair? ls)
((pair? ls) (cat (c-in-test (c-expr c)) " ? " (c-expr p) " : "
(cat (c-in-test (c-expr c)) " ? " (c-expr p) " : " (c-with-op 'conditional-else
(c-with-op 'conditional-else (if (pair? (cdr ls))
(if (pair? (cdr ls)) (lp (car ls) (cadr ls) (cddr ls))
(lp (car ls) (cadr ls) (cddr ls)) (lp 'else (car ls) '())))))
(lp 'else (car ls) '()))))) (else
(else (c-or (c-in-test (c-expr c)) (c-expr p)))))))
(c-or (c-in-test (c-expr c)) (c-expr p))))))
(define (c-if . args) (define (c-if . args)
(fmt-if fmt-expression? (fmt-if fmt-expression?