commit 1d45a9ea6247b21c5b64bfa22445c18dcb2dee4f
parent a7dd0c07593eade7676dce7775b078c442fd02b0
Author: Georges Dupéron <georges.duperon@gmail.com>
Date: Tue, 30 Aug 2016 13:13:32 +0200
Added ~mixin, which checs that its argument is indeed a mixin. Mixins can still be used by themeselves, but there's always the risk that they'll be seen as a pattern variable, if for some reason their identifier is not bound to a mixin (forgot to export, wrong scopes…)
Diffstat:
4 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/main.rkt b/main.rkt
@@ -6,6 +6,7 @@
"private/post.rkt"
"private/global.rkt"
"private/optional.rkt"
+ "private/mixin.rkt"
(for-template "private/define-syntax+simple-api.rkt"))
(provide #;define-splicing-syntax-class-with-eh-mixins
@@ -14,6 +15,7 @@
(expander-out eh-mixin)
~seq-no-order
~no-order
+ ~mixin
~post-check
~post-fail
~nop
diff --git a/private/define-syntax+simple-api.rkt b/private/define-syntax+simple-api.rkt
@@ -63,7 +63,7 @@
(define (name stx2)
(syntax-parameterize ([stx (make-rename-transformer #'stx2)])
(syntax-parse stx2
- [(name . colon-stxclass) . body])))
+ [(_ . colon-stxclass) . body])))
(define (private-simple-api stx/arg attr-name/arg …)
(syntax-parameterize ([stx (make-rename-transformer #'stx/arg)])
(syntax-parse #'nothing
diff --git a/private/mixin.rkt b/private/mixin.rkt
@@ -0,0 +1,11 @@
+#lang racket
+
+(require "no-order.rkt"
+ (for-syntax syntax/parse))
+
+(provide ~mixin)
+
+(define-eh-mixin-expander ~mixin
+ (syntax-parser
+ [(_ (~var mixin (static eh-mixin-expander? "an eh-mixin expander")))
+ #'(mixin)]))
+\ No newline at end of file
diff --git a/test/test-structure-options.rkt b/test/test-structure-options.rkt
@@ -73,11 +73,11 @@
{structure-kw-predicate-mixin}
{structure-kw-fields-mixin}}))
-;; ---------
-
(define-splicing-syntax-class structure-kws
(pattern {~seq-no-order {structure-kw-all-mixin}}))
+;; ---------
+
(check-equal? (syntax-parse #'(#:instance #:? p)
[(:structure-kws)
(list* (attribute instance)
@@ -163,4 +163,4 @@ builder-style field declarations"
;; body]))
;;
;; For speed, we could just copy the whole implementation in real-macro-name's
-;; definition, instead of calling simplified-macro-implementation.
-\ No newline at end of file
+;; definition, instead of calling simplified-macro-implementation.