racket - Creating a readtable with a disabled dispatch reader macro -


i creating new language based on racket , don't want #x macros work, such syntax-quote #'. how remove #' not syntax quote, whatever unbound dispatch macro-char does?

i can single-char macros doing

(make-readtable (current-readtable)                 #\' #\a #f) ; set ' same normal character 

but don't know how dispatch macros.

assuming want #' treated ':

provide reader-proc calls normal read-syntax:

#lang racket/base  (define (reader-proc ch in src line col pos)   (read-syntax src in))  (define our-readtable (make-readtable (current-readtable)                                       #\'                                       'dispatch-macro                                       reader-proc))  ;; `#:wrapper1` `syntax/module-reader`, i.e. use in ;; lang/reader.rkt (define (wrapper1 thk)   (parameterize ([current-readtable our-readtable])     (thk))) (provide wrapper1)  ;; tests (module+ test   (require rackunit            racket/port)   (parameterize ([current-readtable our-readtable])     (check-equal? (with-input-from-string "#'foo" read)                   'foo)     (check-equal? (with-input-from-string "#'(foo)" read)                   '(foo))     (check-equal? (with-input-from-string "#'(foo #'(bar))" read)                   '(foo (bar))))) 

a more complicated example of working 'dispatch-macro lambda reader literal support added #lang rackjure.


updated

assuming want #' cause read error, "bad syntax: #'":

#lang racket/base  (require syntax/readerr)  (define (reader-proc ch in src line col pos)   (raise-read-error (format "bad syntax: #~a" ch)                     src line col pos 2))  (define our-readtable (make-readtable (current-readtable)                                       #\'                                       'dispatch-macro                                       reader-proc))  ;; `#:wrapper1` `syntax/module-reader`, i.e. use in ;; lang/reader.rkt (define (wrapper1 thk)   (parameterize ([current-readtable our-readtable])     (thk))) (provide wrapper1)  ;; tests (module+ test   (require rackunit            racket/port)   (parameterize ([current-readtable our-readtable])     (check-exn exn:fail? (λ () (with-input-from-string "#'foo" read))))) 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -