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
51
52
53
|
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
(.require
[library
[lux (.except with)
[abstract
[equivalence (.only Equivalence)]]]])
(def .public equivalence
(Equivalence Location)
(implementation
(def (= reference subject)
(and (.text_=# (the .#module reference) (the .#module subject))
(.i64_=# (the .#line reference) (the .#line subject))
(.i64_=# (the .#column reference) (the .#column subject))))))
(def .public dummy
Location
[.#module ""
.#line 0
.#column 0])
(def .public here
(macro (_ tokens compiler)
(when 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 (`` ((.in_module# (,, (static .prelude)) wrong_syntax_error) (symbol ..here)))})))
(def .public (format it)
(-> Location Text)
(let [separator ","
[file line column] it]
(.text_composite# "@"
(`` ((.in_module# (,, (static .prelude)) .text#encoded) file)) separator
(`` ((.in_module# (,, (static .prelude)) .nat#encoded) line)) separator
(`` ((.in_module# (,, (static .prelude)) .nat#encoded) column)))))
(def \n
(.int_char# +10))
(def .public (with location error)
(-> Location Text Text)
(.text_composite# (..format location) \n
error))
|