[racket] Read-syntax for an entire .rkt file
What you want is `with-module-reading-parameterization
<http://docs.racket-lang.org/syntax/module-helpers.html?q=with-module-reading#%28def._%28%28lib._syntax%2Fmodread..rkt%29._with-module-reading-parameterization%29%29>
`:
(with-module-reading-parameterization
<http://docs.racket-lang.org/syntax/module-helpers.html?q=with-module-reading#%28def._%28%28lib._syntax%2Fmodread..rkt%29._with-module-reading-parameterization%29%29>
(lambda
() (read (open-input-port "my-file.rkt"))))
On Fri Feb 20 2015 at 12:43:15 AM Thomas Gilray <thomas.gilray at gmail.com>
wrote:
> Hi,
>
> I am trying to figure out how to use read-syntax on a port for an entire
> .rkt file. I want to then call (expand ...) on this and get back a (begin
> ...) or (module ...) form for the entire file in fully expanded form. Right
> now I have three issues:
>
> a) I have to skip over the #lang as this is not recognized by read-syntax
> itself
>
> b) I've needed to call read-syntax repeatedly to consume the whole file
> and put each expression in a top-level begin (a pretty klugy workaround)
>
> c) even then, calling expand will report an error that "define" is not
> itself defined. Maybe there is a version of read-syntax that will use
> read-language internally in the right way but I can't find it.
>
> There is probably a way of doing all of this at once, and better, but I
> don't know what that would be. I feel read-language is needed, but I don't
> see how this would work together with read-syntax.
>
> Any advice or pointers would be greatly appreciated!
>
> --
> Tom
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150220/4f89ac68/attachment.html>