blob: 9fdc2d84def061acf2e7f765cb62de7b4214e0dc (
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
(.module:
[library
[lux #*
[abstract
[equivalence (#+ Equivalence)]
[monad (#+ do)]]
[control
["." exception (#+ exception:)]
["<>" parser
["<.>" xml (#+ Parser)]
["<.>" text]]]
[data
["." product]
["." maybe]
["." text
["%" format]]
[format
["." xml (#+ XML)]]
[collection
["." list ("#\." functor)]]]
[math
[number
["n" nat]]]
["." time (#+ Time)
["." date (#+ Date)]
["." year]
["." month]]]]
["." // #_
["#." time]
["#." snapshot (#+ Snapshot)
["#/." version (#+ Version)]]])
(type: #export Versioning
{#snapshot Snapshot
#last_updated //time.Time
#versions (List Version)})
(def: #export init
{#snapshot #//snapshot.Local
#last_updated //time.epoch
#versions (list)})
(def: #export equivalence
(Equivalence Versioning)
($_ product.equivalence
//snapshot.equivalence
//time.equivalence
(list.equivalence //snapshot/version.equivalence)
))
(template [<definition> <tag>]
[(def: <definition> xml.Tag ["" <tag>])]
[<last_updated> "lastUpdated"]
[<snapshot_versions> "snapshotVersions"]
[<versioning> "versioning"]
)
(def: format_last_updated
(-> //time.Time XML)
(|>> //time.format #xml.Text list (#xml.Node ..<last_updated> xml.attributes)))
(def: #export (format (^slots [#snapshot #last_updated #versions]))
(-> Versioning XML)
(<| (#xml.Node ..<versioning> xml.attributes)
(list (//snapshot.format snapshot)
(..format_last_updated last_updated)
(|> versions
(list\map //snapshot/version.format)
(#xml.Node ..<snapshot_versions> xml.attributes)))))
(def: (text tag)
(-> xml.Tag (Parser Text))
(<| (<xml>.node tag)
<xml>.text))
(def: last_updated_parser
(Parser //time.Time)
(<| (<text>.embed //time.parser)
(..text ..<last_updated>)))
(def: #export parser
(Parser Versioning)
(<| (<xml>.node ..<versioning>)
($_ <>.and
(<>.default #//snapshot.Local (<xml>.somewhere //snapshot.parser))
(<>.default //time.epoch (<xml>.somewhere ..last_updated_parser))
(<| (<>.default (list))
<xml>.somewhere
(<xml>.node ..<snapshot_versions>)
(<>.some //snapshot/version.parser))
)))
|