[plt-scheme] using custom readers

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Aug 24 21:05:52 EDT 2008

At Sun, 24 Aug 2008 17:00:45 -0700, "Steve Huffman" wrote:
> I have a module in "slice.scm" that provides versions of read and
> read-syntax that uses a custom readtable.
> If I say (require "slice.scm) then use #reader "slice.scm" I can use
> my custom readtable for the following expression, and all is well.
> What I'd really like to be able to do is define another module that
> uses my "slice" reader without having to say #reader "slice.scm"
> before every form. For example, it would really be really nice to
> start a module with "#lang slice" and have it use my reader. Right now
> when I do that I get an error similar to:
> default-load-handler: expected a `module' declaration for `foo',
> found: something else in: #<path:/tmp/foo.scm>

The `slide/lang/reader' module needs to provide a `read' that's a
little different than the one from "slice.scm". Instead of reading a
single expression, the reader from `slide/lang/reader' should read
until it hits an EOF. Then it should package up the forms that it found
(before EOF) into a `module' form.

The `wrap-read-all' function from `syntax/module-reader' is useful for
creating the latter kind of reader. As an example, see the R5RS reader
in the `r5rs/lang/reader' module.


Posted on the users mailing list.