This commit is contained in:
parent
7ea4caa56b
commit
ad874141cc
2 changed files with 16 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue