Skip to content

Commit a46c66a

Browse files
committed
added phase-0 syntax define-typed-variable-syntax
1 parent cb42c24 commit a46c66a

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

turnstile/turnstile.rkt

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#lang racket/base
22

3-
(provide (except-out (all-from-out macrotypes/typecheck)
3+
(provide (except-out (all-from-out macrotypes/typecheck)
44
-define-typed-syntax -define-syntax-category)
55
define-typed-syntax define-syntax-category
6+
define-typed-variable-syntax
67
(rename-out [define-typed-syntax define-typerule]
78
[define-typed-syntax define-syntax/typecheck])
89
(for-syntax syntax-parse/typecheck
@@ -527,3 +528,33 @@
527528
[current-tag 'key1])
528529
(syntax-parse/typecheck stx kw-stuff (... ...)
529530
rule (... ...))))])))]))
531+
532+
(define-syntax define-typed-variable-syntax
533+
(syntax-parser
534+
[(_ (NAME:id orig-var-pat . props-pat)
535+
(~and (~seq kw-stuff ...) :stxparse-kws)
536+
rule ...+)
537+
#:with ((~seq tag:id _) ...) #'props-pat
538+
#:with make-transformer (generate-temporary #'name)
539+
#:with invalid-invok-str (format "invalid invocation of var, expected tags: ~a"
540+
(syntax->datum #'(tag ...)))
541+
#'(begin-for-syntax
542+
(define (make-transformer stx)
543+
(syntax-parse stx
544+
#:datum-literals (tag ...)
545+
[(orig-var-pat . props-pat)
546+
(make-set!-transformer
547+
(syntax-parser
548+
[(~var _ identifier)
549+
(syntax-parse/typecheck this-syntax
550+
kw-stuff ...
551+
rule ...)]
552+
[(id . args)
553+
#:with ap (datum->syntax this-syntax '#%app)
554+
(syntax/loc this-syntax (ap id . args))]))]
555+
[_
556+
(raise-syntax-error #f 'invalid-invok-str this-syntax)]))
557+
(define-syntax (NAME stx)
558+
(syntax-case stx ()
559+
[(_ . args)
560+
#'(make-transformer #'args)])))]))

0 commit comments

Comments
 (0)