Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenldl committed Apr 12, 2023
1 parent f8c79bf commit aefc340
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/document.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ module Parsers = struct
let words_p ~delim = many (word_p ~delim <* spaces)
end

type work_stage = [
| `Title
| `Content
]
type work_stage =
| Title
| Content

let parse (s : (int * string) Seq.t) : t =
let rec aux (stage : work_stage) title s =
match stage with
| `Content -> (
| Content -> (
let s =
match title with
| None -> s
Expand All @@ -50,15 +49,15 @@ let parse (s : (int * string) Seq.t) : t =
content_index;
}
)
| `Title -> (
| Title -> (
match s () with
| Seq.Nil -> aux `Content title Seq.empty
| Seq.Nil -> aux Content title Seq.empty
| Seq.Cons ((_line_num, x), xs) -> (
aux `Content (Some x) xs
aux Content (Some x) xs
)
)
in
aux `Title None s
aux Title None s

let of_in_channel ~path ic : t =
let s = CCIO.read_lines_seq ic
Expand Down

0 comments on commit aefc340

Please sign in to comment.