8 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.
8.1 Representations
(require syntax/srcloc) |
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.
procedure
(source-location? x) → boolean?
x : any/c
procedure
x : any/c
procedure
x : any/c
Examples: | ||||||||||||||||
|
procedure
(check-source-location! name x) → void?
name : symbol? x : any/c
Examples: | ||||||||||||||||||||||||||
|
procedure
(build-source-location loc ...) → srcloc?
loc : source-location?
procedure
(build-source-location-list loc ...) → source-location-list?
loc : source-location?
procedure
(build-source-location-vector loc ...) → source-location-vector?
loc : source-location?
procedure
(build-source-location-syntax loc ...) → syntax?
loc : source-location?
Examples: | ||||||||||||||||||||||||||||||||||||||||
|
procedure
(source-location-known? loc) → boolean?
loc : source-location?
Examples: | ||||||||||||||
|
procedure
(source-location-source loc) → any/c
loc : source-location?
procedure
(source-location-line loc)
→ (or/c orexact-positive-integer? #f) loc : source-location?
procedure
(source-location-column loc)
→ (or/c exact-nonnegative-integer? #f) loc : source-location?
procedure
(source-location-position loc)
→ (or/c exact-positive-integer? #f) loc : source-location?
procedure
(source-location-span loc)
→ (or/c exact-nonnegative-integer? #f) loc : source-location?
Examples: | ||||||||||
|
procedure
(source-location-end loc)
→ (or/c exact-nonnegative-integer? #f) loc : source-location?
Examples: | ||||||||
|
procedure
(update-source-location loc #:source source #:line line #:column column #:position position #:span span) → source-location? loc : source-location? source : any/c line : (or/c exact-nonnegative-integer? #f) column : (or/c exact-positive-integer? #f) position : (or/c exact-nonnegative-integer? #f) span : (or/c exact-positive-integer? #f)
Examples: | ||||||
|
procedure
(source-location->string loc) → string?
loc : source-location?
procedure
(source-location->prefix loc) → string?
loc : source-location?
Examples: | ||||||||||||||||||||||||
|
8.2 Quoting
(require syntax/location) |
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.
syntax
(quote-srcloc form) (quote-srcloc form #:module-source expr)
Examples: | ||||||||||||||||
|
syntax
(quote-source-file form)
syntax
(quote-line-number form)
syntax
(quote-column-number form)
syntax
(quote-character-position form)
syntax
(quote-character-span form)
Examples: | |||||||||||||||||||||||||||||||||
|
syntax
(quote-srcloc-string form)
syntax
(quote-srcloc-prefix form)
Examples: | ||||||||||||||||||||||||
|
syntax
(quote-module-name submod-path-element ...)
Returns a path, symbol, list, or 'top-level, where 'top-level is produced when used outside of a module. A list corresponds to a submodule in the same format as the result of variable-reference->module-name. Any given submod-path-elements (as in a submod form) are added to form a result submodule path.
To produce a name suitable for use in printed messages, apply path->relative-string/library when the result is a path.
Examples: | |||||||||||||||||||||||||||||||||||||||||||||
|
syntax
(quote-module-path submod-path-element ...)
Builds the result using quote, a path, submod, or 'top-level, where 'top-level is produced when used outside of a module. Any given submod-path-elements (as in a submod form) are added to form a result submodule path.
Examples: | |||||||||||||||||||||||||||||||||||||||||||||
|