aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/artifact/snapshot.lux
blob: df36e1d0d5d32bd9beded6ae126c3800d8be819b (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
(.require
 [library
  [lux (.except Type)
   [abstract
    [equivalence (.only Equivalence)]
    [monad (.only do)]]
   [control
    ["<>" parser]]
   [data
    ["[0]" sum]
    ["[0]" text
     ["<[1]>" \\parser]]
    [format
     ["[0]" xml (.only XML)
      ["<[1]>" \\parser (.only Parser)]]]]]]
 ["[0]" /
  ["[1][0]" stamp (.only Stamp)]])

(type .public Snapshot
  (Variant
   {#Local}
   {#Remote Stamp}))

(def any_equivalence
  (Equivalence Any)
  (implementation
   (def (= _ _)
     true)))

(def .public equivalence
  (Equivalence Snapshot)
  (all sum.equivalence
       ..any_equivalence
       /stamp.equivalence
       ))

(with_template [<definition> <tag>]
  [(def <definition> xml.Tag ["" <tag>])]

  [<local_copy> "localCopy"]
  [<snapshot> "snapshot"]
  )

(def local_copy_value
  "true")

(def local_copy_format
  XML
  {xml.#Node <local_copy>
             xml.attributes
             (list {xml.#Text ..local_copy_value})})

(def local_copy_parser
  (Parser Any)
  (<| (<xml>.node ..<local_copy>)
      (<text>.then (<text>.this ..local_copy_value))
      <xml>.text))

(def .public (format snapshot)
  (-> Snapshot XML)
  (<| {xml.#Node ..<snapshot> xml.attributes}
      (when snapshot
        {#Local}
        (list ..local_copy_format)
        
        {#Remote stamp}
        (/stamp.format stamp))))

(def .public parser
  (Parser Snapshot)
  (<| (<xml>.node <snapshot>)
      (<>.or ..local_copy_parser
             /stamp.parser)))