Alternatively, to allow intercepting reading from source files only, Chez Scheme could provide `make-read-handler`.
(set-who! default-make-read-handler
(lambda (ip sfd fp)
(lambda ()
(let-values ([(x new-fp) (do-read who ip sfd #t fp)])
(set! fp new-fp)
x))))
(set! make-read-handler
(make-parameter default-make-read-handler))
(set! $make-read
(lambda (ip sfd fp)
(define who 'read)
(unless (and (input-port? ip) (textual-port? ip))
($oops who "~s is not a textual input port" ip))
(unless (or (not sfd) (source-file-descriptor? sfd))
($oops who "~s is not a source-file descriptor" sfd))
((make-read-handler) ip sfd fp)))
Michał