This commit is contained in:
swrup 2026-02-10 04:24:05 +01:00
parent b234654de8
commit eeb8f80c44

View file

@ -38,16 +38,20 @@ module Parse_data = struct
take_while1 ident_char >>| String.lowercase_ascii take_while1 ident_char >>| String.lowercase_ascii
let line = take_till is_eol <* end_of_line let line = take_till is_eol <* end_of_line
let blank = blanks <* end_of_line >>| fun () -> Blank let blank_line = blanks <* end_of_line >>| fun () -> Blank
let comment = blanks *> (char '#' <|> char '%') *> line >>| fun s -> Comment s let comment = blanks *> (char '#' <|> char '%') *> line >>| fun s -> Comment s
let header = char '[' *> id <* char ']' <* end_of_line >>| fun s -> Header s let header = blanks *> char '[' *> id <* char ']' <* blanks <* end_of_line >>| fun s -> Header s
let item_value = let item_value =
let unquoted_value = let unquoted_value =
take_while1 (fun c -> not (is_whitespace c || is_eol c)) <* end_of_line take_while1 (fun c -> not (is_whitespace c || is_eol c)) <* blanks <* end_of_line
in in
let quoted_value = let quoted_value =
char '"' *> take_till is_eol <* end_of_line >>= fun s -> char '"' *>
take_till ((=) '"') <* char '"'
<* end_of_line >>= fun s ->
match String.ends_with ~suffix:"\"" s with match String.ends_with ~suffix:"\"" s with
| false -> fail "invalid quoted value" | false -> fail "invalid quoted value"
| true -> | true ->
@ -62,7 +66,7 @@ module Parse_data = struct
id id
(blanks *> char '=' *> blanks *> item_value) (blanks *> char '=' *> blanks *> item_value)
let config = many (choice [ blank; comment; header; item ]) <* end_of_input let config = many (choice [ blank_line; comment; header; item ]) <* end_of_input
let fold_sections l = let fold_sections l =
let rec loop section_l item_l l = let rec loop section_l item_l l =