8.10 Experimental
The following facilities are experimental.
8.10.1 Contracts for Macro Sub-expressions
This module is deprecated; it reprovides expr/c for backward
compatibility.
8.10.2 Contracts for Syntax Classes
|
|
syntax-class-contract | | = | | (syntax-class/c (mandatory-arg ...)) | | | | | | | | | | | | arg | | = | | contract-expr | | | | | | keyword contract-expr |
|
|
|
Provides the syntax class (or splicing syntax class)
syntax-class-id with the given contracts imposed on its
formal parameters.
8.10.3 Reflection
A syntax class can be reified into a run-time value, and a reified
syntax class can be used in a pattern via the ~reflect and
~splicing-reflect pattern forms.
Reifies the syntax class named syntax-class-id as a run-time
value. The same form also handles splicing syntax classes. Syntax
classes with the #:no-delimit-cut option cannot be reified.
Returns #t if x is a reified (normal) syntax class
or a reified splicing syntax class, respectively.
Returns the reified syntax class’s attributes.
Partially applies the reified syntax class to the given arguments. If
more arguments are given than the reified syntax class accepts, an
error is raised.
S-pattern | | = | | .... |
| | | | | (~reflect var-id (reified-expr arg-expr ...) maybe-attrs) |
| | | | |
H-pattern | | = | | .... |
| | | | | |
(~reflect var-id (reified-expr arg-expr ...) maybe-attrs) |
|
maybe-attrs | | = | | | | | | | | #:attributes (attr-arity-decl ...) |
|
Like ~var, except that the syntax class position is an
expression evaluating to a reified syntax object, not a syntax class
name, and the attributes bound by the reified syntax class (if any)
must be specified explicitly.
Like ~reflect but for reified splicing syntax classes.
Examples: |
| | > (define r-nat> (reify-syntax-class nat>)) | current-directory: `exists' access denied for | /var/tmp/racket/src/build/ | > (define r-nat/mult (reify-syntax-class nat/mult)) | current-directory: `exists' access denied for | /var/tmp/racket/src/build/ | | > (partition/r #'(1 2 3 4 5) r-nat> 3) | reference to an identifier before its definition: r-nat> | > (partition/r #'(1 2 3 4 5) r-nat/mult 2) | reference to an identifier before its definition: r-nat/mult | | > (bad-attrs r-nat>) | reference to an identifier before its definition: r-nat> | > (bad-attrs r-nat/mult) | reference to an identifier before its definition: r-nat/mult |
|
8.10.4 Procedural Splicing Syntax Classes
Defines a splicing syntax via a procedural parser.
The parser procedure is given two arguments, the syntax to parse and a
failure procedure. To signal a successful parse, the parser procedure
returns a list of N+1 elements, where N is the
number of attributes declared by the splicing syntax class. The first
element is the size of the prefix consumed. The rest of the list
contains the values of the attributes.
To indicate failure, the parser calls the failure procedure with an
optional message argument.
8.10.5 Ellipsis-head Alternative Sets
Unlike single-term patterns and head patterns, ellipsis-head patterns
cannot be encapsulated by syntax classes, since they describe not only
sets of terms but also repetition constraints.
This module provides ellipsis-head alternative sets,
reusable encapsulations of ellipsis-head patterns.
Defines
name as an ellipsis-head alternative set. Using
name (via
~eh-var) in an ellipsis-head pattern is
equivalent to including each of the alternatives in the pattern via
~oreh, except that the attributes bound by the alternatives are
prefixed with the name given to
~eh-var.
Unlike syntax classes, ellipsis-head alternative sets must be defined
before they are referenced.
EH-pattern | | = | | .... |
| | | | | (~eh-var name eh-alternative-set-id) |
(~eh-var name eh-alternative-set-id) |
Includes the alternatives of eh-alternative-set-id, prefixing
their attributes with name.
Examples: |
| | > (parse/options #'(m #:a 1 #:b 2 #:b 3)) | #<syntax:13:0 (1 (2 3))> | > (parse/options #'(m #:a 1 #:a 2)) | m: too many occurrences of #:a option at: () | | > (parse/more-options #'(m #:a 1 #:b 2 #:c 3 4 #:c 5 6)) | #<syntax:16:0 (1 (2) ((3 4) (5 6)))> | | | #<syntax:19:0 (1 (2) ((3 4) (5 6)))> |
|
8.10.6 Syntax Class Specialization
(define-syntax-class/specialize header syntax-class-use) |
|
header | | = | | id | | | | | | (id . kw-formals) | | | | | | syntax-class-use | | = | | target-stxclass-id | | | | | | (target-stxclass-id arg ...) |
|
Defines id as a syntax class with the same attributes,
options (eg, #:commit, #:no-delimit-cut), and
patterns as target-stxclass-id but with the given
args supplied.