aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/macro/syntax/declaration.lux
blob: d817fa193406b8374ff751feff8abbedc7fde473 (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
(.using
 [library
  [lux "*"
   [abstract
    [equivalence {"+" Equivalence}]]
   [control
    ["<>" parser ("[1]#[0]" monad)
     ["<[0]>" code {"+" Parser}]]]
   [data
    ["[0]" product]
    ["[0]" text]
    [collection
     ["[0]" list ("[1]#[0]" functor)]]]
   [macro
    ["[0]" code]]]])

(type: .public Declaration
  (Record
   [#name Text
    #arguments (List Text)]))

(def: .public equivalence
  (Equivalence Declaration)
  ($_ product.equivalence
      text.equivalence
      (list.equivalence text.equivalence)
      ))

(def: .public parser
  (Parser Declaration)
  (<>.either (<>.and <code>.local_symbol
                     (<>#in (list)))
             (<code>.form (<>.and <code>.local_symbol
                                  (<>.some <code>.local_symbol)))))

(def: .public (format value)
  (-> Declaration Code)
  (let [g!name (code.local_symbol (the #name value))]
    (case (the #arguments value)
      {.#End}
      g!name
      
      arguments
      (` ((~ g!name) (~+ (list#each code.local_symbol arguments)))))))