aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source')
-rw-r--r--stdlib/source/lux/macro.lux27
-rw-r--r--stdlib/source/lux/macro/syntax.lux9
2 files changed, 23 insertions, 13 deletions
diff --git a/stdlib/source/lux/macro.lux b/stdlib/source/lux/macro.lux
index ead5b366e..a2e17e2d9 100644
--- a/stdlib/source/lux/macro.lux
+++ b/stdlib/source/lux/macro.lux
@@ -384,6 +384,11 @@
_
(fail (text/compose "Code is not a local identifier: " (code.to-text ast)))))
+(def: #export wrong-syntax-error
+ (-> Name Text)
+ (|>> name/encode
+ (text/compose "Wrong syntax for ")))
+
(macro: #export (with-gensyms tokens)
{#.doc (doc "Creates new identifiers and offers them to the body expression."
(syntax: #export (synchronized lock body)
@@ -406,7 +411,7 @@
(~ body))))))
_
- (fail "Wrong syntax for with-gensyms")))
+ (fail (..wrong-syntax-error (name-of ..with-gensyms)))))
(def: #export (expand-1 token)
{#.doc "Works just like expand, except that it ensures that the output is a single Code token."}
@@ -692,7 +697,7 @@
(function (_ compiler)
(#error.Success [compiler (get@ #.type-context compiler)])))
-(do-template [<macro> <func> <desc>]
+(do-template [<macro> <func>]
[(macro: #export (<macro> tokens)
{#.doc (doc "Performs a macro-expansion and logs the resulting code."
"You can either use the resulting code, or omit them."
@@ -716,7 +721,7 @@
(do Monad<Meta>
[cursor ..cursor
output (<func> token)
- #let [_ (log! ($_ text/compose <desc> " @ " (.cursor-description cursor)))
+ #let [_ (log! ($_ text/compose (name/encode (name-of <macro>)) " @ " (.cursor-description cursor)))
_ (list/map (|>> code.to-text log!)
output)
_ (log! "")]]
@@ -725,9 +730,17 @@
output)))
#.None
- (fail ($_ text/compose "Wrong syntax for " <desc> "."))))]
+ (fail (..wrong-syntax-error (name-of <macro>)))))]
- [log-expand! expand "log-expand!"]
- [log-expand-all! expand-all "log-expand-all!"]
- [log-expand-once! expand-once "log-expand-once!"]
+ [log-expand! expand]
+ [log-expand-all! expand-all]
+ [log-expand-once! expand-once]
)
+
+(macro: #export (multi tokens)
+ (case tokens
+ (^ (list [_ (#.Tuple parts)]))
+ (:: Monad<Meta> wrap parts)
+
+ _
+ (fail (..wrong-syntax-error (name-of ..multi)))))
diff --git a/stdlib/source/lux/macro/syntax.lux b/stdlib/source/lux/macro/syntax.lux
index 02c3ad1ae..cb235043f 100644
--- a/stdlib/source/lux/macro/syntax.lux
+++ b/stdlib/source/lux/macro/syntax.lux
@@ -195,10 +195,6 @@
(wrap [real value]))))
## [Syntax]
-(def: (quote name)
- (-> Text Text)
- ($_ text/compose "'" name "'"))
-
(macro: #export (syntax: tokens)
{#.doc (doc "A more advanced way to define macros than 'macro:'."
"The inputs to the macro can be parsed in complex ways through the use of syntax parsers."
@@ -253,8 +249,9 @@
_
(//.fail "Syntax pattern expects records or identifiers."))))
args)
+ this-module //.current-module-name
#let [g!state (code.identifier ["" "*compiler*"])
- error-msg (code.text ($_ text/compose "Wrong syntax for " (quote name) ": "))
+ error-msg (code.text (//.wrong-syntax-error [this-module name]))
export-ast (: (List Code)
(if exported?
(list (' #export))
@@ -275,4 +272,4 @@
(~ body)))))))))))))
_
- (//.fail (text/compose "Wrong syntax for " (quote "syntax:"))))))
+ (//.fail (//.wrong-syntax-error (name-of ..syntax:))))))