blob: 640dcee6ab8740d4aaf571facc85b7fb00eda306 (
plain)
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
|
(.using
[library
[lux (.except)
[abstract
[equivalence (.only Equivalence)]]]])
(implementation: .public equivalence
(Equivalence Location)
(def: (= reference subject)
(and ("lux text =" (the .#module reference) (the .#module subject))
("lux i64 =" (the .#line reference) (the .#line subject))
("lux i64 =" (the .#column reference) (the .#column subject)))))
(def: .public dummy
Location
[.#module ""
.#line 0
.#column 0])
(macro: .public (here tokens compiler)
(case tokens
{.#End}
(let [location (the .#location compiler)]
{.#Right [compiler
(list (` (.is .Location
[.#module (~ [..dummy {.#Text (the .#module location)}])
.#line (~ [..dummy {.#Nat (the .#line location)}])
.#column (~ [..dummy {.#Nat (the .#column location)}])])))]})
_
{.#Left (`` (("lux in-module" (~~ (static .prelude_module)) wrong_syntax_error) (symbol ..here)))}))
(def: .public (format it)
(-> Location Text)
(let [separator ","
[file line column] it]
(all "lux text concat"
"@"
(`` (("lux in-module" (~~ (static .prelude_module)) .text#encoded) file)) separator
(`` (("lux in-module" (~~ (static .prelude_module)) .nat#encoded) line)) separator
(`` (("lux in-module" (~~ (static .prelude_module)) .nat#encoded) column)))))
(def: \n
("lux i64 char" +10))
(def: .public (with location error)
(-> Location Text Text)
(all "lux text concat" (..format location) \n
error))
|