Make syntax-local-introduce work in match expanders
This commit is contained in:
parent
d944b8589e
commit
2bccbf76ad
|
@ -695,8 +695,9 @@ properties.
|
||||||
}
|
}
|
||||||
|
|
||||||
@defproc[(syntax-local-match-introduce [stx syntax?]) syntax?]{
|
@defproc[(syntax-local-match-introduce [stx syntax?]) syntax?]{
|
||||||
Like @racket[syntax-local-introduce], but for match expanders.
|
For backward compatibility only; equivalent to @racket[syntax-local-introduce].
|
||||||
}
|
|
||||||
|
@history[#:changed "6.90.0.29" @elem{Made equivalent to @racket[syntax-local-introduce].}]}
|
||||||
|
|
||||||
|
|
||||||
@defparam[match-equality-test comp-proc (any/c any/c . -> . any)]{
|
@defparam[match-equality-test comp-proc (any/c any/c . -> . any)]{
|
||||||
|
|
|
@ -841,5 +841,18 @@
|
||||||
(set! foo 2)
|
(set! foo 2)
|
||||||
(check-equal? x 2))
|
(check-equal? x 2))
|
||||||
|
|
||||||
|
(test-case
|
||||||
|
"match-expander with arity 2"
|
||||||
|
(define-syntax forty-two-pat
|
||||||
|
(let ()
|
||||||
|
(define-struct datum-pat (datum)
|
||||||
|
#:property prop:match-expander
|
||||||
|
(lambda (pat stx)
|
||||||
|
(datum->syntax #'here (datum-pat-datum pat) stx)))
|
||||||
|
(make-datum-pat 42)))
|
||||||
|
(check-equal? (match 42
|
||||||
|
[(forty-two-pat) #t])
|
||||||
|
#t))
|
||||||
|
|
||||||
|
|
||||||
))
|
))
|
||||||
|
|
|
@ -2,10 +2,9 @@
|
||||||
|
|
||||||
(require (for-template racket/base)
|
(require (for-template racket/base)
|
||||||
syntax/boundmap
|
syntax/boundmap
|
||||||
|
syntax/apply-transformer
|
||||||
racket/struct-info
|
racket/struct-info
|
||||||
;macro-debugger/emit
|
"patterns.rkt")
|
||||||
"patterns.rkt"
|
|
||||||
"syntax-local-match-introduce.rkt")
|
|
||||||
|
|
||||||
(provide ddk? parse-literal all-vars pattern-var? match:syntax-err
|
(provide ddk? parse-literal all-vars pattern-var? match:syntax-err
|
||||||
match-expander-transform trans-match trans-match* parse-struct
|
match-expander-transform trans-match trans-match* parse-struct
|
||||||
|
@ -170,20 +169,16 @@
|
||||||
error-msg)
|
error-msg)
|
||||||
(let* ([expander* (syntax-local-value expander)]
|
(let* ([expander* (syntax-local-value expander)]
|
||||||
[transformer (accessor expander*)]
|
[transformer (accessor expander*)]
|
||||||
;; this transformer might have been defined w/ `syntax-id-rules'
|
[transformer-proc (if (set!-transformer? transformer)
|
||||||
[transformer (if (set!-transformer? transformer)
|
|
||||||
(set!-transformer-procedure transformer)
|
(set!-transformer-procedure transformer)
|
||||||
transformer)])
|
transformer)])
|
||||||
(unless transformer (raise-syntax-error #f error-msg expander*))
|
(unless transformer (raise-syntax-error #f error-msg expander*))
|
||||||
(define introducer (make-syntax-introducer))
|
(parse (local-apply-transformer
|
||||||
(parameterize ([current-match-introducer introducer])
|
(λ (stx) (if (procedure-arity-includes? transformer-proc 2)
|
||||||
(let* ([mstx (introducer (syntax-local-introduce stx))]
|
(transformer-proc expander* stx)
|
||||||
[mresult (if (procedure-arity-includes? transformer 2)
|
(transformer-proc stx)))
|
||||||
(transformer expander* mstx)
|
stx
|
||||||
(transformer mstx))]
|
'expression))))
|
||||||
[result (syntax-local-introduce (introducer mresult))])
|
|
||||||
;(emit-local-step stx result #:id expander)
|
|
||||||
(parse result)))))
|
|
||||||
|
|
||||||
;; raise an error, blaming stx
|
;; raise an error, blaming stx
|
||||||
(define (match:syntax-err stx msg)
|
(define (match:syntax-err stx msg)
|
||||||
|
|
|
@ -1,15 +1,8 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(provide syntax-local-match-introduce
|
(provide syntax-local-match-introduce)
|
||||||
current-match-introducer)
|
|
||||||
|
|
||||||
(define current-match-introducer
|
|
||||||
(make-parameter
|
|
||||||
(lambda (x)
|
|
||||||
(error 'syntax-local-match-introduce "not expanding match expander form"))))
|
|
||||||
|
|
||||||
(define (syntax-local-match-introduce x)
|
(define (syntax-local-match-introduce x)
|
||||||
(unless (syntax? x)
|
(unless (syntax? x)
|
||||||
(raise-argument-error 'syntax-local-match-introduce "syntax?" x))
|
(raise-argument-error 'syntax-local-match-introduce "syntax?" x))
|
||||||
((current-match-introducer) x))
|
(syntax-local-introduce x))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user