Added quasitemplate/debug to the library.

This commit is contained in:
Georges Dupéron 2016-02-29 20:26:17 +01:00
parent 9457f05599
commit 0a532aa96e
2 changed files with 34 additions and 4 deletions

View File

@ -353,7 +353,7 @@ The first step macro is defined as follows:
@chunk[<first-step>
(define-syntax/parse <signature>
<define-ids/first-step>
(debug-template debug
(template/debug debug
;; Can't use (let () …) because of TR bug #262
;; https://github.com/racket/typed-racket/issues/262
(begin
@ -378,7 +378,7 @@ It will be called from the first step with the following syntax:
@chunk[<second-step>
(define-syntax/parse <signature-second-step>
<define-ids/second-step>
(debug-template debug
(template/debug debug
(begin
(begin <define-mapping-function>)

View File

@ -310,7 +310,8 @@
stx-list
stx-e
stx-pair
debug-template
template/debug
quasitemplate/debug
;string-set!
;string-copy!
;string-fill!
@ -463,7 +464,7 @@
'((y z) . x)))
(require syntax/parse/experimental/template)
(define-syntax (debug-template stx)
(define-syntax (template/debug stx)
(syntax-parse stx
[(_ debug-attribute:id . rest)
#'((λ (x)
@ -472,6 +473,35 @@
x)
(template . rest))]))
(define-syntax (quasitemplate/debug stx)
(syntax-parse stx
[(_ debug-attribute:id . rest)
#'((λ (x)
(when (attribute debug-attribute)
(pretty-write (syntax->datum x)))
x)
(quasitemplate . rest))]))
;; TODO: this is kind of a hack, as we have to write:
#;(with-syntax ([(x ) #'(a bb ccc)])
(let ([y 70])
(quasitemplate
([x (meta-eval (+ #,y (string-length
(symbol->string
(syntax-e #'x)))))]
))))
;; Where we need #,y instead of using:
;; (+ y (string-length etc.)).
(module m-meta-eval racket
(provide meta-eval)
(require syntax/parse/experimental/template)
(define-template-metafunction (meta-eval stx)
(syntax-case stx ()
[(_ . body)
#`#,(eval #'(begin . body))])))
(require/provide 'm-meta-eval)
(define-syntax (string-set! stx)
(raise-syntax-error 'string-set! "Do not mutate strings." stx))
(define-syntax (string-copy! stx)