(module generator-definitions mzscheme
(provide define-generator)
(require-for-syntax "generator-struct.scm")
(require-for-template mzscheme)
(define-syntax (define-generator stx)
(syntax-case stx ()
[(_ (name arg) body ...)
(begin
(unless (identifier? #'name)
(raise-syntax-error
'define-generator "expected (define-generator <id> <procedure>), got: " #'name))
(unless (identifier? #'name)
(raise-syntax-error
'define-generator "expected (define-generator (<id> name) <body> ...), got: " #'name))
#'(begin
(define-for-syntax name (make-generator 'name (lambda (arg) body ...)))
(define-syntax name (make-generator 'name (lambda (arg) body ...)))))]
[(_ name proc)
(begin
(unless (identifier? #'name)
(raise-syntax-error
'define-generator "expected (define-generator <id> <procedure>), got: " #'name))
#'(begin
(define-for-syntax name (make-generator 'name proc))
(define-syntax name (make-generator 'name proc))))]
[_else
(raise-syntax-error
'define-generator
"expected either (define-generator <id> <proc>) or (define-generator (<id1> <id2>) <body> ... , got: "
stx)])))