From 33546008b3cbde646f4393e5868c326b8ff7aa1d Mon Sep 17 00:00:00 2001 From: Alexis King Date: Thu, 17 May 2018 12:25:16 -0500 Subject: [PATCH] Make syntax-local-introduce work in require/provide syntax --- .../scribblings/reference/syntax.scrbl | 26 +++++++------------ racket/collects/racket/provide-syntax.rkt | 15 +++-------- racket/collects/racket/require-syntax.rkt | 18 ++++--------- 3 files changed, 18 insertions(+), 41 deletions(-) diff --git a/pkgs/racket-doc/scribblings/reference/syntax.scrbl b/pkgs/racket-doc/scribblings/reference/syntax.scrbl index d88bdcf440..ceacc18434 100644 --- a/pkgs/racket-doc/scribblings/reference/syntax.scrbl +++ b/pkgs/racket-doc/scribblings/reference/syntax.scrbl @@ -2583,20 +2583,17 @@ procedure that accepts and returns a syntax object representing a This form expands to @racket[define-syntax] with a use of @racket[make-require-transformer] (see @secref["require-trans"] for -more information), and the @tech{syntax object} passed to and from the -macro transformer is adjusted via @racket[syntax-local-require-introduce]. +more information). The second form is a shorthand the same as for @racket[define-syntax]; it expands to a definition of the first form where the @racket[proc-expr] is a @racket[lambda] form.} -@defproc[(syntax-local-require-introduce [stx syntax?]) - syntax?]{ +@defproc[(syntax-local-require-introduce [stx syntax?]) syntax?]{ -Provided @racket[for-syntax] for use only during the application of a -@racket[require] sub-form macro transformer: like -@racket[syntax-local-introduce], but for @racket[require] sub-form -expansion.} +For backward compatibility only; equivalent to @racket[syntax-local-introduce]. + +@history[#:changed "6.90.0.29" @elem{Made equivalent to @racket[syntax-local-introduce].}]} @; ---------------------------------------------------------------------- @@ -2614,20 +2611,17 @@ procedure that accepts and returns a syntax object representing a This form expands to @racket[define-syntax] with a use of @racket[make-provide-transformer] (see @secref["provide-trans"] for -more information), and the @tech{syntax object} passed to and from the -macro transformer is adjusted via @racket[syntax-local-provide-introduce]. +more information). The second form is a shorthand the same as for @racket[define-syntax]; it expands to a definition of the first form where the @racket[expr] is a @racket[lambda] form.} -@defproc[(syntax-local-provide-introduce [stx syntax?]) - syntax?]{ +@defproc[(syntax-local-provide-introduce [stx syntax?]) syntax?]{ -Provided @racket[for-syntax] for use only during the application of a -@racket[provide] sub-form macro transformer: like -@racket[syntax-local-introduce], but for @racket[provide] sub-form -expansion.} +For backward compatibility only; equivalent to @racket[syntax-local-introduce]. + +@history[#:changed "6.90.0.29" @elem{Made equivalent to @racket[syntax-local-introduce].}]} @;------------------------------------------------------------------------ @section[#:tag "begin"]{Sequencing: @racket[begin], @racket[begin0], and @racket[begin-for-syntax]} diff --git a/racket/collects/racket/provide-syntax.rkt b/racket/collects/racket/provide-syntax.rkt index a53b3a07f4..f9c43cec4b 100644 --- a/racket/collects/racket/provide-syntax.rkt +++ b/racket/collects/racket/provide-syntax.rkt @@ -4,27 +4,18 @@ (for-syntax syntax-local-provide-introduce)) (require (for-syntax racket/base + syntax/apply-transformer "provide-transform.rkt")) -(define-for-syntax orig-insp (variable-reference->module-declaration-inspector - (#%variable-reference))) - -(define-for-syntax current-provide-introducer - (make-parameter (lambda (x) (error "not expanding provide form")))) - (define-for-syntax (syntax-local-provide-introduce x) (unless (syntax? x) (raise-argument-error 'syntax-local-introduce-provide "syntax?" x)) - ((current-provide-introducer) x)) + (syntax-local-introduce x)) (define-for-syntax (make-provide-macro proc) (make-provide-transformer (lambda (stx modes) - (let* ([i (make-syntax-introducer)] - [d-stx (syntax-disarm stx orig-insp)] - [new-stx (parameterize ([current-provide-introducer i]) - (i (proc (i d-stx))))]) - (expand-export (syntax-rearm new-stx stx) modes))))) + (expand-export (local-apply-transformer proc stx 'expression) modes)))) (define-syntax (define-provide-syntax stx) (syntax-case stx () diff --git a/racket/collects/racket/require-syntax.rkt b/racket/collects/racket/require-syntax.rkt index 67c46588ea..ce69f5dbd0 100644 --- a/racket/collects/racket/require-syntax.rkt +++ b/racket/collects/racket/require-syntax.rkt @@ -3,27 +3,19 @@ (provide define-require-syntax (for-syntax syntax-local-require-introduce)) -(require (for-syntax racket/base "require-transform.rkt")) - -(define-for-syntax orig-insp (variable-reference->module-declaration-inspector - (#%variable-reference))) - -(define-for-syntax current-require-introducer - (make-parameter (lambda (x) (error "not expanding require form")))) +(require (for-syntax racket/base + syntax/apply-transformer + "require-transform.rkt")) (define-for-syntax (syntax-local-require-introduce x) (unless (syntax? x) (raise-argument-error 'syntax-local-introduce-require "syntax?" x)) - ((current-require-introducer) x)) + (syntax-local-introduce x)) (define-for-syntax (make-require-macro proc) (make-require-transformer (lambda (stx) - (let* ([i (make-syntax-introducer)] - [d-stx (syntax-disarm stx orig-insp)] - [new-stx (parameterize ([current-require-introducer i]) - (i (proc (i d-stx))))]) - (expand-import (syntax-rearm new-stx stx)))))) + (expand-import (local-apply-transformer proc stx 'expression))))) (define-syntax (define-require-syntax stx) (syntax-case stx ()