aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/meta/location.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/library/lux/meta/location.lux49
1 files changed, 49 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/meta/location.lux b/stdlib/source/library/lux/meta/location.lux
new file mode 100644
index 000000000..ddc40b147
--- /dev/null
+++ b/stdlib/source/library/lux/meta/location.lux
@@ -0,0 +1,49 @@
+(.module:
+ [library
+ [lux #*
+ [abstract
+ [equivalence (#+ Equivalence)]]]])
+
+(implementation: #export equivalence
+ (Equivalence Location)
+
+ (def: (= reference subject)
+ (and ("lux text =" (get@ #.module reference) (get@ #.module subject))
+ ("lux i64 =" (get@ #.line reference) (get@ #.line subject))
+ ("lux i64 =" (get@ #.column reference) (get@ #.column subject)))))
+
+(def: #export dummy
+ Location
+ {#.module ""
+ #.line 0
+ #.column 0})
+
+(macro: #export (here tokens compiler)
+ (case tokens
+ #.Nil
+ (let [location (get@ #.location compiler)]
+ (#.Right [compiler
+ (list (` [(~ [..dummy (#.Text (get@ #.module location))])
+ (~ [..dummy (#.Nat (get@ #.line location))])
+ (~ [..dummy (#.Nat (get@ #.column location))])]))]))
+
+ _
+ (#.Left (`` (("lux in-module" (~~ (static .prelude_module)) wrong_syntax_error) (name_of ..here))))))
+
+(def: #export (format value)
+ (-> Location Text)
+ (let [separator ","
+ [file line column] value]
+ ($_ "lux text concat"
+ "@"
+ (`` (("lux in-module" (~~ (static .prelude_module)) .text\encode) file)) separator
+ (`` (("lux in-module" (~~ (static .prelude_module)) .nat\encode) line)) separator
+ (`` (("lux in-module" (~~ (static .prelude_module)) .nat\encode) column)))))
+
+(def: \n
+ ("lux i64 char" +10))
+
+(def: #export (with location error)
+ (-> Location Text Text)
+ ($_ "lux text concat" (..format location) \n
+ error))