[racket] Help: Scribble does not see readtable extensions when loading a module

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Jun 27 15:37:01 EDT 2011

What Carl means is something like this: 

@;%
@(begin
#reader scribble/comment-reader
(schemeblock
 ;; Int -> Int 
 ;; increment the argument by 1
 (define (plus1 x) (+ x 1))
))
@;%

If I don't set the sribble/comment-reader the ;-line comments disappear. 

-- Matthias




On Jun 27, 2011, at 3:32 PM, Carl Eastlund wrote:

> Maurizio,
> 
> Modules, including Scribble documents, are read in their entirety
> before any compilation or evaluation is performed.  The read error you
> have seen happens long before your mymodule language gets involved.
> There are a few different ways to fix the example.  First, you could
> put a #reader directive before the code in question, so your <...>
> syntax would be used there.  Second, you could use your <...> reader
> for the entire Scribble document by changing your #lang line.  This
> probably requires a new language implementation similar to #lang s-exp
> that specifies the reader but allows you to specify any language
> bindings, in this case scribble/manual.  Third, you could build the
> example code at runtime by reading from a string.
> 
> Carl Eastlund
> 
> On Mon, Jun 27, 2011 at 12:17 PM, maurizio.giorda
> <maurizio.giorda at gmail.com> wrote:
>> Hi everyone,
>> 
>> I have developed a racket module that implements a new
>> language. In this module I have readtable re-definition like this:
>> 
>> ------------mymodule.rkt---------------------
>> (module mymodule
>> (require racket/base)
>> ...
>> ; new readtable with extensions to support the reading of a new
>> ; data structure: "mset" is a tuple of elements, like < 1, 2, 3 >
>> (define mset-readtable
>>      (make-readtable #f #\< 'terminating-macro parse-open-mset ))
>> 
>> ; change the reader to support my new data structure "mset"
>> (current-readtable mset-readtable)
>> ...
>> )
>> ----------------------------------------------------
>> 
>> Now I am trying to write documentation for this module with scribble.
>> When I use the @interaction in the followign way:
>> 
>> ------------mymodule.scrbl---------------------
>> #lang scribble/manual
>> @(require scribble/eval)
>> ...
>>  @interaction[
>>     (require mymodule)
>>     (make-mset #(1 2 3 4))
>>     (define t2 < 1, 2, 3, 4 >)
>>   ]
>> ...
>> -------------------------------------------------------
>> 
>> I got this in the produced documetation web page:
>> --------------------------------------------------------
>>> (require mymodule)
>>> (make-mset #(1 2 3 4))
>> <1, 2, 3, 4>
>>> (define t2 < 1,2,3,4 >)
>>  eval:3:0: define: bad syntax (multiple expressions after
>>  identifier) in: (define t2 < 1 (unquote 2) (unquote 3)
>>  (unquote 4) >)
>> --------------------------------------------------------
>> 
>> "make-mset" is my data structure constructor function, and it works
>> (you see the printout on the 3rd line),
>> but the same constructor should be called by the reader when
>> processing the "< 1, 2, 3, 4 >" input.
>> So my conclusion is that, for some reasons, the scribble
>> reader have not set my readtable extensions.
>> Does anyone know what is wrong?
>> 
>> Maurizio Giordano
>> 
>> PS: I also tried using @eval[...]
>> with a sandbox evalutator defined by me with
>> the "required" module loaded into it... but it gives
>> me the same result.
> 
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users



Posted on the users mailing list.