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
module type S = sig
val of_string : string -> (Rpmfile.metadata, string) result
val of_channel : in_channel -> (Rpmfile.metadata, string) result
val of_file : string -> (Rpmfile.metadata, string) result
end
module P (S : Rpmfile.Selector.S) = struct
open Rpmfile
open Parsers
let metadata_parser =
let open Angstrom in
let* lead = lead_parser in
let* signature = header_parser ~selector:S.select_signature_tag in
let* = header_parser ~selector:S.select_header_tag in
return { lead; signature; header }
end
module Make (Selector : Rpmfile.Selector.S) : S = struct
let of_string =
let module P = P (Selector) in
Angstrom.(parse_string ~consume:Consume.Prefix) P.metadata_parser
let of_channel ic =
let module P = P (Selector) in
Angstrom_unix.parse P.metadata_parser ic |> snd
let of_file path = In_channel.with_open_bin path of_channel
end