handle zero-arg case

pull/218/head
Matthew Butterick 4 years ago
parent 00255a1889
commit 0e2ff2c79a

@ -1 +1 @@
1578422046
1578527156

@ -87,21 +87,24 @@
;; the srcloc of the `lambda` expression determines the srcloc of errors raised within its body
#`(define ID
(make-keyword-procedure
#,(syntax/loc #'ID (lambda (kws kwargs attrs . elems)
(define tx-proc (keyword-apply default-tag-function kws kwargs (list 'ID)))
#,(syntax/loc #'ID (lambda (kws kwargs . args)
(let ([elems (match args
[(list* _ elems) elems]
[_ #false])])
(when elems
(unless (and (list? elems) (andmap txexpr-element? elems))
(raise-argument-error 'ID (format "elements need to be passed to tag function as individual trailing arguments (or, if you want to pass them as a single list, use `(apply ~a ···)` here instead of `(~a ···)`)" 'ID 'ID) (car elems)))
(define tx (apply tx-proc attrs elems))
(raise-argument-error 'ID (format "elements need to be passed to tag function as individual trailing arguments (or, if you want to pass them as a single list, use `(apply ~a ···)` here instead of `(~a ···)`)" 'ID 'ID) (car elems)))))
(define tx-proc (keyword-apply default-tag-function kws kwargs (list 'ID)))
(define tx (apply tx-proc args))
(define-values (_ ATTRS ELEMS) (txexpr->values tx))
EXPR ...))))]))
(module+ test
(require)
(define foo2 (default-tag-function 'foo))
(define-tag-function (foo attrs elems)
`(foo ,(reverse attrs) ,@elems))
(check-txexprs-equal? (foo) (foo2))
(check-txexprs-equal? ◊foo[#:zim "zam"]{hello} ◊foo2[#:zim "zam"]{hello})
(check-txexprs-equal? ◊foo[#:ding "dong" '((zim "zam"))]{hello} ◊foo2[#:ding "dong" '((zim "zam"))]{hello})
(check-txexprs-equal? ◊foo['zim: "zam" #:ding "dong" ]{hello} ◊foo2['zim: "zam" #:ding "dong" ]{hello})

Loading…
Cancel
Save