(module grammar mzscheme
(require-for-syntax "grammar-procedures.ss"
"grammar-predicate.ss")
(require "grammar-procedures.ss")
(provide (all-from "grammar-procedures.ss"))
(provide grammar define-grammar)
(define-syntax (grammar stx)
(syntax-case stx ()
((_ start (i v ...) ...)
(and (memq (syntax-object->datum (syntax start))
(syntax-object->datum (syntax (i ...))))
(grammar? (syntax-object->datum stx)))
(syntax (letrec ((i (lambda (x) ((seq v ...) x))) ...)
(cfa->predicate start))))))
(define-syntax (define-grammar stx)
(syntax-case stx ()
((_ pred? (grammar start (i v ...) ...))
(and (memq (syntax-object->datum (syntax start))
(syntax-object->datum (syntax (i ...))))
(grammar? (syntax-object->datum (syntax (grammar start (i v ...) ...)))))
(syntax (define-values (pred? i ...)
(letrec ((i (lambda (x) ((grammar-seq v ...) x)))
...)
(values
(grammar-cfa->predicate start)
i ...)))))))
)