From 0b1c0ba13b69f89cb442f2e7d22907a6e22a2e48 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 7 May 2013 14:14:24 -0400 Subject: [PATCH] racket/{require,provide}-syntax: add `syntax-local-{require,provide}-introduce' --- collects/racket/provide-syntax.rkt | 14 +++++++++-- collects/racket/require-syntax.rkt | 14 +++++++++-- collects/scribblings/reference/syntax.scrbl | 28 +++++++++++++++++---- doc/release-notes/racket/HISTORY.txt | 2 ++ 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/collects/racket/provide-syntax.rkt b/collects/racket/provide-syntax.rkt index 4b818886b3..a53b3a07f4 100644 --- a/collects/racket/provide-syntax.rkt +++ b/collects/racket/provide-syntax.rkt @@ -1,6 +1,7 @@ #lang racket/base -(provide define-provide-syntax) +(provide define-provide-syntax + (for-syntax syntax-local-provide-introduce)) (require (for-syntax racket/base "provide-transform.rkt")) @@ -8,12 +9,21 @@ (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)) + (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 (i (proc (i d-stx)))]) + [new-stx (parameterize ([current-provide-introducer i]) + (i (proc (i d-stx))))]) (expand-export (syntax-rearm new-stx stx) modes))))) (define-syntax (define-provide-syntax stx) diff --git a/collects/racket/require-syntax.rkt b/collects/racket/require-syntax.rkt index 87f9759a7c..67c46588ea 100644 --- a/collects/racket/require-syntax.rkt +++ b/collects/racket/require-syntax.rkt @@ -1,18 +1,28 @@ #lang racket/base -(provide define-require-syntax) +(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")))) + +(define-for-syntax (syntax-local-require-introduce x) + (unless (syntax? x) + (raise-argument-error 'syntax-local-introduce-require "syntax?" x)) + ((current-require-introducer) 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 (i (proc (i d-stx)))]) + [new-stx (parameterize ([current-require-introducer i]) + (i (proc (i d-stx))))]) (expand-import (syntax-rearm new-stx stx)))))) (define-syntax (define-require-syntax stx) diff --git a/collects/scribblings/reference/syntax.scrbl b/collects/scribblings/reference/syntax.scrbl index ee3285502f..f65dd4f84c 100644 --- a/collects/scribblings/reference/syntax.scrbl +++ b/collects/scribblings/reference/syntax.scrbl @@ -2498,13 +2498,22 @@ procedure that accepts and returns a syntax object representing a @racket[require] sub-form. This form expands to @racket[define-syntax] with a use of -@racket[make-require-transformer]; see @secref["require-trans"] for -more information. +@racket[make-require-transformer] (see @secref["require-trans"] for +more information), and the @tech{syntax object} passed to and from the +macro transformer is marked via @racket[syntax-local-require-introduce]. 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 +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?]{ + +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.} + @; ---------------------------------------------------------------------- @subsection[#:tag "provide-syntax"]{@racket[provide] Macros} @@ -2520,13 +2529,22 @@ procedure that accepts and returns a syntax object representing a @racket[provide] sub-form. This form expands to @racket[define-syntax] with a use of -@racket[make-provide-transformer]; see @secref["provide-trans"] for -more information. +@racket[make-provide-transformer] (see @secref["provide-trans"] for +more information), and the @tech{syntax object} passed to and from the +macro transformer is marked via @racket[syntax-local-provide-introduce]. 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?]{ + +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.} + @;------------------------------------------------------------------------ @section[#:tag "begin"]{Sequencing: @racket[begin], @racket[begin0], and @racket[begin-for-syntax]} diff --git a/doc/release-notes/racket/HISTORY.txt b/doc/release-notes/racket/HISTORY.txt index 4c00342b7c..a7677d1ddf 100644 --- a/doc/release-notes/racket/HISTORY.txt +++ b/doc/release-notes/racket/HISTORY.txt @@ -1,6 +1,8 @@ Version 5.3.4.8 Add `configure-runtime' submodule support racket/rerequire: added +racket/require-syntax: added syntax-local-require-introduce +racket/provide-syntax: added syntax-local-provide-introduce Version 5.3.4.7 scribble: use `doc' submodule when available