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 Logical = struct
type t =
| Next [@name "next"]
| Prev [@name "prev"]
[@@deriving yojson]
let to_string = function
| Next -> "next"
| Prev -> "prev"
;;
let of_string s =
match String.lowercase_ascii s |> String.trim with
| "next" -> Some Next
| "prev" -> Some Prev
| _ -> None
;;
end
module Spatial = struct
type t =
| Up [@name "up"]
| Down [@name "down"]
| Left [@name "left"]
| Right [@name "right"]
[@@deriving yojson]
let to_string = function
| Up -> "up"
| Down -> "down"
| Left -> "left"
| Right -> "right"
;;
let of_string s =
match String.lowercase_ascii s |> String.trim with
| "up" -> Some Up
| "down" -> Some Down
| "left" -> Some Left
| "right" -> Some Right
| _ -> None
;;
end
type t =
| Logical of Logical.t [@name "logical"]
| Spatial of Spatial.t [@name "spatial"]
[@@deriving yojson]
let to_string = function
| Logical d -> Logical.to_string d
| Spatial d -> Spatial.to_string d
;;
let of_string s =
match Logical.of_string s with
| Some d -> Some (Logical d)
| None ->
(match Spatial.of_string s with
| Some d -> Some (Spatial d)
| None -> None)
;;