Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions default-recommendations/syntax-parse-shortcuts-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,29 @@ no-change-test: "define-syntax-parser with multiple clauses not refactorable"
[(_ 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)])
------------------------------
16 changes: 5 additions & 11 deletions default-recommendations/syntax-parse-shortcuts.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,15 @@ equivalent `define-syntax-parse-rule` macro."
#:description
"This `define-syntax-parser` macro with a single clause can be replaced with a simpler, equivalent
`define-syntax-parse-rule` macro."
#:literals (define-syntax-parser)
#:literals (define-syntax-parser [syntax-id syntax #:phase 1])

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

#:do [(define (strip-syntax-wrapper stx)
(syntax-parse stx
#:literals (syntax)
[(syntax body) #'body]
[other #'other]))
(define new-body (map strip-syntax-wrapper (attribute body)))]

#:with (new-body-part ...) new-body
#:with (new-body ...)
#'((~@ . directive) ... last-form)

(define-syntax-parse-rule (macro . pattern) new-body-part ...))
(define-syntax-parse-rule (macro . pattern) new-body ...))


(define-refactoring-suite syntax-parse-shortcuts
Expand Down