This commit is contained in:
parent
824e4918c2
commit
1329c27e35
2 changed files with 664 additions and 15 deletions
|
|
@ -1,13 +1,7 @@
|
|||
(* rudimentary recfile parser
|
||||
https://www.gnu.org/software/recutils/manual/recutils.html#The-Rec-Format *)
|
||||
open Angstrom
|
||||
|
||||
(* rudimentary recfile parser
|
||||
https://www.gnu.org/software/recutils/manual/recutils.html#The-Rec-Format
|
||||
|
||||
field
|
||||
record
|
||||
comments
|
||||
record descriptors
|
||||
*)
|
||||
type field = {
|
||||
k: string;
|
||||
v: string;
|
||||
|
|
@ -17,8 +11,6 @@ type record = field list
|
|||
|
||||
let newline = char '\n'
|
||||
let is_newline = function '\n' -> true | _ -> false
|
||||
let blank = satisfy (function ' ' | '\t' -> true | _ -> false)
|
||||
let blanks = skip_many1 blank
|
||||
|
||||
let field_name =
|
||||
let first_char =
|
||||
|
|
@ -37,14 +29,23 @@ let field_name =
|
|||
let field_value = take_till is_newline <* newline
|
||||
|
||||
let field =
|
||||
let blank = satisfy (function ' ' | '\t' -> true | _ -> false) in
|
||||
let blanks = skip_many1 blank in
|
||||
lift3 (fun k () v -> { k; v }) field_name (char ':' *> blanks) field_value
|
||||
|
||||
let comment_line = char '#' *> take_till is_newline <* newline
|
||||
(*>>| fun _s -> ()*)
|
||||
let blank = newline *> return ()
|
||||
let comment = (char '#' *> take_till is_newline <* newline) *> return ()
|
||||
|
||||
let record =
|
||||
let sep =
|
||||
(* at least one blank line *)
|
||||
skip_many comment *> blank *> skip_many (comment <|> blank)
|
||||
in
|
||||
sep_by1 sep field
|
||||
|
||||
let recfile : record list t =
|
||||
skip_many (comment <|> blank) *> many record <* skip_many (comment <|> blank)
|
||||
|
||||
let line_sep = choice [ skip_many comment_line; (newline >>| fun _c -> ()) ]
|
||||
let record = sep_by1 line_sep field
|
||||
let recfile : record list t = many line_sep *> many record <* many line_sep
|
||||
let parse s = parse_string ~consume:All recfile s
|
||||
|
||||
let () =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue