Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 24, 2025

The define-syntax-parser-to-define-syntax-parse-rule-simple rule was incorrectly matching and stripping syntax wrappers from all body forms, including cases where the body used syntax/loc, had no wrapper, or used quasisyntax.

Changes:

  • Match pattern now requires the last body form to be wrapped in syntax (via [syntax-id syntax #:phase 1] literal)
  • Removed #:do block that unconditionally stripped syntax wrappers from all forms
  • Pattern changed from [(_ . pattern) body ...] to [(_ . pattern) directive:syntax-parse-pattern-directive ... (syntax-id last-form)]

Example:

;; Now correctly ignored (uses syntax/loc instead of syntax)
(define-syntax-parser my-macro
  [(_ pattern)
   (syntax/loc this-syntax
     (some-expr))])

;; Still correctly matched
(define-syntax-parser my-or
  [(_ a b)
   #'(let ([tmp a]) (if tmp tmp b))])

Added test coverage for syntax/loc, unwrapped bodies, and quasisyntax cases.

Original prompt

This section details on the original issue you should resolve

<issue_title>define-syntax-parser-to-define-syntax-parse-rule-simple ignores syntax/loc on the output</issue_title>
<issue_description>See

(define-refactoring-rule define-syntax-parser-to-define-syntax-parse-rule-simple
and benknoble/frosthaven-manager#126</issue_description>

Comments on the Issue (you are @copilot in this section)

@jackfirth Looks like [this logic](https://github.com/jackfirth/resyntax/blob/43f5fc6153b1d1dc9fff65a23391c4aac604fb22/default-recommendations%2Fsyntax-parse-shortcuts.rkt#L54-L64) is wrong. It should only match when the last body form is wrapped in `syntax`, not always match and then strip the `syntax` if it's present.

This is a bug that was also present in the other define-syntax-parse-rule shortcut initially. When I was fixing that in Copilot's implementation, I failed to notice the other rule had the same problem.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix issue with define-syntax-parse-rule ignoring syntax/loc Fix define-syntax-parser-to-define-syntax-parse-rule-simple to only match syntax-wrapped bodies Nov 24, 2025
Copilot AI requested a review from jackfirth November 24, 2025 17:14
Copilot finished work on behalf of jackfirth November 24, 2025 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

define-syntax-parser-to-define-syntax-parse-rule-simple ignores syntax/loc on the output

2 participants