Is there a way to interpose on reading `#;`, `#|...|#`, and `#!` comments
with the standard e-expression reader? I can override the handling of
normal `;` line comments by adding a terminating macro to the reader, but
adding dispatch macros for the others doesn't seem to work (see below). I
wondered if they might be producing special comments
<https://docs.racket-lang.org/reference/special-comments.html>, but, if so,
I haven't managed to intercept them, and I also haven't seen any relevant
reader parameters.

#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")))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to