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

(type: .public Declaration
  {#.doc (example "A declaration for either a constant or a function.")}
  {#name Text
   #arguments (List Text)})

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

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

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