+ parser still buggy on multi-comment

This commit is contained in:
swrup 2025-10-13 06:59:42 +02:00
parent eac7a77d94
commit 3813b7267b
2 changed files with 16 additions and 13 deletions

View file

@ -8,5 +8,3 @@ fractional_trailing_zero_digits= 2
alt_unit_names = "{"0":"€","3":"k€"}" alt_unit_names = "{"0":"€","3":"k€"}"
# comment 1 # comment 1
# comment 2 # comment 2
% comment 3
% comment 4

View file

@ -3,10 +3,11 @@
do not support "$"-path expansion*) do not support "$"-path expansion*)
[@@@ocaml.warning "-27-69-32"] (* TODO
- integer
(* - duration
(* --- Duration values --- *) - YES|NO
- alt_unit_names json pair
type duration_element = { type duration_element = {
number: int; number: int;
@ -57,8 +58,11 @@ let blank_line = whitespace *> end_of_line
let is_eol = function '\n' | '\r' -> true | _ -> false let is_eol = function '\n' | '\r' -> true | _ -> false
let comment = let comment =
whitespace *> peek_char_fail >>= fun c -> whitespace *> peek_char >>= function
if c = '#' || c = '%' then skip_while (fun c -> not (is_eol c)) *> end_of_line | 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" else fail "not a comment"
let skip_ignored = skip_many (choice [ comment; blank_line ]) let skip_ignored = skip_many (choice [ comment; blank_line ])
@ -100,11 +104,11 @@ let section_header = char '[' *> identifier <* char ']'
let section = let section =
lift2 lift2
(fun name items -> { name; items }) (fun name items -> { name; items })
(section_header <* skip_ignored) (skip_ignored *> section_header)
(many (item <* skip_ignored)) (many (skip_ignored *> item))
let config : config Angstrom.t = 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 = let parse_config s =
match parse_string ~consume:Consume.All config s with match parse_string ~consume:Consume.All config s with
@ -129,6 +133,7 @@ let pp_config ppf (cfg : config) =
let () = let () =
let content = read_file "default.config" in let content = read_file "default.config" in
(*Fmt.pr "%s" content;*)
let config = parse_config content in let config = parse_config content in