dev-elider-3
Matthew Butterick 9 years ago
parent d93cb2c4ca
commit f3b176025e

@ -2,22 +2,27 @@
(require (for-syntax racket/base syntax/parse racket/syntax syntax/datum syntax/strip-context)) (require (for-syntax racket/base syntax/parse racket/syntax syntax/datum syntax/strip-context))
(provide (all-defined-out)) (provide (all-defined-out))
;; a little tricky because we have to mix two levels of macrology.
;; does not work with ellipses in the input pattern
(define-syntax (br:debug-define stx) (define-syntax (br:debug-define stx)
(syntax-parse stx (syntax-parse stx
#:literals (syntax) #:literals (syntax)
[(_ (syntax (id pat-arg ... . rest-arg)) body-exp) ; (define #'(foo arg) #'(+ arg arg)) [(_ (syntax (id pat-arg ... . rest-arg)) body-exp) ; (define #'(foo arg) #'(+ arg arg))
#'(define-syntax id (λ (stx) #'(define-syntax id (λ (stx)
(define result (syntax-case stx () (define result (syntax-case stx ()
[(_ pat-arg ... . rest-arg) body-exp])) [(_ pat-arg ... . rest-arg)
(with-syntax ([syntaxed-result result] body-exp]))
[context stx]) (define arg-printing (syntax-case stx ()
#`(begin [(_ pat-arg ... . rest-arg)
(displayln (format "input pattern = #'~a" (quote (id pat-arg ... . rest-arg)))) #`(begin
(displayln (format "output pattern = #'~a" (syntax->datum body-exp))) (displayln (format "arg #'~a = ~a" #,''pat-arg pat-arg)) ...)]))
(displayln (format "arg ~a = ~a" (quote pat-arg) 'zz)) ... (with-syntax ([syntaxed-arg-printing arg-printing]
#;(displayln stx) [syntaxed-result result])
(displayln (format "expansion = ~a" 'syntaxed-result)) #'(begin
(displayln (format "result = ~a" syntaxed-result)) (displayln (format "input syntax = #'~a" (quote (id pat-arg ... . rest-arg))))
(displayln (format "output syntax = #'~a" (syntax->datum body-exp)))
syntaxed-arg-printing
(displayln (format "expanded syntax = #'~a" 'syntaxed-result))
syntaxed-result))))])) syntaxed-result))))]))
(define-syntax (br:define stx) (define-syntax (br:define stx)

Loading…
Cancel
Save