diff options
author | sternenseemann <git@lukasepple.de> | 2020-05-13 18:43:32 +0200 |
---|---|---|
committer | sternenseemann <git@lukasepple.de> | 2020-05-13 18:43:32 +0200 |
commit | 32a424cd0b836f007db2df1bb570219ab28d449d (patch) | |
tree | 7e68a7da3554aae4dbebb070dc161496ce8a3fdc | |
parent | f592360503f99dce3966cdc6fdad1d2728fd6fe6 (diff) |
don't require block lines to be non empty
This allows for: * empty 0 indent blocks (summary) * empty lines in indent 1 or greater blocks (i. e. a line of 2 spaces becomes an empty line in an indent 2 block)
-rw-r--r-- | src/log.ml | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/log.ml b/src/log.ml index ef97101..6032151 100644 --- a/src/log.ml +++ b/src/log.ml @@ -33,6 +33,9 @@ type 'a log = ('a log_entry) list let empty_line = end_of_line let non_empty_line = take_while1 (fun c -> c != '\n') <* end_of_line +let line = take_while (fun c -> c != '\n') <* end_of_line + +let try' p = p <|> return () let editor_comment = string "-*-" *> skip_while (fun c -> c != '\n') @@ -53,16 +56,18 @@ let fail_if_none p = | Some x -> return x in p >>= failer + let rec block indent = - let checkforblock = function + let block_continued = function | None -> false | Some '\n' -> false | Some c -> if indent > 0 then c = ' ' else true - in String.append - <$> (count indent (char ' ') *> non_empty_line) + in + String.append + <$> (count indent (char ' ') *> line) <*> (peek_char >>= (fun c -> - if (checkforblock c) then (String.append "\n") <$> block indent + if (block_continued c) then (String.append "\n") <$> block indent else return "")) let itemp = @@ -75,17 +80,10 @@ let log_entryp = (fun d s i -> Log_entry (d, s, i)) <$> (date <* skip_many empty_line) <*> block 0 - <*> (skip_many empty_line *> spaced_list itemp) - -(* Parser TODO - * - substitutions - * - markdown/other markup - * - proper failure if not - * the whole output is consumed - * … - *) + <*> (skip_many empty_line *> spaced_list itemp <* skip_many empty_line) + let log_parser = - (editor_comment <|> return ()) *> + try' editor_comment *> skip_many empty_line *> spaced_list log_entryp |