This repository has been archived by the owner on Sep 13, 2019. It is now read-only.
/
test-template-save-props.rkt
65 lines (61 loc) · 2.65 KB
/
test-template-save-props.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#lang racket
(require syntax/parse
syntax/parse/experimental/template)
(begin-for-syntax
(struct prefab-st (a b c) #:prefab)
(struct st (a b c))
(define (syntax-properties s . p*)
(if (null? p*)
s
(apply syntax-properties
(syntax-property s (car p*) (cadr p*))
(cddr p*)))))
(define-syntax (define-with-prop stx)
(syntax-case stx ()
[(_ name)
#`(define (name)
(syntax-parse #'1
[v
(template #,(syntax-properties #'(v)
'null '()
'string "str"
'bytes #"by"
'number 123.4
'boolean #t
'char #\c
'keyword '#:kw
'regexp #rx".*"
'pregexp #px".*"
'byte-regexp #rx#".*"
'byte-pregexp #px#".*"
'box #&bx
'symbol 'sym
'pair '(a . b)
'vector #(1 2 3)
'hash #hash([a . 1] [b . 2])
'hasheq #hasheq([a . 1] [b . 2])
'hasheqv #hasheqv([a . 1] [b . 2])
'prefab-st (prefab-st 'x 'y 'z)
'st (st 'x 'y 'z))
#:properties (null
string
bytes
number
boolean
char
keyword
regexp
pregexp
byte-regexp
byte-pregexp
box
symbol
pair
vector
hash
hasheq
hasheqv
prefab-st
st))]))]))
(define-with-prop get-syntax-with-saved-props)
(provide get-syntax-with-saved-props)