aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/macro/template.lux
blob: 869c15518975b53cbd778c1c436c2e83f0b5db77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(.module:
  [library
   [lux {"-" [let]}
    ["$" documentation {"+" [documentation:]}]
    [data
     [text {"+" [\n]}
      ["%" format {"+" [format]}]]
     [collection
      ["." list]]]]]
  [\\library
   ["." /]])

(documentation: /.spliced
  ""
  [(spliced [a b c d])
   "=>"
   a
   b
   c
   d])

(documentation: /.amount
  ""
  [(amount [a b c d])
   "=>"
   4])

(documentation: /.with_locals
  "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"])

(documentation: /.text
  "A text literal made by concatenating pieces of code."
  [(text [#0 123 +456 +789.0 "abc" .def ..ghi])
   "=>"
   "#0123+456+789.0abcdefghi"])

(template [<a/an> <name> <short_example> <full_example>]
  [(documentation: <name>
     (format <a/an> " " (/.text [<name>]) " made by concatenating pieces of code."
             \n "The (optional) module part and the short part are specified independently.")
     [(<name> ["abc" .def ..ghi])
      "=>"
      <short_example>]
     [(<name> [.def] ["abc" .def ..ghi])
      "=>"
      <full_example>])]

  ["An" /.identifier abcdefghi  .abcdefghi]
  ["A"  /.tag       #abcdefghi #.abcdefghi]
  )

(documentation: /.let
  "Lexically-bound templates."
  [(let [(!square <root>)
         [(* <root> <root>)]]
     (def: (square root)
       (-> Nat Nat)
       (!square root)))])

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            "Utilities commonly used while templating."
            [..spliced
             ..amount
             ..with_locals
             ..text
             ..identifier
             ..tag
             ..let
             ($.default /.irregular_arguments)]
            []))