Skip to content

Commit 1c3ca00

Browse files
committed
Rename and add comment
1 parent 18412bf commit 1c3ca00

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

source/Compiler.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ let index (value : int) (json : Json.t) =
176176
| `List _ -> Output.return `Null
177177
| _ -> Error (make_error ("[" ^ string_of_int value ^ "]") json)
178178

179-
let slice (start : int option) (end_ : int option) (json : Json.t) =
179+
let slice (start : int option) (finish : int option) (json : Json.t) =
180180
let start =
181181
match (json, start) with
182182
| `String s, Some start when start > String.length s -> String.length s
@@ -185,36 +185,36 @@ let slice (start : int option) (end_ : int option) (json : Json.t) =
185185
| `List l, Some start when start < 0 -> start + List.length l
186186
| (`String _ | `List _), Some start -> start
187187
| (`String _ | `List _), None -> 0
188-
| _ -> assert false
188+
| _ -> (* slice can't be parsed outside of List or String *) assert false
189189
in
190-
let end_ =
191-
match (json, end_) with
190+
let finish =
191+
match (json, finish) with
192192
| `String s, None -> String.length s
193193
| `String s, Some end_ when end_ > String.length s -> String.length s
194194
| `String s, Some end_ when end_ < 0 -> end_ + String.length s
195195
| `List l, None -> List.length l
196196
| `List l, Some end_ when end_ > List.length l -> List.length l
197197
| `List l, Some end_ when end_ < 0 -> end_ + List.length l
198198
| (`String _ | `List _), Some end_ -> end_
199-
| _ -> assert false
199+
| _ -> (* slice can't be parsed outside of List or String *) assert false
200200
in
201201
match json with
202-
| `String _s when end_ < start -> Output.return (`String "")
203-
| `String s -> Output.return (`String (String.sub s start (end_ - start)))
204-
| `List _l when end_ < start -> Output.return (`List [])
202+
| `String _s when finish < start -> Output.return (`String "")
203+
| `String s -> Output.return (`String (String.sub s start (finish - start)))
204+
| `List _l when finish < start -> Output.return (`List [])
205205
| `List l ->
206206
let sliced =
207207
List.fold_left
208208
(fun (acc, i) x ->
209-
if i >= start && i < end_ then (x :: acc, i + 1) else (acc, i + 1))
209+
if i >= start && i < finish then (x :: acc, i + 1) else (acc, i + 1))
210210
([], 0) l
211211
|> fst |> List.rev
212212
in
213213
Output.return (`List sliced)
214214
| _ ->
215215
Error
216216
(make_error
217-
("[" ^ string_of_int start ^ ":" ^ string_of_int end_ ^ "]")
217+
("[" ^ string_of_int start ^ ":" ^ string_of_int finish ^ "]")
218218
json)
219219

220220
let rec compile expression json : (Json.t list, string) result =
@@ -224,7 +224,7 @@ let rec compile expression json : (Json.t list, string) result =
224224
| Keys -> keys json
225225
| Key (key, opt) -> member key opt json
226226
| Index idx -> index idx json
227-
| Slice (start, end_) -> slice start end_ json
227+
| Slice (start, finish) -> slice start finish json
228228
| Head -> head json
229229
| Tail -> tail json
230230
| Length -> length json

0 commit comments

Comments
 (0)