[plt-scheme] emulating default reader behaviors

From: Felix Klock's PLT scheme proxy (pltscheme at pnkfx.org)
Date: Wed Jan 4 02:52:00 EST 2006

PLTers-

I'm trying to update my here-xexprs library to use the readtable  
system introduced with v300.

In a nutshell, the here-xexprs system is supposed to allow one to write

#<>END
<hello>foo</hello>
END

and get back an appropriate Xexpr.

I really want to do this by piggy-backing my library on top of the  
already existing Here-string implementation in v300.  That is, I want  
to trick the reader into thinking it saw #<< instead of #<>, read the  
corresponding Here-string, and then post-process the Here-string by  
parsing the XML within.

However, I do not see a way, within a reader macro, to force the  
reader to read the input-port as if the characters #\# #\< #\< had  
just been read.

At the end of section 11.2.8 of the MzScheme language manual, it says:

"Note that reader-macro procedures for the default readtable are not  
directly accessible. To invoke default behaviors, use read/recursive  
or read-syntax/recursive (see section 11.2.9.2) with a character and  
the #f readtable."

My impression is that this only allows the user to emulate the  
behavior of default reader syntax similar to that provided by  
terminating-macro and non-terminating-macro; it does not allow the  
user to emulate the behavior of default reader syntax similar to that  
provided by dispatch-macro.  That is, the caller needs to feed in at  
least two characters to get hash character dispatches to fire off  
(and for my purposes I'd really need all three characters).

(I have also tried getting the effect using input-port-append to push  
the "#<<" character sequence onto the port.  But this doesn't seem to  
work properly in the DrScheme repl.  My initial investigations show  
that this could be because input-port-append eagerly drops ports as  
soon as it sees EOF, even for the last port on its argument list.   
But even hacking that to not drop the final port does not seem to do  
the trick.)

If anyone wants to see the code I have so far, I'm happy to share,  
but I thought someone might have some immediate insight as to how to  
approach this problem first.

-Felix



Posted on the users mailing list.