Source file async_reader.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
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
open! Core
open Async
type ('a, 'b) load = ?allow_includes:bool -> string -> (Sexp.t -> 'a) -> 'b Deferred.t
module Macro_loader = Macro.Loader (struct
module Monad = struct
type 'a t = 'a Deferred.t
let return = return
module Monad_infix = Deferred.Monad_infix
module List = struct
let iter xs ~f = Deferred.List.iter ~how:`Sequential xs ~f
let map xs ~f = Deferred.List.map ~how:`Sequential xs ~f
end
end
let load_sexps file =
match%map
Monitor.try_with ~run:`Schedule ~rest:`Log ~extract_exn:true (fun () ->
Reader.with_file file ~f:(fun t -> Pipe.to_list (Reader.read_sexps t)))
with
| Ok sexps -> sexps
| Error e -> raise (Macro.add_error_location file e)
;;
let load_annotated_sexps file =
match%map
Monitor.try_with ~run:`Schedule ~rest:`Log ~extract_exn:true (fun () ->
Reader.with_file file ~f:(fun t -> Pipe.to_list (Reader.read_annotated_sexps t)))
with
| Ok sexps -> sexps
| Error e -> raise (Macro.add_error_location file e)
;;
end)
let gen_load_sexp_exn (type a) ~allow_includes ~file ~(a_of_sexp : Sexp.t -> a) =
Macro_loader.load_sexp_conv ?allow_includes file a_of_sexp >>| ok_exn
;;
let load_sexp_exn ?allow_includes file a_of_sexp =
gen_load_sexp_exn ~allow_includes ~file ~a_of_sexp
;;
let[@warning "-16"] gen_load_sexp ?allow_includes ~file ~a_of_sexp =
Deferred.Or_error.try_with ~run:`Schedule ~rest:`Log ~extract_exn:true (fun () ->
gen_load_sexp_exn ~allow_includes ~file ~a_of_sexp)
;;
let load_sexp ?allow_includes file a_of_sexp =
gen_load_sexp ?allow_includes ~file ~a_of_sexp
;;
let[@warning "-16"] gen_load_sexps_exn
(type a)
?allow_includes
~file
~(a_of_sexp : Sexp.t -> a)
=
Macro_loader.load_sexps_conv ?allow_includes file a_of_sexp >>| ok_exn
;;
let load_sexps_exn ?allow_includes file a_of_sexp =
gen_load_sexps_exn ?allow_includes ~file ~a_of_sexp
;;
let[@warning "-16"] gen_load_sexps ?allow_includes ~file ~a_of_sexp =
Deferred.Or_error.try_with ~run:`Schedule ~rest:`Log ~extract_exn:true (fun () ->
gen_load_sexps_exn ?allow_includes ~file ~a_of_sexp)
;;
let load_sexps ?allow_includes file a_of_sexp =
gen_load_sexps ?allow_includes ~file ~a_of_sexp
;;
let included_files file =
Deferred.Or_error.try_with ~run:`Schedule ~rest:`Log (fun () ->
Macro_loader.included_files file)
;;