This repository has been archived by the owner on May 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
JsonResult.elm
125 lines (90 loc) · 2.89 KB
/
JsonResult.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
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
module JsonResult exposing (BindingValue, Environment, JsonMatchResult, JsonRewriteResult, Location, Match, bindingDecoder, defaultLocation, environmentDecoder, locationDecoder, matchDecoder, matchResultDecoder, rewriteResultDecoder)
import Http exposing (..)
import Json.Decode exposing (..)
type alias Location =
{ offset : Int
, line : Int
, column : Int
}
defaultLocation : Location
defaultLocation =
{ offset = 0
, line = 0
, column = 0
}
type alias Range =
{ start : Location
, end : Location
}
type alias BindingValue =
{ variable : String
, value : String
, range : Range
}
type alias Environment =
List BindingValue
type alias Match =
{ range : Range
, environment : Environment
, matched : String
}
type alias JsonMatchResult =
{ matches : List Match
, source : String
, id : Int
}
type alias InPlaceSubstitution =
{ range : Range
, environment : Environment
, replacement_content : String
}
type alias JsonRewriteResult =
{ in_place_substitutions : List InPlaceSubstitution
, rewritten_source : String
, id : Int
}
locationDecoder : Json.Decode.Decoder Location
locationDecoder =
Json.Decode.map3 Location
(field "offset" Json.Decode.int)
(field "line" Json.Decode.int)
(field "column" Json.Decode.int)
rangeDecoder : Json.Decode.Decoder Range
rangeDecoder =
Json.Decode.map2 Range
(field "start" locationDecoder)
(field "end" locationDecoder)
bindingDecoder : Json.Decode.Decoder BindingValue
bindingDecoder =
Json.Decode.map3
BindingValue
(field "variable" Json.Decode.string)
(field "value" Json.Decode.string)
(field "range" rangeDecoder)
environmentDecoder : Json.Decode.Decoder Environment
environmentDecoder =
Json.Decode.list bindingDecoder
matchDecoder : Json.Decode.Decoder Match
matchDecoder =
Json.Decode.map3 Match
(field "range" rangeDecoder)
(field "environment" environmentDecoder)
(field "matched" Json.Decode.string)
matchResultDecoder : Json.Decode.Decoder JsonMatchResult
matchResultDecoder =
Json.Decode.map3 JsonMatchResult
(field "matches" (Json.Decode.list matchDecoder))
(field "source" Json.Decode.string)
(field "id" Json.Decode.int)
inPlaceSubstitutionDecoder : Json.Decode.Decoder InPlaceSubstitution
inPlaceSubstitutionDecoder =
Json.Decode.map3 InPlaceSubstitution
(field "range" rangeDecoder)
(field "environment" environmentDecoder)
(field "replacement_content" Json.Decode.string)
rewriteResultDecoder : Json.Decode.Decoder JsonRewriteResult
rewriteResultDecoder =
Json.Decode.map3 JsonRewriteResult
(field "in_place_substitutions" (Json.Decode.list inPlaceSubstitutionDecoder))
(field "rewritten_source" Json.Decode.string)
(field "id" Json.Decode.int)