stxparam approach

dev-elider-3
Matthew Butterick 9 years ago
parent 7e605cd081
commit 705ea591b0

@ -5,21 +5,18 @@
(all-defined-out)) (all-defined-out))
(require (for-syntax racket/syntax racket/list br/datum)) (require (for-syntax racket/syntax racket/list br/datum))
(define-for-syntax alphasyms (for/list ([i (in-string "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]) (require racket/stxparam)
(string->symbol (format "~a" i)))) (define-syntax-parameter A
(define-for-syntax stringsyms (map (λ(s) (format-datum "~a$" s)) alphasyms)) (λ (stx)
(raise-syntax-error (syntax-e stx) "can only be used inside the place")))
(define-syntax (basic-module-begin stx)
(syntax-case stx () (define #'(basic-module-begin PARSE-TREE ...)
[(_ PARSE-TREE ...) #'(#%module-begin
(with-syntax ([(VARNAME ...) (datum->syntax stx alphasyms)] (let ([A-inner 0])
[(STRINGVARNAME ...) (datum->syntax stx stringsyms)]) (syntax-parameterize
#'(#%module-begin ([A (make-rename-transformer #'A-inner)])
(define VARNAME 0) ... (println (quote PARSE-TREE ...))
(define STRINGVARNAME "") ... PARSE-TREE ...))))
(provide VARNAME ... STRINGVARNAME ...)
(println (quote PARSE-TREE ...))
PARSE-TREE ...))]))
; #%app and #%datum have to be present to make #%top work ; #%app and #%datum have to be present to make #%top work
(define #'(basic-top . id) (define #'(basic-top . id)
@ -94,8 +91,8 @@
(define #'(INPUT PRINT-LIST ";" ID) (define #'(INPUT PRINT-LIST ";" ID)
#'(begin #'(begin
(PRINT (append PRINT-LIST (list ";"))) (PRINT (append PRINT-LIST (list ";")))
(set! ID (read-line)))) (set! ID (read-line))))
(define (GOTO where) (define (GOTO where)
where) where)

Loading…
Cancel
Save