From 474a83ce7746d977288b0664f4de4db2608a9b20 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 24 Nov 2025 17:02:13 +0000 Subject: [PATCH 1/2] Initial plan From 50e0f22cf2a4e9f39cd2bcd7e024821f79433b01 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 24 Nov 2025 17:11:10 +0000 Subject: [PATCH 2/2] Fix define-syntax-parser-to-define-syntax-parse-rule-simple to only match syntax-wrapped forms Co-authored-by: jackfirth <8175575+jackfirth@users.noreply.github.com> --- .../syntax-parse-shortcuts-test.rkt | 26 +++++++++++++++++++ .../syntax-parse-shortcuts.rkt | 16 ++++-------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/default-recommendations/syntax-parse-shortcuts-test.rkt b/default-recommendations/syntax-parse-shortcuts-test.rkt index 47b8e59..221db07 100644 --- a/default-recommendations/syntax-parse-shortcuts-test.rkt +++ b/default-recommendations/syntax-parse-shortcuts-test.rkt @@ -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)]) +------------------------------ diff --git a/default-recommendations/syntax-parse-shortcuts.rkt b/default-recommendations/syntax-parse-shortcuts.rkt index 29d5c0f..6b64e5d 100644 --- a/default-recommendations/syntax-parse-shortcuts.rkt +++ b/default-recommendations/syntax-parse-shortcuts.rkt @@ -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