-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathsource.ss
50 lines (37 loc) · 1.43 KB
/
source.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(export #t (for-syntax #t))
(import (for-syntax :std/stxutil
:std/misc/path
:std/misc/ports)
:std/sugar)
;;; Locations follow the Gambit convention: it's a vector of two values.
;;; The first value is either a string which is filename, or a list containing a symbol.
;;; The second value is a fixnum, either non-negative (+ (* 65536 column) line),
;;; or if the previous formula had overflows, negative file position.
(begin-syntax
(def (stx-source-file stx)
(alet (loc (stx-source stx))
(vector-ref loc 0)))
(def (stx-source-position stx)
(alet (loc (stx-source stx))
(vector-ref loc 1)))
(def (stx-source-directory stx)
(alet (file (stx-source-file stx))
(path-directory file)))
(def (stx-source-path stx . relpath)
(alet (dir (stx-source-directory stx))
(apply subpath dir relpath)))
(def (stx-source-content stx . relpath)
(alet (path (apply stx-source-path stx relpath))
(read-file-u8vector path))))
(defsyntax-call (this-source-location ctx)
(stx-source ctx))
(defsyntax-call (this-source-file ctx)
`',(stx-source-file ctx))
(defsyntax-call (this-source-position ctx)
(stx-source-position ctx))
(defsyntax-call (this-source-directory ctx)
(stx-source-directory ctx))
(defsyntax-call (this-source-path ctx relpath)
(stx-source-path ctx relpath))
(defsyntax-call (this-source-content ctx relpath)
(stx-source-content ctx relpath))