aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source')
-rw-r--r--stdlib/source/lux.lux35
1 files changed, 22 insertions, 13 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux
index fafecd7ad..a9bc53018 100644
--- a/stdlib/source/lux.lux
+++ b/stdlib/source/lux.lux
@@ -5684,6 +5684,14 @@
_
(fail "Wrong syntax for ^multi")))
+## TODO: Allow asking the compiler for the name of the definition
+## currently being defined. That name can then be fed into
+## 'wrong-syntax-error' for easier maintenance of the error-messages.
+(def: wrong-syntax-error
+ (-> Name Text)
+ (|>> name/encode
+ (text/compose "Wrong syntax for ")))
+
(macro: #export (name-of tokens)
{#.doc (doc "Given an identifier or a tag, gives back a 2 tuple with the prefix and name parts, both as Text."
(name-of #.doc)
@@ -5696,7 +5704,7 @@
([#Identifier] [#Tag])
_
- (fail "Wrong syntax for name-of")))
+ (fail (..wrong-syntax-error ["lux" "name-of"]))))
(do-template [<type> <even> <odd> <%> <=> <0> <2>]
[(def: #export (<even> n)
@@ -5752,7 +5760,7 @@
(fail (text/compose "Indexed-type does not exist: " (nat/encode idx)))))
_
- (fail "Wrong syntax for $")))
+ (fail (..wrong-syntax-error (name-of ..$)))))
(def: #export (is? reference sample)
{#.doc (doc "Tests whether the 2 values are identical (not just 'equal')."
@@ -5779,7 +5787,7 @@
branches)))
_
- (fail "Wrong syntax for ^@")))
+ (fail (..wrong-syntax-error (name-of ..^@)))))
(macro: #export (^|> tokens)
{#.doc (doc "Pipes the value being pattern-matched against prior to binding it to a variable."
@@ -5795,7 +5803,7 @@
branches)))
_
- (fail "Wrong syntax for ^|>")))
+ (fail (..wrong-syntax-error (name-of ..^|>)))))
(macro: #export (:assume tokens)
{#.doc (doc "Coerces the given expression to the type of whatever is expected."
@@ -5807,7 +5815,7 @@
(wrap (list (` ("lux coerce" (~ (type-to-code type)) (~ expr))))))
_
- (fail "Wrong syntax for :assume")))
+ (fail (..wrong-syntax-error (name-of ..:assume)))))
(macro: #export (undefined tokens)
{#.doc (doc "Meant to be used as a stand-in for functions with undefined implementations."
@@ -5821,7 +5829,7 @@
(return (list (` (error! "Undefined behavior."))))
_
- (fail "Wrong syntax for undefined")))
+ (fail (..wrong-syntax-error (name-of ..undefined)))))
(macro: #export (:of tokens)
{#.doc (doc "Generates the type corresponding to a given expression."
@@ -5848,7 +5856,7 @@
(..:of (~ g!temp)))))))
_
- (fail "Wrong syntax for :of")))
+ (fail (..wrong-syntax-error (name-of ..:of)))))
(def: (parse-complex-declaration tokens)
(-> (List Code) (Meta [[Text (List Text)] (List Code)]))
@@ -5929,7 +5937,8 @@
g!_ (gensym "_")
#let [rep-env (list/map (function (_ arg)
[arg (` ((~' ~) (~ (identifier$ ["" arg]))))])
- args)]]
+ args)]
+ this-module current-module-name]
(wrap (list (` (macro: (~+ (export export?))
((~ (identifier$ ["" name])) (~ g!tokens) (~ g!compiler))
(~ anns)
@@ -5941,7 +5950,7 @@
input-templates)))])
(~ g!_)
- (#.Left (~ (text$ (text/compose "Wrong syntax for " name))))
+ (#.Left (~ (text$ (..wrong-syntax-error [this-module name]))))
)))))
))
@@ -5957,7 +5966,7 @@
[compiler] #Right)
_
- (#Left "Wrong syntax for char")))
+ (#Left (..wrong-syntax-error (name-of ..char)))))
(def: #export (when test f)
(All [a] (-> Bit (-> a a) (-> a a)))
@@ -6003,7 +6012,7 @@
(wrap (list (..default default (pick-for-target target options))))
_
- (fail "Wrong syntax for 'for'"))))
+ (fail (..wrong-syntax-error (name-of ..for))))))
(do-template [<name> <type> <output>]
[(def: (<name> xy)
@@ -6059,7 +6068,7 @@
(~ labelled))))))
_
- (fail "Wrong syntax for ``")
+ (fail (..wrong-syntax-error (name-of ..``)))
))
(def: (name$ [module name])
@@ -6141,7 +6150,7 @@
(wrap (list pattern)))
_
- (fail "Wrong syntax for ^code")))
+ (fail (..wrong-syntax-error (name-of ..^code)))))
(def: #export (n/mod param subject)
(-> Nat Nat Nat)