-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsyntax-parse-shortcuts-test.rkt
More file actions
112 lines (90 loc) · 2.87 KB
/
syntax-parse-shortcuts-test.rkt
File metadata and controls
112 lines (90 loc) · 2.87 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#lang resyntax/test
require: resyntax/default-recommendations syntax-parse-shortcuts
header:
------------------------------
#lang racket/base
(require (for-syntax racket/base syntax/parse)
syntax/parse/define)
------------------------------
test: "define-syntax with syntax-parse and one clause refactorable to define-syntax-parse-rule"
------------------------------
(define-syntax my-or
(lambda (stx)
(syntax-parse stx
[(_ a b)
#'(let ([tmp a]) (if tmp tmp b))])))
==============================
(define-syntax-parse-rule (my-or a b)
(let ([tmp a]) (if tmp tmp b)))
------------------------------
test: "define-syntax-parser with one clause refactorable to define-syntax-parse-rule"
------------------------------
(define-syntax-parser my-or
[(_ a b)
#'(let ([tmp a]) (if tmp tmp b))])
==============================
(define-syntax-parse-rule (my-or a b)
(let ([tmp a]) (if tmp tmp b)))
------------------------------
test: "define-syntax with syntax-parse using stx name refactorable to define-syntax-parse-rule"
------------------------------
(define-syntax my-macro
(lambda (stx)
(syntax-parse stx
[(_ x:id)
#'(quote x)])))
==============================
(define-syntax-parse-rule (my-macro x:id)
(quote x))
------------------------------
test: "define-syntax with syntax-parse using custom name in directives replaced with this-syntax"
------------------------------
(define-syntax my-macro
(lambda (input-stx)
(syntax-parse input-stx
[(_ x:id)
#:with loc input-stx
#'(quote (x loc))])))
==============================
(define-syntax-parse-rule (my-macro x:id)
#:with loc this-syntax
(quote (x loc)))
------------------------------
no-change-test: "define-syntax with syntax-parse and multiple clauses not refactorable"
------------------------------
(define-syntax my-or
(lambda (stx)
(syntax-parse stx
[(_ a b)
#'(let ([tmp a]) (if tmp tmp b))]
[(_ a)
#'a])))
------------------------------
no-change-test: "define-syntax-parser with multiple clauses not refactorable"
------------------------------
(define-syntax-parser my-or
[(_ a b)
#'(let ([tmp a]) (if tmp tmp b))]
[(_ a)
#'a])
------------------------------
no-change-test: "define-syntax-parser with syntax/loc not refactorable"
------------------------------
(define-syntax-parser my-macro
[(_ pattern)
(syntax/loc this-syntax
(some-expr))])
------------------------------
no-change-test: "define-syntax-parser without syntax wrapper not refactorable"
------------------------------
(define-syntax-parser my-macro
[(_ x:id)
(let ([tmp (syntax-e #'x)])
#'(quote tmp))])
------------------------------
no-change-test: "define-syntax-parser with quasisyntax not refactorable"
------------------------------
(define-syntax-parser my-macro
[(_ x:id)
#`(quote #,#'x)])
------------------------------