4 Reader Helpers
4.1 Raising exn:fail:read
| ||||||||||||||||||||||||||||||||||||||||||
msg-string : string? | ||||||||||||||||||||||||||||||||||||||||||
source : any/c | ||||||||||||||||||||||||||||||||||||||||||
Creates and raises an exn:fail:read exception, using msg-string as the base error message.
Source-location information is added to the error message using the last five arguments (if the error-print-source-location parameter is set to #t). The source argument is an arbitrary value naming the source location – usually a file path string. Each of the line, pos arguments is #f or a positive exact integer representing the location within source-name (as much as known), col is a non-negative exact integer for the source column (if known), and span is #f or a non-negative exact integer for an item range starting from the indicated position.
The usual location values should point at the beginning of whatever it is you were reading, and the span usually goes to the point the error was discovered.
| ||||||||||||||||||||||||||||||||||||||||||
msg-string : string? | ||||||||||||||||||||||||||||||||||||||||||
source : any/c | ||||||||||||||||||||||||||||||||||||||||||
Like raise-read-error, but raises exn:fail:read:eof instead of exn:fail:read.
4.2 Module Reader
The syntax/module-reader language provides support for defining #lang readers.
(#%module-begin module-path) |
Causes a module written in the syntax/module-reader language to define and provide read and read-syntax functions, making the module an implementation of a reader. In particular, the exported reader functions read all S-expressions until an end-of-file, and it packages them into a new module in the module-path language.
That is, a module something/lang/reader implemented as
(module reader module-syntax/module-reader |
module-path) |
creates a reader that converts #lang something into
(module name-id module-path |
....) |
where name-id is derived from the name of the port used by the reader.
For example, scheme/base/lang/reader is implemented as
(module reader module-syntax/module-reader |
scheme/base) |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mod-path : module-path? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
in : input-port? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mod-path-stx : syntax? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
line : number? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
col : number? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pos : number? |
Repeatedly calls read on in until an end of file, collecting the results in order into lst, and derives a name-id from (object-name in). The last five arguments are used to construct the syntax object for the language position of the module. The result is roughly
`(module ,name-id ,mod-path ,@lst)