Reputation: 277
I have created a module which provides various functions, including #%module-begin. I want to use it with at-exp syntax, which I can do using the following #lang line:
#lang at-exp s-exp "my-library.rkt"
However, this does not read unknown symbols as strings, as would happen for example when using the scribble/text language. How can I provide this functionality from my library, to save me writing quote marks around all my strings?
I think it may have something to do with the #%top function. Perhaps I can require it somehow from scribble/text and then provide it from my library?
Upvotes: 0
Views: 96
Reputation: 8373
What scribble/text
does, is it starts reading the file in "text" mode, whereas at-exp
starts reading the file in "racket" mode. Messing with #%top
is not what you want here. To do the same thing as scribble/text
, you would need a version of at-exp
that starts in text mode. That doesn't exist (yet) though.
The function read-syntax-inside
from scribble/reader
does this. However, you will have to define your own #lang
language that uses it. For that, you might find this documentation helpful, but there's no quick answer.
I looked at the implementation of scribble/text
, and the answer seems a lot quicker than I thought it would be. Something like this should work:
my-library/lang/reader.rkt
:
#lang s-exp syntax/module-reader
my-library/main
#:read scribble:read-inside
#:read-syntax scribble:read-syntax-inside
#:whole-body-readers? #t
#:info (scribble-base-reader-info)
(require (prefix-in scribble: scribble/reader)
(only-in scribble/base/reader scribble-base-reader-info))
Testing it:
#lang my-library
This is text
@(list 'but 'this 'is 'not)
I tested this with my-library/main.rkt
re-providing everything from racket/base
.
Upvotes: 2