8 Source Locations
(require unstable/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.
| ||
| ||
|
Examples: |
> (source-location? #f) |
#t |
> (source-location? #'here) |
#t |
> (source-location? (make-srcloc 'here 1 0 1 0)) |
#t |
> (source-location? (make-srcloc 'bad 1 #f 1 0)) |
#f |
> (source-location? (list 'here 1 0 1 0)) |
#t |
> (source-location? (list* 'bad 1 0 1 0 'tail)) |
#f |
> (source-location? (vector 'here 1 0 1 0)) |
#t |
> (source-location? (vector 'bad 0 0 0 0)) |
#f |
(check-source-location! name x) → void? |
name : symbol? |
x : any/c |
Examples: |
> (check-source-location! 'this-example #f) |
> (check-source-location! 'this-example #'here) |
> (check-source-location! 'this-example (make-srcloc 'here 1 0 1 0)) |
> (check-source-location! 'this-example (make-srcloc 'bad 1 #f 1 0)) |
this-example: expected a source location with line number |
and column number both numeric or both #f; got 1 and #f |
respectively: #(struct:srcloc bad 1 #f 1 0) |
> (check-source-location! 'this-example (list 'here 1 0 1 0)) |
> (check-source-location! 'this-example (list* 'bad 1 0 1 0 'tail)) |
this-example: expected a source location (a list of 5 |
elements); got an improper list: (bad 1 0 1 0 . tail) |
> (check-source-location! 'this-example (vector 'here 1 0 1 0)) |
> (check-source-location! 'this-example (vector 'bad 0 0 0 0)) |
this-example: expected a source location with a positive |
line number or #f (second element); got line number 0: |
#(bad 0 0 0 0) |
| ||
| ||
| ||
|
Examples: |
> (build-source-location) |
#(struct:srcloc #f #f #f #f #f) |
> (build-source-location-list) |
(#f #f #f #f #f) |
> (build-source-location-vector) |
#(#f #f #f #f #f) |
> (build-source-location-syntax) |
#<syntax ()> |
> (build-source-location #f) |
#(struct:srcloc #f #f #f #f #f) |
> (build-source-location-list #f) |
(#f #f #f #f #f) |
> (build-source-location-vector #f) |
#(#f #f #f #f #f) |
> (build-source-location-syntax #f) |
#<syntax ()> |
> (build-source-location (list 'here 1 2 3 4)) |
#(struct:srcloc here 1 2 3 4) |
> (build-source-location-list (make-srcloc 'here 1 2 3 4)) |
(here 1 2 3 4) |
> (build-source-location-vector (make-srcloc 'here 1 2 3 4)) |
#(here 1 2 3 4) |
> (build-source-location-syntax (make-srcloc 'here 1 2 3 4)) |
#<syntax:1:2 ()> |
> (build-source-location (list 'here 1 2 3 4) (vector 'here 5 6 7 8)) |
#(struct:srcloc here 1 2 3 12) |
> (build-source-location-list (make-srcloc 'here 1 2 3 4) (vector 'here 5 6 7 8)) |
(here 1 2 3 12) |
> (build-source-location-vector (make-srcloc 'here 1 2 3 4) (vector 'here 5 6 7 8)) |
#(here 1 2 3 12) |
> (build-source-location-syntax (make-srcloc 'here 1 2 3 4) (vector 'here 5 6 7 8)) |
#<syntax:1:2 ()> |
> (build-source-location (list 'here 1 2 3 4) (vector 'there 5 6 7 8)) |
#(struct:srcloc #f #f #f #f #f) |
> (build-source-location-list (make-srcloc 'here 1 2 3 4) (vector 'there 5 6 7 8)) |
(#f #f #f #f #f) |
> (build-source-location-vector (make-srcloc 'here 1 2 3 4) (vector 'there 5 6 7 8)) |
#(#f #f #f #f #f) |
> (build-source-location-syntax (make-srcloc 'here 1 2 3 4) (vector 'there 5 6 7 8)) |
#<syntax ()> |
| ||
|
Examples: |
> (source-location->string (make-srcloc 'here 1 2 3 4)) |
"here:1.2" |
> (source-location->string (make-srcloc 'here #f #f 3 4)) |
"here::3-7" |
> (source-location->string (make-srcloc 'here #f #f #f #f)) |
"here" |
> (source-location->string (make-srcloc #f 1 2 3 4)) |
":1.2" |
> (source-location->string (make-srcloc #f #f #f 3 4)) |
"::3-7" |
> (source-location->string (make-srcloc #f #f #f #f #f)) |
"" |
> (source-location->prefix (make-srcloc 'here 1 2 3 4)) |
"here:1.2: " |
> (source-location->prefix (make-srcloc 'here #f #f 3 4)) |
"here::3-7: " |
> (source-location->prefix (make-srcloc 'here #f #f #f #f)) |
"here: " |
> (source-location->prefix (make-srcloc #f 1 2 3 4)) |
":1.2: " |
> (source-location->prefix (make-srcloc #f #f #f 3 4)) |
"::3-7: " |
> (source-location->prefix (make-srcloc #f #f #f #f #f)) |
"" |