forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_key.ml
53 lines (46 loc) · 1.04 KB
/
file_key.ml
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
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
type t =
| LibFile of string
| SourceFile of string
| JsonFile of string
| ResourceFile of string
| Builtins
let to_string = function
| LibFile x
| SourceFile x
| JsonFile x
| ResourceFile x ->
x
| Builtins -> "(global)"
let to_path = function
| LibFile x
| SourceFile x
| JsonFile x
| ResourceFile x ->
Ok x
| Builtins -> Error "File key refers to a builtin"
let compare =
let order_of_filename = function
| Builtins -> 1
| LibFile _ -> 2
| SourceFile _ -> 3
| JsonFile _ -> 3
| ResourceFile _ -> 4
in
fun a b ->
let k = order_of_filename a - order_of_filename b in
if k <> 0 then
k
else
String.compare (to_string a) (to_string b)
let compare_opt a b =
match (a, b) with
| (Some _, None) -> -1
| (None, Some _) -> 1
| (None, None) -> 0
| (Some a, Some b) -> compare a b