From 9019652c6f6ae9d5fa3807e694bdbdaa5e4ab129 Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Mon, 30 Nov 2015 09:39:47 -0500 Subject: [PATCH] Support static-interface as def transformer --- remix/data0.rkt | 26 ++++++++++++++++++++++---- remix/tests/simple.rkt | 12 +++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/remix/data0.rkt b/remix/data0.rkt index f266962..4413019 100644 --- a/remix/data0.rkt +++ b/remix/data0.rkt @@ -25,8 +25,8 @@ (require (submod "." interface-member) (for-syntax (submod "." interface-member))) - - (define-syntax (:static-interface stx) + + (define-syntax (phase1:static-interface stx) (syntax-parse stx #:literals (remix:#%brackets) [(_si (remix:#%brackets @@ -75,6 +75,8 @@ (if xd #'xb #'(make-rename-transformer #'xb))]) (quasisyntax/loc stx (remix:def (remix:#%brackets x-def #,x-stx) x-def-v)))) + ;; XXX add the ability to add other properties, + ;; interfaces, etc. (singleton-struct #:property prop:procedure (λ (_ stx) @@ -116,10 +118,26 @@ (remix:#%app rhs real-i . blah)) ... (remix:def (remix:#%brackets remix:stx i) - (:static-interface + (phase1:static-interface (remix:#%brackets lhs def-rhs) ...)))))]))]))))]))) -(provide (for-syntax (rename-out [:static-interface static-interface]) +(define-syntax phase0:static-interface + (singleton-struct + #:property prop:procedure + (λ (_ stx) + (raise-syntax-error 'static-interface "Illegal outside def" stx)) + #:methods remix:gen:def-transformer + [(define (def-transform _ stx) + (syntax-parse stx + #:literals (remix:#%brackets) + [(def (remix:#%brackets me:id i:id) . body:expr) + (syntax/loc stx + (remix:def (remix:#%brackets remix:stx i) + (phase1:static-interface . body)))]))])) + + +(provide (rename-out [phase0:static-interface static-interface]) + (for-syntax (rename-out [phase1:static-interface static-interface]) gen:static-interface static-interface?)) diff --git a/remix/tests/simple.rkt b/remix/tests/simple.rkt index 431d976..fe0a1c4 100644 --- a/remix/tests/simple.rkt +++ b/remix/tests/simple.rkt @@ -299,13 +299,15 @@ {example3^.h ≡ 19}) ;; The syntax of interface members is not limited to identifiers. In -;; particular, #:keywords are useful. +;; particular, #:keywords are useful. Furthermore, static-interface is +;; a def transformer itself, to clean up the syntax a little bit. I +;; expect that most people will use it this way. (def example4-kw-key '#:key) (def example4-key 'key) -(def [stx example4^] - (static-interface - [#:key example4-kw-key] - [key example4-key])) +(def [static-interface example4^] + [#:key example4-kw-key] + [key example4-key]) (module+ test {example4^.#:key ≡ '#:key} {example4^.key ≡ 'key}) +