Compare commits

..

No commits in common. "master" and "allow-identifier-macro-style-expanders" have entirely different histories.

3 changed files with 11 additions and 24 deletions

View File

@ -23,7 +23,6 @@ expanders for use with other macros.
environment} environment}
@item{@code{expand-all-id-expanders} - a procedure bound at phase @item{@code{expand-all-id-expanders} - a procedure bound at phase
@; TODO: expand-all-expanders-of-type is not documented @; TODO: expand-all-expanders-of-type is not documented
level 1 that's equivalent to level 1 that's equivalent to @racket[expand-all-expanders-of-type] with
@racket[expand-syntax-tree-with-expanders-of-type] with the the @code{id-expander-type} as the type argument}
@code{id-expander-type} as the type argument}
]} ]}

View File

@ -4,14 +4,16 @@
syntax/parse syntax/parse
syntax/stx syntax/stx
predicates predicates
fancy-app fancy-app)
racket/syntax)
(provide (struct-out expander) (provide (struct-out expander)
(contract-out (contract-out
[expander-of-type? (-> expander-type? expander? boolean?)] [expander-of-type? (-> expander-type? expander? boolean?)]
[expand-syntax-tree-with-expanders-of-type (-> expander-type? syntax? syntax?)])) [expand-syntax-tree-with-expanders-of-type (-> expander-type? syntax? syntax?)]))
(define (maybe-syntax-local-value stx)
(syntax-local-value stx (λ () #f)))
(struct expander (type transformer)) (struct expander (type transformer))
(define (expander-of-type? type expander) (define (expander-of-type? type expander)
@ -20,12 +22,12 @@
(define (expander-stx? v) (define (expander-stx? v)
(and (syntax? v) (and (syntax? v)
(syntax-parse v (syntax-parse v
[(id:id . _) (syntax-local-value/record #'id expander?)] [(id:id . _) (expander? (maybe-syntax-local-value #'id))]
[_ #f]))) [_ #f])))
(define (expander-stx->expander expander-stx) (define (expander-stx->expander expander-stx)
(syntax-parse expander-stx (syntax-parse expander-stx
[(id:id . _) (syntax-local-value/record #'id expander?)])) [(id:id . _) (maybe-syntax-local-value #'id)]))
(define (expander-stx-of-type? type v) (define (expander-stx-of-type? type v)
(and (expander-stx? v) (and (expander-stx? v)
@ -45,7 +47,6 @@
(define (expand-syntax-tree-with-expanders-of-type type stx) (define (expand-syntax-tree-with-expanders-of-type type stx)
(define not-expander-stx-of-type? (not? (expander-stx-of-type? type _))) (define not-expander-stx-of-type? (not? (expander-stx-of-type? type _)))
(with-disappeared-uses (expand-syntax-tree not-expander-stx-of-type?
(expand-syntax-tree not-expander-stx-of-type? call-expander-transformer
call-expander-transformer stx))
stx)))

View File

@ -1,13 +0,0 @@
#lang racket
(require generic-syntax-expanders rackunit)
(define-expander-type foo)
(define-foo-expander foo1 (λ _ #''ok))
(define-syntax (bar stx)
(syntax-case stx ()
[(_ body)
(expand-all-foo-expanders #'body)]))
;; When hovering "foo1" in the code below with the mouse, an arrow should
;; be shown in DrRacket from the foo1 in (define-foo-expander foo1 …) above.
;; This is not automatically checked, as it would be difficult/brittle to check
;; for the syntax property. Patches welcome.
(check-equal? (bar (foo1)) 'ok)