Throw an error message that is more helpful when type is wrong

This commit is contained in:
Vivianne 2024-03-01 17:04:46 -05:00
parent fdb3e4f3a2
commit c700b7d91d
1 changed files with 15 additions and 14 deletions

View File

@ -70,28 +70,29 @@
(set-record-type-printer! <style> style->sequence)
(define (cons-seq stylish sequence)
(define (cons-sequence stylish sequence)
(match stylish
((? string? str)
(make-style str (list sequence)))
((style)
(cons-seq style sequence))
(cons-sequence style sequence))
((? list? l)
(make-style-node (map (cut cons-seq <> sequence) l)))
(make-style-node (map (cut cons-sequence <> sequence) l)))
((? style? style)
(set-style-sequences style
(cons* sequence (style-sequences style))))
((? style-node? node)
(set-style-node-children node
(map (cut cons-seq <> sequence) (style-node-children node))))))
(map (cut cons-sequence <> sequence) (style-node-children node))))
(anything-else (scm-error 'wrong-type-arg "cons-sequence" "Expected either a string or a style node (created by functions `bold', `italic', etc), got ~S" (list anything-else) (list anything-else)))))
(define (bold . s) (cons-seq s %BOLD))
(define (faint . s) (cons-seq s %FAINT))
(define (italic . s) (cons-seq s %ITALIC))
(define (underline . s) (cons-seq s %UNDERLINE))
(define (overline . s) (cons-seq s %OVERLINE))
(define (blink . s) (cons-seq s %BLINK))
(define (invert . s) (cons-seq s %REVERSE))
(define (cross-out . s) (cons-seq s %CROSS-OUT))
(define (foreground c . s) (cons-seq s (make-foreground c)))
(define (background c . s) (cons-seq s (make-background c)))
(define (bold . s) (cons-sequence s %BOLD))
(define (faint . s) (cons-sequence s %FAINT))
(define (italic . s) (cons-sequence s %ITALIC))
(define (underline . s) (cons-sequence s %UNDERLINE))
(define (overline . s) (cons-sequence s %OVERLINE))
(define (blink . s) (cons-sequence s %BLINK))
(define (invert . s) (cons-sequence s %REVERSE))
(define (cross-out . s) (cons-sequence s %CROSS-OUT))
(define (foreground c . s) (cons-sequence s (make-foreground c)))
(define (background c . s) (cons-sequence s (make-background c)))