commit 75fa5aea07b8f1b7fda217a60e118e20574bfdee
parent 01c9b553a5b35d5661548d59c928c727af7f966f
Author: Georges Dupéron <georges.duperon@gmail.com>
Date: Thu, 22 Sep 2016 22:52:54 +0200
Added #:define-syntax-class option, tweaked documentation
Diffstat:
4 files changed, 48 insertions(+), 10 deletions(-)
diff --git a/private/no-order.rkt b/private/no-order.rkt
@@ -51,7 +51,9 @@
(define-syntax define-eh-alternative-mixin
(syntax-parser
- [(_ name (~maybe #:define-splicing-syntax-class splicing-name)
+ [(_ name
+ (~maybe #:define-splicing-syntax-class splicing-name)
+ (~maybe #:define-syntax-class class-name)
((~literal pattern) pat) ...)
#`(begin
(define-eh-mixin-expander name
@@ -61,6 +63,10 @@
#,@(if (attribute splicing-name)
#'((define-splicing-syntax-class splicing-name
(pattern {~seq-no-order {name}})))
+ #'())
+ #,@(if (attribute class-name)
+ #'((define-syntax-class class-name
+ (pattern {~no-order {name}})))
#'()))]))
(define-for-syntax (inline-or stx)
diff --git a/scribblings/defining-reusable-mixins.scrbl b/scribblings/defining-reusable-mixins.scrbl
@@ -11,10 +11,16 @@
@title{Defining reusable parser mixins}
@defform[#:literals (pattern)
- (define-eh-alternative-mixin name maybe-define-class
+ (define-eh-alternative-mixin name
+ maybe-splicing-class
+ maybe-define-splicing-class
(pattern clause-or-mixin) ...)
#:grammar
[(maybe-define-class
+ (code:line)
+ (code:line #:define-syntax-class class-name))
+ (maybe-define-splicing-class
+ (code:line)
(code:line #:define-splicing-syntax-class splicing-name))
(clause-or-mixin #,ntax-pattern
(~mixin #,-alternative-mixin)
@@ -34,7 +40,14 @@
The @racket[derived-or] term covers any
@tech[#:doc '(lib "syntax/scribblings/syntax.scrbl")]{pattern expander} or
@tech{eh-mixin expander} application which expands to a
- @racket[clause-or-mixin].}
+ @racket[clause-or-mixin].
+
+ The @racket[#:define-syntax-class] option defines a syntax class with the given
+ @racket[class-name] which matches @racket[{~no-order {~mixin name}}].
+
+ The @racket[#:define-splicing-syntax-class] option defines a splicing syntax
+ class with the given @racket[class-name] which matches
+ @racket[{~seq-no-order {~mixin name}}].}
@deftogether[[@defthing[#:kind "for-syntax value"
eh-mixin-expander-type expander-type?]
diff --git a/scribblings/forward-attributes.scrbl b/scribblings/forward-attributes.scrbl
@@ -1,11 +1,12 @@
#lang scribble/manual
@require[scribble/example
"utils.rkt"
- @for-label[phc-toolkit/untyped
+ @for-label[(except-in phc-toolkit/untyped stx-cdr)
extensible-parser-specifications
generic-syntax-expanders
racket/base
syntax/parse
+ (only-in syntax/stx stx-cdr)
(only-in racket/base [... …])]]
@title{Chaining macro calls without re-parsing everything}
@@ -14,16 +15,30 @@
#:grammar
[(name-or-curry name
(name-or-curry arg ...))
- (maybe-define-class #:define-splicing-syntax-class class-id)
+ (maybe-define-class
+ (code:line)
+ (code:line #:define-syntax-class splicing-name))
+ (maybe-define-splicing-class
+ (code:line)
+ (code:line #:define-splicing-syntax-class splicing-name))
(name identifier?)
- (class-id identifier?)]]{
+ (class-name identifier?)
+ (splicing-name identifier?)]]{
This macro works like @racket[define/syntax-parse] from @racket[phc-toolkit],
except that it also defines the function @racket[_name-forward-attributes],
which can be used by other macros to forward already parsed attributes to the
@racket[body], without the need to parse everything a second time.
The syntax pattern for the @racket[name] macro's arguments can be saved in a
- syntax class by specifying the @racket[#:define-splicing-syntax-class] option.
+ splicing syntax class by specifying the @racket[#:define-splicing-syntax-class]
+ option. The pattern only includes the arguments after the name, i.e it matches
+ @racket[(stx-cdr stx)].
+
+ The syntax pattern for the @racket[name] macro's arguments can be saved in a
+ syntax class by specifying the @racket[#:define-syntax-class] option. The
+ pattern only includes the arguments after the name, i.e it matches
+ @racket[(stx-cdr stx)].
+
If the caller macro which uses @racket[(_name-forward-attributes)] parsed its
own @racket[stx] argument using @racket[class-id], then
diff --git a/scribblings/no-order.scrbl b/scribblings/no-order.scrbl
@@ -47,11 +47,15 @@
Like @racket[~seq-no-order], except that it matches a syntax list, instead of
being spliced into the surrounding sequence of patterns. In other words,
- @racketblock[(~seq-no-order clause-or-mixin ...)]
+ @racketblock[({~seq-no-order clause-or-mixin ...})]
- Equivalent to (notice the extra pair of braces):
+ is equivalent to (notice the extra pair of braces above):
- @racketblock[({~seq-no-order clause-or-mixin ...})]}
+ @racketblock[(~no-order clause-or-mixin ...)]
+
+ Additionally, @racket[~no-order] can include clauses which use
+ @racket[~lift-rest], which lifts a pattern which matches the tail of an
+ improper list.}
@section{Enforcing a partial order on the alternatives}