Merge pull request #10 from jsmaniac/allow-arbitrary-expander-parameters

Allow arbitrary expander parameters, like (some-foo-expander x y . z).
This commit is contained in:
Jack Firth 2016-08-25 11:51:27 -07:00 committed by GitHub
commit fa35d7b777
2 changed files with 24 additions and 2 deletions

View File

@ -22,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 _ ...) (expander? (maybe-syntax-local-value #'id))] [(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 _ ...) (maybe-syntax-local-value #'id)])) [(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)

View File

@ -0,0 +1,22 @@
#lang racket
(require generic-syntax-expanders
(for-syntax syntax/parse)
rackunit)
(define-expander-type foo)
(define-foo-expander some-foo-expander
(syntax-parser
[(_ a:id b:id c:id . d:id) #'(d c b a)]))
(define-syntax (test-foo-expander stx)
(syntax-parse stx
[(_ e:expr)
#`'#,(expand-all-foo-expanders #'e)]))
(test-equal?
"Check that some-foo-expander accepts being called
when it is the first item of a dotted list"
(test-foo-expander (some-foo-expander x y z . t))
'(t z y x))