You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beautiful-racket/beautiful-racket-lib/br/quicklang.rkt

32 lines
1.3 KiB
Racket

#lang br
(require (for-syntax racket/list sugar/debug))
(provide (except-out (all-from-out br) #%module-begin)
8 years ago
(rename-out [quicklang-mb #%module-begin])
(for-syntax (all-from-out sugar/debug)))
8 years ago
(define-macro (quicklang-mb . EXPRS)
9 years ago
(define-values
(kw-pairs other-exprs)
8 years ago
(let loop ([kw-pairs null][exprs (syntax->list #'EXPRS)])
(if (and (pair? exprs) (keyword? (syntax-e (car exprs))))
(loop (cons (cons (string->symbol (keyword->string (syntax-e (car exprs))))
9 years ago
(cadr exprs)) ; leave val in stx form so local binding is preserved
kw-pairs)
(cddr exprs))
(values kw-pairs exprs))))
(define reserved-keywords '(provide))
(define (reserved? kw-pair) (memq (car kw-pair) reserved-keywords))
(define-values (reserved-kwpairs other-kwpairs) (partition reserved? kw-pairs))
(with-pattern ([((KW . VAL) ...) other-kwpairs]
[(PROVIDED-ID ...) (or (assq 'provide reserved-kwpairs) null)])
9 years ago
#`(#%module-begin
(provide PROVIDED-ID ...)
9 years ago
(provide (rename-out [VAL KW]) ...)
(provide #%top #%app #%datum #%top-interaction)
8 years ago
. #,(datum->syntax #'EXPRS other-exprs #'EXPRS))))
(module reader syntax/module-reader
#:language 'br/quicklang
#:info br-get-info
(require br/get-info))