From 0b6be3e4022acfa4650f09f53b9aa5a5e7818cf7 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 25 Feb 2019 21:26:25 -0400 Subject: Can easily compose text, identifiers and tags inside templates. --- stdlib/source/lux/macro/template.lux | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'stdlib') 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 [ ] + [(syntax: #export ( {simple ..part} {complex (p.maybe ..part)}) + (case complex + #.None + (wrap (list (|> simple (text.join-with "") ))) + + (#.Some complex) + (wrap (list ( [(text.join-with "" simple) + (text.join-with "" complex)])))))] + + [identifier code.local-identifier code.identifier] + [tag code.local-tag code.tag] + ) -- cgit v1.2.3