improve template->pattern, used in syntax-lens

This commit is contained in:
Alex Knauth 2016-07-24 20:55:42 -04:00 committed by AlexKnauth
parent 7274791b7d
commit 27806613c0

View File

@ -53,10 +53,11 @@
[(a ...) (ormap (target-stx target-id) (syntax->list #'(a ...)))] [(a ...) (ormap (target-stx target-id) (syntax->list #'(a ...)))]
[a (and (bound-identifier=? target-id #'a) #'a)])) [a (and (bound-identifier=? target-id #'a) #'a)]))
(define template->pattern (define (template->pattern stx)
(syntax-parser #:literals (_) (syntax-parse stx
[(a ...) #`(#,@(stx-map template->pattern #'(a ...)))] ;; preserve lexical context, source location, and properties
[_ (generate-temporary)] [(a ...) (datum->syntax stx (stx-map template->pattern #'(a ...)) stx stx)]
[(~literal _) (generate-temporary)]
[a #'a])) [a #'a]))
(define ((template-rebuilder target-id) parse-pattern) (define ((template-rebuilder target-id) parse-pattern)