aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stdlib/source/lux/macro/template.lux31
1 files changed, 30 insertions, 1 deletions
diff --git a/stdlib/source/lux/macro/template.lux b/stdlib/source/lux/macro/template.lux
index b069736e5..7f5fe4ba6 100644
--- a/stdlib/source/lux/macro/template.lux
+++ b/stdlib/source/lux/macro/template.lux
@@ -4,11 +4,12 @@
["." monad (#+ do)]
["p" parser]]
[data
+ ["." text]
[collection
["." list ("#/." monad)]]]]
["." //
["." code]
- ["s" syntax (#+ syntax:)]])
+ ["s" syntax (#+ Syntax syntax:)]])
(syntax: #export (splice {parts (s.tuple (p.some s.any))})
(wrap parts))
@@ -24,3 +25,31 @@
(list (code.local-identifier name) (as-is identifier))))
list/join))]
(~ body)))))))
+
+(def: snippet
+ (Syntax Text)
+ ($_ p.either
+ s.text
+ s.local-identifier
+ s.local-tag))
+
+(def: part
+ (Syntax (List Text))
+ (s.tuple (p.many ..snippet)))
+
+(syntax: #export (text {simple ..part})
+ (wrap (list (|> simple (text.join-with "") code.text))))
+
+(do-template [<name> <simple> <complex>]
+ [(syntax: #export (<name> {simple ..part} {complex (p.maybe ..part)})
+ (case complex
+ #.None
+ (wrap (list (|> simple (text.join-with "") <simple>)))
+
+ (#.Some complex)
+ (wrap (list (<complex> [(text.join-with "" simple)
+ (text.join-with "" complex)])))))]
+
+ [identifier code.local-identifier code.identifier]
+ [tag code.local-tag code.tag]
+ )