From d14c923f9ea584232054ed37778bc7b2b71f814c Mon Sep 17 00:00:00 2001 From: swrup Date: Mon, 13 Oct 2025 06:59:42 +0200 Subject: [PATCH] --- default.config | 4 +--- include/parse_config.ml | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/default.config b/default.config index 4cc19e36..030410fe 100644 --- a/default.config +++ b/default.config @@ -7,6 +7,4 @@ fractional_normal_digits =2 fractional_trailing_zero_digits= 2 alt_unit_names = "{"0":"€","3":"k€"}" # comment 1 - # comment 2 - % comment 3 -% comment 4 +# comment 2 diff --git a/include/parse_config.ml b/include/parse_config.ml index ea4c9362..b82dbe44 100644 --- a/include/parse_config.ml +++ b/include/parse_config.ml @@ -3,10 +3,11 @@ do not support "$"-path expansion*) -[@@@ocaml.warning "-27-69-32"] - -(* -(* --- Duration values --- *) +(* TODO + - integer + - duration + - YES|NO + - alt_unit_names json pair type duration_element = { number: int; @@ -57,9 +58,12 @@ let blank_line = whitespace *> end_of_line let is_eol = function '\n' | '\r' -> true | _ -> false let comment = - whitespace *> peek_char_fail >>= fun c -> - if c = '#' || c = '%' then skip_while (fun c -> not (is_eol c)) *> end_of_line - else fail "not a comment" + whitespace *> peek_char >>= function + | None -> fail "peek_char end_of_file failure" + | Some c -> + if c = '#' || c = '%' then + skip_while (fun c -> not (is_eol c)) *> end_of_line + else fail "not a comment" let skip_ignored = skip_many (choice [ comment; blank_line ]) @@ -100,11 +104,11 @@ let section_header = char '[' *> identifier <* char ']' let section = lift2 (fun name items -> { name; items }) - (section_header <* skip_ignored) - (many (item <* skip_ignored)) + (skip_ignored *> section_header) + (many (skip_ignored *> item)) let config : config Angstrom.t = - skip_ignored *> many section <* skip_ignored <* end_of_input + many_till (section <* skip_ignored) end_of_input let parse_config s = match parse_string ~consume:Consume.All config s with @@ -129,6 +133,7 @@ let pp_config ppf (cfg : config) = let () = let content = read_file "default.config" in + (*Fmt.pr "%s" content;*) let config = parse_config content in