Skip to content
Snippets Groups Projects
Commit b371f1a0 authored by hondet's avatar hondet
Browse files

parsing with angstrom exclusively

parent 52cba94e
No related branches found
No related tags found
No related merge requests found
......@@ -5,3 +5,6 @@ _build/default/chainprops.exe: chainprops.ml
psnj-chainprops: _build/default/chainprops.exe
@cp -f _build/default/chainprops.exe psnj-chainprops
man: psnj-chainprops
@./psnj-chainprops --help=groff > psnj-chainprops.1
(** Parse dependencies file *)
module Deps = struct
module Deps : sig
type t
val pp : Format.formatter -> t -> unit
val parse : in_channel -> t list
end = struct
open Angstrom
type t = string * string list
......@@ -10,27 +16,26 @@ module Deps = struct
let blank1 = satisfy is_space *> blank
let eol = string "\n\r" <|> string "\n"
let colon = blank *> char ':' <* blank
let word = take_till is_space
let word = take_till (fun c -> is_space c || c = '\n' || c = '\r')
let line = both (word <* colon) (sep_by blank1 word)
let deps = sep_by (many1 eol) line
let pp ppf ((s, deps) : t) =
let open Format in
let pp_sep = pp_print_space in
fprintf ppf "@[<h>%s:@ %a@]" s (pp_print_list ~pp_sep pp_print_string) deps
let parse (ic : in_channel) : t list =
let deps = ref [] in
try
while true do
match parse_string ~consume:Prefix line (input_line ic) with
| Ok v -> deps := v :: !deps
| Error msg -> failwith msg
done;
assert false (* End of line should be reached*)
with End_of_file -> List.rev !deps
let file = really_input_string ic (in_channel_length ic) in
match parse_string ~consume:Prefix deps file with
| Ok v -> v
| Error msg -> failwith msg
end
open Cmdliner
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment