add define-syntax-parser
idea from
863d39229f (diff-3252674930bbd0c4e113856a2a3a5747R118)
This commit is contained in:
parent
cb3f296678
commit
fae92a19f5
|
@ -37,3 +37,25 @@ Defines a macro named @racket[macro-id]; equivalent to the following:
|
||||||
]
|
]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@defform[(define-syntax-parser macro-id parse-option ... clause ...+)]{
|
||||||
|
|
||||||
|
Defines a macro named @racket[macro-id]; equivalent to:
|
||||||
|
|
||||||
|
@racketblock[
|
||||||
|
(define-syntax macro-id
|
||||||
|
(syntax-parser parse-option ... clause ...))
|
||||||
|
]
|
||||||
|
|
||||||
|
@myexamples[
|
||||||
|
(define-syntax-parser fn3
|
||||||
|
[(fn3 x:id rhs:expr)
|
||||||
|
#'(lambda (x) rhs)]
|
||||||
|
[(fn3 x:id y:id rhs:expr)
|
||||||
|
#'(lambda (x y) rhs)])
|
||||||
|
((fn3 x x) 17)
|
||||||
|
((fn3 a b (+ a b)) 3 4)
|
||||||
|
(fn3 1 2)
|
||||||
|
(fn3 a #:b 'c)
|
||||||
|
]}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
syntax/parse
|
syntax/parse
|
||||||
"private/sc.rkt"))
|
"private/sc.rkt"))
|
||||||
(provide define-simple-macro
|
(provide define-simple-macro
|
||||||
|
define-syntax-parser
|
||||||
(for-syntax (all-from-out syntax/parse)))
|
(for-syntax (all-from-out syntax/parse)))
|
||||||
|
|
||||||
(define-syntax (define-simple-macro stx)
|
(define-syntax (define-simple-macro stx)
|
||||||
|
@ -12,3 +13,8 @@
|
||||||
(syntax-parser/template
|
(syntax-parser/template
|
||||||
#,((make-syntax-introducer) stx)
|
#,((make-syntax-introducer) stx)
|
||||||
[pattern . body]))]))
|
[pattern . body]))]))
|
||||||
|
|
||||||
|
(define-simple-macro (define-syntax-parser macro:id option-or-clause ...)
|
||||||
|
(define-syntax macro
|
||||||
|
(syntax-parser option-or-clause ...)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user