Make syntax-local-introduce work in require/provide syntax

This commit is contained in:
Alexis King 2018-05-17 12:25:16 -05:00
parent 2bccbf76ad
commit 33546008b3
3 changed files with 18 additions and 41 deletions

View File

@ -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]}

View File

@ -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 ()

View File

@ -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 ()