scribble include

26 views
Skip to first unread message

Hendrik Boom

unread,
Apr 6, 2020, 6:27:30 PM4/6/20
to Racket Users
Once again I'm trying to get @(include ...) working in scribble.

The trouble with just using @(include filepath) in scribble is that
the included file is read as racket input instead of syntax and
semantics instead of wih scribble's syntax.

So I thought to try include/reader instead; it has an extra parameter
that can specify how the other file is to be read.

#lang scribble/base
@(require scribble/reader)
@(require racket/include)
foo
@(include/reader "si1.inc" (make-at-reader))
bar

But this gives me a completely unexpected problem. It claims
make-at-reader is an unbound identifier.

If I Use it outside the call to include/reader it's *not* unbound.

The Racket documentation tells me:

The reader-expr is evaluated at expansion time in the transformer
environment.

Is there some way of making this work?

-- hendrik

Matthew Flatt

unread,
Apr 7, 2020, 8:03:48 AM4/7/20
to Hendrik Boom, Racket Users
Use `for-syntax` to import into the transformer environment:

#lang scribble/base
@(require (for-syntax racket/base
(only-in scribble/reader
make-at-reader)))
@(require racket/include)
foo
@(include/reader "si1.inc" (make-at-reader))
bar


The result of `make-at-reader` starts in S-expression mode where `@`
switches to text mode. You may want "si1.inc" to start out in text
mode, more like `#lang scribble/base`. That's almost as easy as
`(make-at-reader #:inside? #t)`, except that the reader in "inside"
mode returns an empty list for an empty input stream, which doesn't
work quite the right way for `include/reader`. Here's one way to adapt
it:

@(include/reader "si1.inc"
(lambda (src in)
(cond
[(eof-object? (peek-byte in))
eof]
[else
(cons #'begin
((make-at-reader #:inside? #t) src in))])))
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/20200406222722.2dvly3zgoi46iack%
> 40topoi.pooq.com.
Reply all
Reply to author
Forward
0 new messages