Skip to content

Commit 50e0f22

Browse files
Copilotjackfirth
andcommitted
Fix define-syntax-parser-to-define-syntax-parse-rule-simple to only match syntax-wrapped forms
Co-authored-by: jackfirth <[email protected]>
1 parent 474a83c commit 50e0f22

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

default-recommendations/syntax-parse-shortcuts-test.rkt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,29 @@ no-change-test: "define-syntax-parser with multiple clauses not refactorable"
8484
[(_ a)
8585
#'a])
8686
------------------------------
87+
88+
89+
no-change-test: "define-syntax-parser with syntax/loc not refactorable"
90+
------------------------------
91+
(define-syntax-parser my-macro
92+
[(_ pattern)
93+
(syntax/loc this-syntax
94+
(some-expr))])
95+
------------------------------
96+
97+
98+
no-change-test: "define-syntax-parser without syntax wrapper not refactorable"
99+
------------------------------
100+
(define-syntax-parser my-macro
101+
[(_ x:id)
102+
(let ([tmp (syntax-e #'x)])
103+
#'(quote tmp))])
104+
------------------------------
105+
106+
107+
no-change-test: "define-syntax-parser with quasisyntax not refactorable"
108+
------------------------------
109+
(define-syntax-parser my-macro
110+
[(_ x:id)
111+
#`(quote #,#'x)])
112+
------------------------------

default-recommendations/syntax-parse-shortcuts.rkt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,15 @@ equivalent `define-syntax-parse-rule` macro."
4949
#:description
5050
"This `define-syntax-parser` macro with a single clause can be replaced with a simpler, equivalent
5151
`define-syntax-parse-rule` macro."
52-
#:literals (define-syntax-parser)
52+
#:literals (define-syntax-parser [syntax-id syntax #:phase 1])
5353

5454
(define-syntax-parser macro:id
55-
[(_ . pattern) body ...])
55+
[(_ . pattern) directive:syntax-parse-pattern-directive ... (syntax-id last-form)])
5656

57-
#:do [(define (strip-syntax-wrapper stx)
58-
(syntax-parse stx
59-
#:literals (syntax)
60-
[(syntax body) #'body]
61-
[other #'other]))
62-
(define new-body (map strip-syntax-wrapper (attribute body)))]
63-
64-
#:with (new-body-part ...) new-body
57+
#:with (new-body ...)
58+
#'((~@ . directive) ... last-form)
6559

66-
(define-syntax-parse-rule (macro . pattern) new-body-part ...))
60+
(define-syntax-parse-rule (macro . pattern) new-body ...))
6761

6862

6963
(define-refactoring-suite syntax-parse-shortcuts

0 commit comments

Comments
 (0)