General reformat, and move the new comment about #%module-begin to the end of the section
svn: r17194
This commit is contained in:
parent
49df9502a4
commit
ac0a1dc7d8
|
@ -2,7 +2,8 @@
|
||||||
@(require "common.ss")
|
@(require "common.ss")
|
||||||
|
|
||||||
@(require (for-label syntax/module-reader
|
@(require (for-label syntax/module-reader
|
||||||
(only-in scribble/reader read-syntax-inside read-inside)))
|
(only-in scribble/reader
|
||||||
|
read-syntax-inside read-inside)))
|
||||||
|
|
||||||
@title[#:tag "module-reader"]{Module Reader}
|
@title[#:tag "module-reader"]{Module Reader}
|
||||||
|
|
||||||
|
@ -15,7 +16,8 @@ is the name of the module that will be used in the language position
|
||||||
of read modules; using keywords, the resulting readers can be
|
of read modules; using keywords, the resulting readers can be
|
||||||
customized in a number of ways.
|
customized in a number of ways.
|
||||||
|
|
||||||
@defform*/subs[[(#%module-begin module-path)
|
@defform*/subs[
|
||||||
|
[(#%module-begin module-path)
|
||||||
(#%module-begin module-path reader-option ... body ....)
|
(#%module-begin module-path reader-option ... body ....)
|
||||||
(#%module-begin reader-option ... body ....)]
|
(#%module-begin reader-option ... body ....)]
|
||||||
([reader-option (code:line #:language lang-expr)
|
([reader-option (code:line #:language lang-expr)
|
||||||
|
@ -41,8 +43,7 @@ as
|
||||||
module-path)
|
module-path)
|
||||||
]
|
]
|
||||||
|
|
||||||
creates a reader that converts @scheme[#,(hash-lang)_something]
|
creates a reader that converts @scheme[#,(hash-lang)_something] into
|
||||||
into
|
|
||||||
|
|
||||||
@schemeblock[
|
@schemeblock[
|
||||||
(module _name-id module-path
|
(module _name-id module-path
|
||||||
|
@ -82,9 +83,9 @@ procedure (to be called with the key and default result for default
|
||||||
handling). If @scheme[#:info] is not supplied, the default
|
handling). If @scheme[#:info] is not supplied, the default
|
||||||
info-getting procedure is used.
|
info-getting procedure is used.
|
||||||
|
|
||||||
You can also use the (optional) module @scheme[body] forms to provide more
|
You can also use the (optional) module @scheme[body] forms to provide
|
||||||
definitions that might be needed to implement your reader functions.
|
more definitions that might be needed to implement your reader
|
||||||
For example, here is a case-insensitive reader for the
|
functions. For example, here is a case-insensitive reader for the
|
||||||
@scheme[scheme/base] language:
|
@scheme[scheme/base] language:
|
||||||
|
|
||||||
@schemeblock[
|
@schemeblock[
|
||||||
|
@ -138,13 +139,6 @@ no need to iterate them (e.g., Scribble's @scheme[read-inside] and
|
||||||
@scheme[#:whole-body-readers?] as @scheme[#t] --- the readers are
|
@scheme[#:whole-body-readers?] as @scheme[#t] --- the readers are
|
||||||
expected to return a list of expressions in this case.
|
expected to return a list of expressions in this case.
|
||||||
|
|
||||||
[If such whole-body reader functions return a list with a single
|
|
||||||
expression that begins with @scheme[#%module-begin], then the
|
|
||||||
@scheme[syntax/module-reader] language will not inappropriately add
|
|
||||||
another. This for backwards-compatibility with older code: having a
|
|
||||||
whole-body reader functions or wrapper functions that return a
|
|
||||||
@scheme[#%module-begin]-wrapped body is deprectaed.]
|
|
||||||
|
|
||||||
In addition, the two wrappers can return a different value than the
|
In addition, the two wrappers can return a different value than the
|
||||||
wrapped function. This introduces two more customization points for
|
wrapped function. This introduces two more customization points for
|
||||||
the resulting readers:
|
the resulting readers:
|
||||||
|
@ -157,8 +151,7 @@ the resulting readers:
|
||||||
@schemeblock[
|
@schemeblock[
|
||||||
(module ignored syntax/module-reader
|
(module ignored syntax/module-reader
|
||||||
scheme/base
|
scheme/base
|
||||||
#:wrapper1 (lambda (t) (t) '()))
|
#:wrapper1 (lambda (t) (t) '()))]
|
||||||
]
|
|
||||||
Note that it is still performing the read, otherwise the module
|
Note that it is still performing the read, otherwise the module
|
||||||
loader will complain about extra expressions.}
|
loader will complain about extra expressions.}
|
||||||
@item{The reader function that is passed to a @scheme[#:wrapper2]
|
@item{The reader function that is passed to a @scheme[#:wrapper2]
|
||||||
|
@ -198,13 +191,15 @@ expression can be useful in cases such as the above, where the base
|
||||||
language module is chosen based on the input. To make this more
|
language module is chosen based on the input. To make this more
|
||||||
convenient, you can omit the @scheme[module-path] and instead specify
|
convenient, you can omit the @scheme[module-path] and instead specify
|
||||||
it via a @scheme[#:language] expression. This expression can evaluate
|
it via a @scheme[#:language] expression. This expression can evaluate
|
||||||
to a datum or syntax object that is used as a language, or it can evaluate to a thunk.
|
to a datum or syntax object that is used as a language, or it can
|
||||||
In the latter case, the thunk is invoked to obtain such a datum
|
evaluate to a thunk. In the latter case, the thunk is invoked to
|
||||||
before reading the module body begins, in a dynamic extent where
|
obtain such a datum before reading the module body begins, in a
|
||||||
@scheme[current-input-port] is the source input. A syntax object is converted
|
dynamic extent where @scheme[current-input-port] is the source
|
||||||
using @scheme[syntax->datum] when a datum is needed (for @scheme[read] instead of @scheme[read-syntax]).
|
input. A syntax object is converted using @scheme[syntax->datum] when
|
||||||
Using @scheme[#:language], the last
|
a datum is needed (for @scheme[read] instead of @scheme[read-syntax]).
|
||||||
example above can be written more concisely:
|
Using @scheme[#:language], the last example above can be written more
|
||||||
|
concisely:
|
||||||
|
|
||||||
@schemeblock[
|
@schemeblock[
|
||||||
(module reader syntax/module-reader
|
(module reader syntax/module-reader
|
||||||
#:language read
|
#:language read
|
||||||
|
@ -214,6 +209,15 @@ example above can be written more concisely:
|
||||||
(rd in)))
|
(rd in)))
|
||||||
(require scribble/reader))
|
(require scribble/reader))
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Note: if such whole-body reader functions return a list with a single
|
||||||
|
expression that begins with @scheme[#%module-begin], then the
|
||||||
|
@scheme[syntax/module-reader] language will not inappropriately add
|
||||||
|
another. This for backwards-compatibility with older code: having a
|
||||||
|
whole-body reader functions or wrapper functions that return a
|
||||||
|
@scheme[#%module-begin]-wrapped body is deprectaed.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -234,7 +238,8 @@ procedures chains to another language that is specified in an input
|
||||||
stream.
|
stream.
|
||||||
|
|
||||||
@margin-note{The @schememodname[at-exp], @schememodname[reader], and
|
@margin-note{The @schememodname[at-exp], @schememodname[reader], and
|
||||||
@schememodname[planet] languages are implemented using this function.}
|
@schememodname[planet] languages are implemented using this
|
||||||
|
function.}
|
||||||
|
|
||||||
The generated functions expect a target language description in the
|
The generated functions expect a target language description in the
|
||||||
input stream that is provided to @scheme[read-spec]. The default
|
input stream that is provided to @scheme[read-spec]. The default
|
||||||
|
@ -247,7 +252,8 @@ description of the expected language form in the error message.
|
||||||
|
|
||||||
@margin-note{The @schememodname[reader] language supplies
|
@margin-note{The @schememodname[reader] language supplies
|
||||||
@scheme[read] for @scheme[read-spec]. The @schememodname[at-exp] and
|
@scheme[read] for @scheme[read-spec]. The @schememodname[at-exp] and
|
||||||
@schememodname[planet] languages use the default @scheme[read-spec].}
|
@schememodname[planet] languages use the default
|
||||||
|
@scheme[read-spec].}
|
||||||
|
|
||||||
The result of @scheme[read-spec] is converted to a module path using
|
The result of @scheme[read-spec] is converted to a module path using
|
||||||
@scheme[module-path-parser]. If @scheme[module-path-parser] produces
|
@scheme[module-path-parser]. If @scheme[module-path-parser] produces
|
||||||
|
|
Loading…
Reference in New Issue
Block a user