From 4fbf087e171f23c24ebbe2f30ba78fa0973675d0 Mon Sep 17 00:00:00 2001 From: Ryan Culpepper Date: Fri, 8 Jul 2011 03:38:33 -0600 Subject: [PATCH] syntax/parse: add expr/c to main module Merge to release branch (cherry picked from commit 0aecbf97ffc50f4879f5d75d5acc6e2aa15b6aa7) --- collects/syntax/parse.rkt | 6 +- .../syntax/parse/experimental/contract.rkt | 2 +- .../syntax/scribblings/parse/ex-exprc.scrbl | 5 +- .../scribblings/parse/experimental.scrbl | 19 +---- collects/syntax/scribblings/parse/lib.scrbl | 71 +++++++++++++++++++ collects/unstable/scribblings/wrapc.scrbl | 49 +------------ 6 files changed, 81 insertions(+), 71 deletions(-) diff --git a/collects/syntax/parse.rkt b/collects/syntax/parse.rkt index cd71a6b25b..337481d76f 100644 --- a/collects/syntax/parse.rkt +++ b/collects/syntax/parse.rkt @@ -3,11 +3,13 @@ "parse/private/sc.rkt" "parse/private/litconv.rkt" "parse/private/lib.rkt" - "parse/experimental/provide.rkt") + "parse/experimental/provide.rkt" + "parse/experimental/contract.rkt") (provide (except-out (all-from-out "parse/private/sc.rkt") syntax-parser/template parser/rhs) (all-from-out "parse/private/litconv.rkt") (except-out (all-from-out "parse/private/lib.rkt") - static)) + static) + expr/c) (provide-syntax-class/contract [static (syntax-class/c [(-> any/c any/c) (or/c string? symbol? #f)])]) diff --git a/collects/syntax/parse/experimental/contract.rkt b/collects/syntax/parse/experimental/contract.rkt index 4e8e847718..d0d7064e34 100644 --- a/collects/syntax/parse/experimental/contract.rkt +++ b/collects/syntax/parse/experimental/contract.rkt @@ -29,7 +29,7 @@ (#:positive (or/c syntax? string? module-path-index? 'from-macro 'use-site 'unknown) #:negative (or/c syntax? string? module-path-index? - 'from-macro 'same-as-use-site 'unknown) + 'from-macro 'use-site 'unknown) #:name (or/c identifier? string? symbol? #f) #:macro (or/c identifier? string? symbol? #f) #:context (or/c syntax? #f)))]) diff --git a/collects/syntax/scribblings/parse/ex-exprc.scrbl b/collects/syntax/scribblings/parse/ex-exprc.scrbl index d7b7d50dbf..3db0d746ad 100644 --- a/collects/syntax/scribblings/parse/ex-exprc.scrbl +++ b/collects/syntax/scribblings/parse/ex-exprc.scrbl @@ -6,10 +6,7 @@ "parse-common.rkt" (for-label racket/class)) -@title[#:tag "exprc"]{Experimental: Contracts on macro sub-expressions} - -@emph{This section involves facilities that are experimental and -subject to change.} +@title[#:tag "exprc"]{Contracts on macro sub-expressions} Just as procedures often expect certain kinds of values as arguments, macros often have expectations about the expressions they are diff --git a/collects/syntax/scribblings/parse/experimental.scrbl b/collects/syntax/scribblings/parse/experimental.scrbl index e545185f6d..20f079436e 100644 --- a/collects/syntax/scribblings/parse/experimental.scrbl +++ b/collects/syntax/scribblings/parse/experimental.scrbl @@ -13,23 +13,8 @@ The following facilities are experimental. @defmodule[syntax/parse/experimental/contract] -Macros can apply contracts to their sub-expressions using the -@racket[expr/c] syntax class. - -@defproc[(expr/c [contract-expr syntax?] - [#:positive pos-blame 'use-site] - [#:negative neg-blame 'from-macro] - [#:name expr-name #f] - [#:macro macro-name #f] - [#:context ctx #f]) - (attributes c)]{ - -Accepts an expression (@racket[expr]) and computes an attribute -@racket[c] that represents the expression wrapped with the contract -represented by @racket[contract-expr]. - -See @secref{exprc} for an example. -} +This module is deprecated; it reprovides @racket[expr/c] for backward +compatibility. @section{Contracts for syntax classes} diff --git a/collects/syntax/scribblings/parse/lib.scrbl b/collects/syntax/scribblings/parse/lib.scrbl index e9f20d530a..1114c1b930 100644 --- a/collects/syntax/scribblings/parse/lib.scrbl +++ b/collects/syntax/scribblings/parse/lib.scrbl @@ -58,6 +58,77 @@ When used outside of the dynamic extent of a macro transformer (see The attribute @var[value] contains the value the name is bound to. } +@defproc[(expr/c [contract-expr syntax?] + [#:positive pos-blame + (or/c syntax? string? module-path-index? 'from-macro 'use-site 'unknown) + 'use-site] + [#:negative neg-blame + (or/c syntax? string? module-path-index? 'from-macro 'use-site 'unknown) + 'from-macro] + [#:name expr-name (or/c identifier? string? symbol?) #f] + [#:macro macro-name (or/c identifier? string? symbol?) #f] + [#:context ctx (or/c syntax? #f) #, @elem{determined automatically}]) + (attributes c)]{ + +Accepts an expression (@racket[expr]) and computes an attribute +@racket[c] that represents the expression wrapped with the contract +represented by @racket[contract-expr]. + +The contract's positive blame represents the obligations of the +expression being wrapped. The negative blame represents the +obligations of the macro imposing the contract---the ultimate user +of @racket[expr/c]. By default, the positive blame is taken as +the module currently being expanded, and the negative blame is +inferred from the definition site of the macro (itself inferred from +the @racket[context] argument), but both blame locations can be +overridden. + +The @racket[pos-blame] and @racket[neg-blame] arguments are turned +into blame locations as follows: +@itemize[ +@item{If the argument is a string, it is used directly as the blame + label.} +@item{If the argument is syntax, its source location is used + to produce the blame label.} +@item{If the argument is a module path index, its resolved module path + is used.} +@item{If the argument is @racket['from-macro], the macro is inferred + from either the @racket[macro-name] argument (if @racket[macro-name] + is an identifier) or the @racket[context] argument, and the module + where it is @emph{defined} is used as the blame location. If + neither an identifier @racket[macro-name] nor a @racket[context] + argument is given, the location is @racket["unknown"].} +@item{If the argument is @racket['use-site], the module being + expanded is used.} +@item{If the argument is @racket['unknown], the blame label is + @racket["unknown"].} +] + +The @racket[macro-name] argument is used to determine the macro's +binding, if it is an identifier. If @racket[expr-name] is given, +@racket[macro-name] is also included in the contract error message. If +@racket[macro-name] is omitted or @racket[#f], but @racket[context] is +a syntax object, then @racket[macro-name] is determined from +@racket[context]. + +If @racket[expr-name] is not @racket[#f], it is used in the contract's +error message to describe the expression the contract is applied to. + +The @racket[context] argument is used, when necessary, to infer the +macro name for the negative blame party and the contract error +message. The @racket[context] should be either an identifier or a +syntax pair with an identifer in operator position; in either case, +that identifier is taken as the macro ultimately requesting the +contract wrapping. + +See @secref{exprc} for an example. + +@bold{Important:} Make sure when using @racket[expr/c] to use the +@racket[c] attribute. The @racket[expr/c] syntax class does not change how +pattern variables are bound; it only computes an attribute that +represents the checked expression. +} + @section{Literal sets} diff --git a/collects/unstable/scribblings/wrapc.scrbl b/collects/unstable/scribblings/wrapc.scrbl index 9c05bb10de..99cdcd7200 100644 --- a/collects/unstable/scribblings/wrapc.scrbl +++ b/collects/unstable/scribblings/wrapc.scrbl @@ -1,6 +1,6 @@ #lang scribble/manual @(require scribble/struct scribble/decode scribble/eval "utils.rkt" - (for-label racket/base racket/contract unstable/wrapc racket/syntax)) + (for-label racket/base racket/contract unstable/wrapc racket/syntax syntax/parse)) @(define the-eval (make-base-eval)) @(the-eval '(require racket/contract (for-syntax racket/base unstable/wrapc))) @@ -35,52 +35,7 @@ Returns a syntax object representing an expression that applies the contract represented by @racket[contract-expr] to the value produced by @racket[expr]. -The contract's positive blame represents the obligations of the -expression being wrapped. The negative blame represents the -obligations of the macro imposing the contract---the ultimate caller -of @racket[wrap-expr/c]. By default, the positive blame is taken as -the module currently being expanded, and the negative blame is -inferred from the definition site of the macro (itself inferred from -the @racket[context] argument). But both blame locations can be -overridden. - -Positive and negative blame locations are determined from -@racket[pos-blame] and @racket[neg-blame], respectively, as follows: -@itemize[ -@item{If the argument is a string, it is used directly as the blame -label.} -@item{If the argument is syntax, its source location is used -to produce the blame label.} -@item{If the argument is a module path index, its resolved module path -is used.} -@item{If the argument is @racket['from-macro], the macro is inferred -from either the @racket[macro-name] argument (if @racket[macro-name] -is an identifier) or the @racket[context] argument, and the module -where it is @emph{defined} is used as the negative blame location. If -neither an identifier @racket[macro-name] nor a @racket[context] -argument is given, the location is @racket["unknown"].} -@item{If the argument is @racket['use-site], the module being -expanded is used.} -@item{If the argument is @racket['unknown], the blame label is -@racket["unknown"].} -] - -The @racket[macro-name] argument is used to determine the macro's -binding, if it is an identifier. If @racket[expr-name] is given, -@racket[macro-name] is also included in the contract error message. If -@racket[macro-name] is omitted or @racket[#f], but @racket[context] is -a syntax object, then @racket[macro-name] is determined from -@racket[context]. - -If @racket[expr-name] is not @racket[#f], it is used in the contract's -error message to describe the expression the contract is applied to. - -The @racket[context] argument is used, when necessary, to infer the -macro name for the negative blame party and the contract error -message. The @racket[context] should be either an identifier or a -syntax pair with an identifer in operator position; in either case, -that identifier is taken as the macro ultimately requesting the -contract wrapping. +The other arguments have the same meaning as for @racket[expr/c]. @examples[#:eval the-eval (define-syntax (myparameterize1 stx)