philip.mcgrath
2019-4-22 20:02:13

Is there a way to interpose on reading #;, #\|...\|#, and #! comments? Adding dispatch macros to a readtable doesn’t seem to work: #lang racket (require syntax/readerr) (define ((comment-error msg) ch in src line col pos) (raise-read-error msg src line col pos 1)) (define readtable (make-readtable #f #\; 'terminating-macro (comment-error "line") #\; 'dispatch-macro (comment-error "s-exp") #\\| 'dispatch-macro (comment-error "block") #\! 'dispatch-macro (comment-error "unix"))) (parameterize ([current-readtable readtable]) (for ([str '("#;datum" "#\|a block\|#" "#!/usr/bin/env racket")]) (read (open-input-string str))) (read (open-input-string ";only this works as expected")))


daniel
2019-4-22 20:54:10

Definitely a beginner’s question here. How would I create a language module – one which I could use as #lang my-lang – if I’m using the s-exp reader? I’m using my own expander.


samdphillips
2019-4-22 21:46:06

@samdphillips has joined the channel


philip.mcgrath
2019-4-22 21:54:19

@daniel This chapter of the guide explains: https://docs.racket-lang.org/guide/hash-languages.html The main step is that you need to install your project as a collection/package. After that, if you put this in the file you would import with (require example): #lang racket/base (module reader syntax/module-reader example) you will be set up to write #lang example.