JJ: Description from the destination commit:
setup_cmd: add --output-pubkey JJ: Description from source commit: use cmdliner
This commit is contained in:
parent
eddc8127a1
commit
2220f66db7
6 changed files with 186 additions and 131 deletions
51
tools/recfile_parser.ml
Normal file
51
tools/recfile_parser.ml
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
(* very rudimentary recfile parser
|
||||
https://www.gnu.org/software/recutils/manual/recutils.html#The-Rec-Format *)
|
||||
|
||||
open Angstrom
|
||||
|
||||
type field = {
|
||||
k: string;
|
||||
v: string;
|
||||
}
|
||||
|
||||
type record = field list
|
||||
|
||||
let newline = char '\n'
|
||||
let is_newline = function '\n' -> true | _ -> false
|
||||
|
||||
let field_name =
|
||||
let first_char =
|
||||
satisfy (function 'a' .. 'z' | 'A' .. 'Z' | '%' -> true | _ -> false)
|
||||
in
|
||||
let subsequent_char =
|
||||
satisfy (function
|
||||
| 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' -> true
|
||||
| _ -> false)
|
||||
in
|
||||
lift2
|
||||
(fun hd tl -> String.of_seq (List.to_seq (hd :: tl)))
|
||||
first_char (many subsequent_char)
|
||||
|
||||
(* todo handle '\' escape and '+' on next line *)
|
||||
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 blank = newline *> return ()
|
||||
let comment = (char '#' *> take_till is_newline <* newline) *> return ()
|
||||
let record = many1 field
|
||||
|
||||
let records =
|
||||
let sep =
|
||||
(* at least one blank line *)
|
||||
skip_many comment *> blank *> skip_many (comment <|> blank)
|
||||
in
|
||||
sep_by1 sep record
|
||||
|
||||
let recfile : record list t =
|
||||
skip_many (comment <|> blank) *> records <* skip_many (comment <|> blank)
|
||||
|
||||
let parse s = parse_string ~consume:All recfile s
|
||||
Loading…
Add table
Add a link
Reference in a new issue