blob: d1294987be23fb483aad9c5a3e47e0ac29aa1bd6 (
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
(.using
[library
[lux "*"
[abstract
[monad {"+" do}]]
[control
[pipe {"+" case>}]
["[0]" maybe ("[1]#[0]" functor)]
["[0]" try {"+" Try}]
["[0]" exception]
["<>" parser
["<[0]>" xml {"+" Parser}]]]
[data
["[0]" name]
["[0]" text]
[format
["_" xml {"+" Tag XML}]]
[collection
["[0]" list ("[1]#[0]" monoid functor mix)]
["[0]" set]
["[0]" dictionary]]]
[world
["[0]" file]]]]
["[0]" // "_"
["/" profile]
["[1][0]" dependency {"+" Dependency}]
[repository
[remote {"+" Address}]]
["[1][0]" artifact {"+" Artifact}
["[1]/[0]" type]]])
... https://maven.apache.org/pom.html
(def: project_tag "project")
(def: dependency_tag "dependency")
(def: dependencies_tag "dependencies")
(def: repositories_tag "repositories")
(def: repository_tag "repository")
(def: url_tag "url")
(def: group_tag "groupId")
(def: artifact_tag "artifactId")
(def: version_tag "version")
(def: .public file
file.Path
"pom.xml")
(def: version
XML
{_.#Node ["" "modelVersion"] _.attributes
(list {_.#Text "4.0.0"})})
(def: (property tag value)
(-> Text Text XML)
{_.#Node ["" tag]
_.attributes
(list {_.#Text value})})
(def: (artifact value)
(-> Artifact (List XML))
(list (..property ..group_tag (value@ //artifact.#group value))
(..property ..artifact_tag (value@ //artifact.#name value))
(..property ..version_tag (value@ //artifact.#version value))))
(def: distribution
(-> /.Distribution XML)
(|>> (case> {/.#Repo} "repo"
{/.#Manual} "manual")
(..property "distribution")))
(def: (license [name url distribution])
(-> /.License XML)
(|> (list (..property "name" name)
(..property ..url_tag url)
(..distribution distribution))
{_.#Node ["" "license"] _.attributes}))
(def: repository
(-> Address XML)
(|>> (..property ..url_tag)
list
{_.#Node ["" ..repository_tag] _.attributes}))
(def: (dependency value)
(-> Dependency XML)
{_.#Node ["" ..dependency_tag]
_.attributes
(list#composite (..artifact (value@ //dependency.#artifact value))
(list (..property "type" (value@ //dependency.#type value))))})
(def: (group tag)
(-> Text (-> (List XML) XML))
(|>> {_.#Node ["" tag] _.attributes}))
(comment
(def: scm
(-> /.SCM XML)
(|>> (..property ..url_tag)
list
{_.#Node ["" "scm"] _.attributes}))
(def: (organization [name url])
(-> /.Organization XML)
(|> (list (..property "name" name)
(..property ..url_tag url))
{_.#Node ["" "organization"] _.attributes}))
(def: (developer_organization [name url])
(-> /.Organization (List XML))
(list (..property "organization" name)
(..property "organizationUrl" url)))
(def: (developer' [name email organization])
(-> /.Developer (List XML))
(list& (..property "name" name)
(..property "email" email)
(|> organization (maybe#each ..developer_organization) (maybe.else (list)))))
(template [<name> <type> <tag>]
[(def: <name>
(-> <type> XML)
(|>> ..developer' {_.#Node ["" <tag>] _.attributes}))]
[developer /.Developer "developer"]
[contributor /.Contributor "contributor"]
)
(def: (info value)
(-> /.Info (List XML))
($_ list#composite
(|> value (value@ /.#url) (maybe#each (..property ..url_tag)) maybe.list)
(|> value (value@ /.#description) (maybe#each (..property "description")) maybe.list)
(|> value (value@ /.#licenses) (list#each ..license) (..group "licenses") list)
(|> value (value@ /.#scm) (maybe#each ..scm) maybe.list)
(|> value (value@ /.#organization) (maybe#each ..organization) maybe.list)
(|> value (value@ /.#developers) (list#each ..developer) (..group "developers") list)
(|> value (value@ /.#contributors) (list#each ..contributor) (..group "contributors") list)
))
)
(def: .public (write value)
(-> /.Profile (Try XML))
(case (value@ /.#identity value)
{.#Some identity}
{try.#Success
{_.#Node ["" ..project_tag] _.attributes
($_ list#composite
(list ..version)
(..artifact identity)
(|> value (value@ /.#repositories) set.list (list#each ..repository) (..group "repositories") list)
(|> value (value@ /.#dependencies) set.list (list#each ..dependency) (..group ..dependencies_tag) list)
)}}
_
(exception.except /.no_identity [])))
(def: property_parser
(Parser [Tag Text])
(do [! <>.monad]
[tag <xml>.tag]
(<| (<xml>.node tag)
(# ! each (|>> [tag]))
<xml>.text)))
(def: (dependency_parser own_version parent_version)
(-> Text Text (Parser Dependency))
(do [! <>.monad]
[properties (# ! each (dictionary.of_list name.hash)
(<| (<xml>.node ["" ..dependency_tag])
(<>.some ..property_parser)))]
(<| <>.lifted
try.of_maybe
(do maybe.monad
[group (dictionary.value ["" ..group_tag] properties)
artifact (dictionary.value ["" ..artifact_tag] properties)]
(in [//dependency.#artifact [//artifact.#group group
//artifact.#name artifact
//artifact.#version (|> properties
(dictionary.value ["" ..version_tag])
(maybe.else "")
(text.replaced "${project.version}" own_version)
(text.replaced "${project.parent.version}" parent_version))]
//dependency.#type (|> properties
(dictionary.value ["" "type"])
(maybe.else //artifact/type.jvm_library))])))))
(def: (dependencies_parser own_version parent_version)
(-> Text Text (Parser (List Dependency)))
(<| (<xml>.node ["" ..dependencies_tag])
(<>.some (..dependency_parser own_version parent_version))))
(def: repository_parser
(Parser Address)
(<| (<xml>.node ["" ..repository_tag])
(<xml>.node ["" ..url_tag])
<xml>.text))
(def: repositories_parser
(Parser (List Address))
(<| (<xml>.node ["" ..repositories_tag])
(<>.some ..repository_parser)))
(def: own_version
(Parser Text)
(<| (<xml>.node ["" ..version_tag])
<xml>.text))
(def: parent_version
(Parser Text)
(<| (<xml>.node ["" "parent"])
..own_version))
(def: .public parser
(Parser /.Profile)
(do [! <>.monad]
[own_version (<>.else "" (<xml>.somewhere ..own_version))
parent_version (<>.else "" (<xml>.somewhere ..parent_version))]
(<| (<xml>.node ["" ..project_tag])
(do !
[dependencies (|> (..dependencies_parser own_version parent_version)
<xml>.somewhere
(<>.else (list)))
repositories (|> ..repositories_parser
<xml>.somewhere
(<>.else (list)))
_ (<>.some <xml>.any)]
(in (|> (# /.monoid identity)
(revised@ /.#dependencies (function (_ empty)
(list#mix set.has empty dependencies)))
(revised@ /.#repositories (function (_ empty)
(list#mix set.has empty repositories)))))))))
|