Fix define-syntax-parser-to-define-syntax-parse-rule-simple to only match syntax-wrapped bodies
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
#:doblock 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-ruleshortcut 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.