File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,17 @@ test: "define-syntax with syntax-parse using stx name refactorable to define-syn
4949------------------------------
5050
5151
52+ no-change-test: "define-syntax with syntax-parse using custom name in directives not refactorable "
53+ ------------------------------
54+ (define-syntax my-macro
55+ (lambda (input-stx)
56+ (syntax-parse input-stx
57+ [(_ x:id)
58+ #:with loc input-stx
59+ #'(quote (x loc))])))
60+ ------------------------------
61+
62+
5263no-change-test: "define-syntax with syntax-parse and multiple clauses not refactorable "
5364------------------------------
5465(define-syntax my-or
Original file line number Diff line number Diff line change @@ -29,8 +29,23 @@ equivalent `define-syntax-parse-rule` macro."
2929 (syntax-parse-id:id parsed-stx:id
3030 [(_ . pattern) body ... ])))
3131
32+ #:do [(define stx-id (attribute stx-var))
33+ ;; Check if stx-var is referenced in the body
34+ (define (has-stx-ref? stx)
35+ (syntax-parse stx
36+ [id:id
37+ #:when (free-identifier=? #'id stx-id)
38+ #t ]
39+ [(head . tail)
40+ (or (has-stx-ref? #'head )
41+ (has-stx-ref? #'tail ))]
42+ [_ #f ]))
43+ (define body-has-stx-ref?
44+ (ormap has-stx-ref? (attribute body)))]
45+
3246 #:when (and (free-identifier=? (attribute stx-var) (attribute parsed-stx))
33- (equal? (syntax-e (attribute syntax-parse-id)) 'syntax-parse ))
47+ (equal? (syntax-e (attribute syntax-parse-id)) 'syntax-parse )
48+ (not body-has-stx-ref?))
3449
3550 (define-syntax-parse-rule (macro . pattern) body ... ))
3651
You can’t perform that action at this time.
0 commit comments