diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/macro/template.lux | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/stdlib/source/library/lux/macro/template.lux b/stdlib/source/library/lux/macro/template.lux index 2f72ef96a..b5a364ffd 100644 --- a/stdlib/source/library/lux/macro/template.lux +++ b/stdlib/source/library/lux/macro/template.lux @@ -1,4 +1,5 @@ (.module: + {#.doc "Utilities commonly used while templating."} [library [lux (#- let local) ["." meta] @@ -34,6 +35,12 @@ (syntax: .public (with_locals [locals (<code>.tuple (<>.some <code>.local_identifier)) body <code>.any]) + {#.doc (example "Creates names for local bindings aliased by the names you choose." + (with_locals [my_var] + (let [my_var 123] + (..text [my_var]))) + "=>" + "__gensym__my_var506")} (do {! meta.monad} [g!locals (|> locals (list\map //.identifier) @@ -80,21 +87,38 @@ (<code>.tuple (<>.many (..snippet module_side?)))) (syntax: .public (text [simple (..part false)]) + {#.doc (example "A text literal made by concatenating pieces of code." + (text [#0 123 +456 +789.0 "abc" .def ..ghi]) + "=>" + "#0123+456+789.0abcdefghi")} (in (list (|> simple (text.join_with "") code.text)))) -(template [<name> <simple> <complex>] - [(syntax: .public (<name> [name (<>.or (<>.and (..part true) (..part false)) - (..part false))]) - (case name - (#.Left [simple complex]) - (in (list (<complex> [(text.join_with "" simple) - (text.join_with "" complex)]))) - - (#.Right simple) - (in (list (|> simple (text.join_with "") <simple>)))))] - - [identifier code.local_identifier code.identifier] - [tag code.local_tag code.tag] +(template [<a/an> <name> <simple> <complex> <short_example> <full_example>] + [(`` (syntax: .public (<name> [name (<>.or (<>.and (..part true) (..part false)) + (..part false))]) + {#.doc (example (~~ (..text [<a/an> " " <name> " made by concatenating pieces of code."])) + "The (optional) module part and the short part are specified independently." + (<name> ["abc" .def ..ghi]) + "=>" + <short_example> + "--------------" + (<name> [.def] ["abc" .def ..ghi]) + "=>" + <full_example>)} + (case name + (#.Left [simple complex]) + (in (list (<complex> [(text.join_with "" simple) + (text.join_with "" complex)]))) + + (#.Right simple) + (in (list (|> simple (text.join_with "") <simple>))))))] + + ["An" identifier code.local_identifier code.identifier + abcdefghi + .abcdefghi] + ["A" tag code.local_tag code.tag + #abcdefghi + #.abcdefghi] ) (type: Environment @@ -104,7 +128,7 @@ (-> Environment Code Code) (case template [_ (#.Identifier "" name)] - (case (dictionary.get name env) + (case (dictionary.value name env) (#.Some substitute) substitute @@ -162,6 +186,12 @@ (syntax: .public (let [locals (<code>.tuple (<>.some ..local)) body <code>.any]) + {#.doc (example "Lexically-bound templates." + (let [(!square <root>) + [(nat.* <root> <root>)]] + (def: (square root) + (-> Nat Nat) + (!square root))))} (do meta.monad [here_name meta.current_module_name expression? (: (Meta Bit) |