This is an R6RS Scheme library that provides a reader with some extra
features not found in the standard read
procedure:
- Compatible mode with support for other RnRS standards.
- Tolerant mode that continues on errors.
- Lexer that returns source code tokens, including whitespace.
- Source annotations, initially designed to be compatible-ish with psyntax.
Läsare means reader in the Swedish language.
(import (laesare reader))
Return a new reader object for the textual input port associated with filename (which is used in annotation objects).
True if obj is a reader object.
Reads a token and returns it as two values.
Read a datum from the reader, returning it as a standard Scheme object.
The same as read-datum
, except it returns an annotation
object.
See the procedures below.
Get the current reader mode. These modes exist:
rnrs
-- any RnRS syntax is allowed, with reasonable compromisesr6rs
-- only R6RS syntax is allowedr7rs
-- only R7RS syntax is allowed
The reader mode will automatically change if the reader encounters
#!r6rs
or #!r7rs
(the latter is not standard, but appears here and
there).
The default mode is rnrs
.
The port associated with the reader. You may manipulate the port (reading, setting the position, etc) as necessary.
Changes the reader mode to mode. See reader-mode
.
Returns #t
if the reader is in case folding mode. A case folding
reader will do string-foldcase
on identifiers.
This mode will automatically change if the reader encounters
#!fold-case
or #!no-fold-case
.
Sets the case folding mode of the reader.
Returns #t
if the reader is in tolerant mode. A tolerant reader
raises continuable warnings when it encounters syntax errors. If the
exception handler returns, then the reader ignores the error and goes
on parsing using some unspecified replacement tokens.
(with-exception-handler
(lambda (con)
(unless (warning? con)
(raise con)))
(lambda ()
(read-datum reader)))
Sets the tolerant mode of the reader.
Helper that raises a reader warning for the current position of the reader. Usually not needed, but can be useful for programs that do their own processing of tokens.
The current line number of the reader's port.
The current column number of the reader's port.
Returns #t
if obj is an annotation object; otherwise #f
.
The datum contained in the annotation. Datums inside the expression are also, in turn, annotatation objects.
The datum in the annotation, recursively stripped of all annotations.
The source object of the annotation, showing the datum's position in the reader.
Converts the source object to a &source-information condition.
Usually not needed but provided for the same type of programs that
would need reader-warning
.
Returns #t
if obj is a source condition; otherwise #f
.
Returns the filename field of the source condition
Returns the line number field of the source condition
Returns the column number field of the source condition
Attempts to guess the type of Scheme source code that lurks behind port. It does this by reading a few of the initial lexemes. The peculiarities are:
- If the first lexeme is a shebang (e.g.
#!/
) then the type isr6rs-program
. - If the port starts with a
library
form then the type isr6rs-library
. - If the port starts with an
import
form then the type isr6rs-program
. This should later be improved to detectr7rs-program
. - If the port starts with a
define-library
form then the type isr7rs-library
.
In other cases the type is unknown
.
(import (laesare writer))
Returns a new writer object for the given textual output port.
True if obj is a writer object.
Format a token and write it to the writer. The exact format depends on
the writer mode. Any data returned by get-token
can be written.
Returns the textual output port of the writer.
Returns the filename associated with the writer object.
Returns the mode associated with the writer. These are the same
symbols as reader-mode
.
Change the mode of the writer. The mode is also changed when an
#!r6rs
or #!r7rs
directive is written with put-token
.
Some R6RS syntax may slip through in the R7RS mode and some R7RS
syntax is not yet implemented. Datum comments, #;xyz
, do not
preserve the whitespace in the comment. Please report bugs in GitHub
issues.