resyntax icon indicating copy to clipboard operation
resyntax copied to clipboard

Fix define-syntax-parser-to-define-syntax-parse-rule-simple to only match syntax-wrapped bodies

Open Copilot opened this issue 3 months ago • 1 comments

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 https://github.com/jackfirth/resyntax/blob/43f5fc6153b1d1dc9fff65a23391c4aac604fb22/default-recommendations/syntax-parse-shortcuts.rkt#L48 and https://github.com/benknoble/frosthaven-manager/pull/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>

  • Fixes jackfirth/resyntax#759

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

Copilot avatar Nov 24 '25 17:11 Copilot

Coverage Status

coverage: 93.69% (+0.006%) from 93.684% when pulling db3af6a8cbee555b98c8875be1d2ea38de35d3d0 on copilot/fix-syntax-parse-rule-issue into 4d3ff74588916912e5086ce7de9e9eaf08ac67b6 on master.

coveralls avatar Jan 05 '26 06:01 coveralls