aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2019-02-25 21:26:25 -0400
committerEduardo Julian2019-02-25 21:26:25 -0400
commit0b6be3e4022acfa4650f09f53b9aa5a5e7818cf7 (patch)
tree485026a2997f8b0f1c6daf3d7a4c1afa40efab80 /stdlib
parent54b6067f611ecb55a4aff7e0503285aa49db0365 (diff)
Can easily compose text, identifiers and tags inside templates.
Diffstat (limited to 'stdlib')
-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]
+ )