Version: 5.1.1
9 Source Locations
There are two libraries in this collection for dealing with source locations;
one for manipulating representations of them, and the other for quoting the
location of a particular piece of source code.
9.1 Representations
This module defines utilities for manipulating representations of source
locations, including both srcloc structures and all the values accepted
by datum->syntax’s third argument: syntax objects, lists, vectors, and
#f.
These functions recognize valid source location representations. The first,
source-location?, recognizes
srcloc structures, syntax
objects, lists, and vectors with appropriate structure, as well as
#f.
The latter predicates recognize only valid lists and vectors, respectively.
This procedure checks that its input is a valid source location. If it is, the
procedure returns
(void). If it is not,
check-source-location! raises a detailed error message in terms of
name and the problem with
x.
These procedures combine multiple (zero or more) source locations, merging
locations within the same source and reporting
#f for locations that
span sources. They also convert the result to the desired representation:
srcloc, list, vector, or syntax object, respectively.
This predicate reports whether a given source location contains more information
than simply #f.
These accessors extract the fields of a source location.
This accessor produces the end position of a source location (the sum of its
position and span, if both are numbers) or #f.
Produces a modified version of loc, replacing its fields with
source, line, column, position, and/or
span, if given.
These procedures convert source locations to strings for use in error messages.
The first produces a string describing the source location; the second appends
": " to the string if it is non-empty.
9.2 Quoting
This module defines macros that evaluate to various aspects of their own source
location.
Note: The examples below illustrate the use of these macros and the
representation of their output. However, due to the mechanism by which they are
generated, each example is considered a single character and thus does not have
realistic line, column, and character positions.
Furthermore, the examples illustrate the use of source location quoting inside
macros, and the difference between quoting the source location of the macro
definition itself and quoting the source location of the macro’s arguments.
Quotes the source location of
form as a
srcloc
structure, using the location of the whole
(quote-srcloc)
expression if no
expr is given. Uses relative directories
for paths found within the collections tree, the user’s collections directory,
or the PLaneT cache.
Quote various fields of the source location of form, or of
the whole macro application if no form is given.
Examples: |
| '(eval 2 0 2 1) | | > (not-here) | '(eval 3 0 3 1) | > (not-here) | '(eval 3 0 3 1) | | > (here) | '(eval 7 0 7 1) | > (here) | '(eval 8 0 8 1) |
|
These forms use relative names for modules found in the collections or PLaneT
cache; their results are suitable for printing, but not for accessing libraries
programmatically, such as via dynamic-require.