-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathPackage.elm
62 lines (45 loc) · 1.21 KB
/
Package.elm
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
module Package (parse, Package, Module) where
import Json.Decode as Json exposing ((:=))
import List
parse : List (String, String) -> Package
parse input =
List.map decode input |> List.concat
decode : (String, String) -> Package
decode (name, json) =
case Json.decodeString (package name) json of
Ok v -> v
Err msg -> []
type alias Package = List Module
type alias Module =
{ packageName : String
, name : String
, values : Values
}
type alias Values =
{ aliases : List Vs
, types : List (String, List String)
, values : List Vs
}
type alias Vs =
{ name : String
, comment : String
, signature : String
}
package : String -> Json.Decoder Package
package packageName =
let name = "name" := Json.string
v =
Json.object3 Vs
("name" := Json.string)
("comment" := Json.string)
("type" := Json.string)
type' =
Json.object2 (,) name
("cases" := Json.list (Json.tuple2 always Json.string Json.value))
values =
Json.object3 Values
("aliases" := Json.list v)
("types" := Json.list type')
("values" := Json.list v)
in
Json.list (Json.object2 (Module packageName) name values)