add define-syntax-parser

idea from
863d39229f (diff-3252674930bbd0c4e113856a2a3a5747R118)
This commit is contained in:
AlexKnauth 2014-12-08 16:18:47 -05:00 committed by Ryan Culpepper
parent cb3f296678
commit fae92a19f5
2 changed files with 28 additions and 0 deletions

View File

@ -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)
]}

View File

@ -3,6 +3,7 @@
syntax/parse
"private/sc.rkt"))
(provide define-simple-macro
define-syntax-parser
(for-syntax (all-from-out syntax/parse)))
(define-syntax (define-simple-macro stx)
@ -12,3 +13,8 @@
(syntax-parser/template
#,((make-syntax-introducer) stx)
[pattern . body]))]))
(define-simple-macro (define-syntax-parser macro:id option-or-clause ...)
(define-syntax macro
(syntax-parser option-or-clause ...)))