diff --git a/default-recommendations/syntax-parse-shortcuts-test.rkt b/default-recommendations/syntax-parse-shortcuts-test.rkt index 47b8e59..653064d 100644 --- a/default-recommendations/syntax-parse-shortcuts-test.rkt +++ b/default-recommendations/syntax-parse-shortcuts-test.rkt @@ -84,3 +84,34 @@ no-change-test: "define-syntax-parser with multiple clauses not refactorable" [(_ a) #'a]) ------------------------------ + + +test: "define-syntax-parser with pattern directives refactorable to define-syntax-parse-rule" +------------------------------ +(define-syntax-parser my-macro + [(_ x:id) + #:with y #'(x x) + #'(quote y)]) +============================== +(define-syntax-parse-rule (my-macro x:id) + #:with y #'(x x) + (quote y)) +------------------------------ + + +no-change-test: "define-syntax-parser with syntax/loc on the output not refactorable" +------------------------------ +(define-syntax-parser my-or + [(_ a b) + (syntax/loc this-syntax + (let ([tmp a]) (if tmp tmp b)))]) +------------------------------ + + +no-change-test: "define-syntax-parser with non-directive body forms not refactorable" +------------------------------ +(define-syntax-parser my-or + [(_ a b) + (printf "expanding my-or\n") + #'(let ([tmp a]) (if tmp tmp b))]) +------------------------------ diff --git a/default-recommendations/syntax-parse-shortcuts.rkt b/default-recommendations/syntax-parse-shortcuts.rkt index 29d5c0f..dc40df3 100644 --- a/default-recommendations/syntax-parse-shortcuts.rkt +++ b/default-recommendations/syntax-parse-shortcuts.rkt @@ -49,21 +49,14 @@ 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 ...]) - - #: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 - - (define-syntax-parse-rule (macro . pattern) new-body-part ...)) + [(_ . pattern) directive:syntax-parse-pattern-directive ... (syntax-id last-form)]) + + #:with (new-body ...) #'((~@ . directive) ... last-form) + + (define-syntax-parse-rule (macro . pattern) new-body ...)) (define-refactoring-suite syntax-parse-shortcuts