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

(type: #export Declaration
  {#name Text
   #arguments (List Text)})

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

(def: #export parser
  {#.doc (doc "A parser for declaration syntax."
              "Such as:"
              quux
              (foo bar baz))}
  (Parser Declaration)
  (<>.either (<>.and <code>.local_identifier
                     (<>\wrap (list)))
             (<code>.form (<>.and <code>.local_identifier
                                  (<>.some <code>.local_identifier)))))

(def: #export (format value)
  (-> Declaration Code)
  (let [g!name (code.local_identifier (get@ #name value))]
    (case (get@ #arguments value)
      #.Nil
      g!name
      
      arguments
      (` ((~ g!name) (~+ (list\map code.local_identifier arguments)))))))