@ -1,4 +1,4 @@
#lang pollen/mode racket/base
#lang pollen/mode debug racket/base
( require ( for-syntax
racket/base
syntax/parse )
@ -78,19 +78,22 @@
( define-syntax ( define-tag-function stx )
( syntax-parse stx
#:literals ( λ )
[ ( _ ( ID:id ARG:id ... ) EXPR:expr ... )
#' ( define-tag-function ID ( λ ( ARG ... ) EXPR ... ) ) ]
[ ( THIS ( ID:id ARG:id ... ) EXPR:expr ... )
#' ( THIS ID ( λ ( ARG ... ) EXPR ... ) ) ]
[ ( _ ID:id ( λ ( ATTRS:id ELEMS:id ARG:id ... ) EXPR:expr ... ) )
#:fail-when ( > ( length ( syntax->list #' ( ARG ... ) ) ) 0 ) " tag function must have exactly 2 positional arguments "
#:fail-when ( check-duplicate-identifier ( list #' ATTRS #' ELEMS ) ) " duplicate variable name "
#:fail-when ( null? ( syntax->list #' ( EXPR ... ) ) ) " body of definition cannot be empty "
#' ( define ID
;; the srcloc of the `lambda` expression determines the srcloc of errors raised within its body
#` ( define ID
( make-keyword-procedure
( λ ( kws kwargs . arg s)
#, ( syntax/loc #' ID ( lambda ( kws kwargs attrs . elem s)
( define tx-proc ( keyword-apply default-tag-function kws kwargs ( list ' ID ) ) )
( define tx ( apply tx-proc args ) )
( 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 ) )
( define-values ( _ ATTRS ELEMS ) ( txexpr->values tx ) )
EXPR ... ) ) ) ] ) )
EXPR ... ) ) ) ) ] ) )
( module+ test