text_parse/parsers/key_value.ml
fox cec56ea18c Applicative text parser
TODO: markdown & gemini coming

git-svn-id: file:///srv/svn/repo/text_parse/trunk@1 cb476dc4-a1c2-9446-a177-162899b6b847
2021-02-25 23:22:35 +00:00

20 lines
655 B
OCaml

module type Fn = sig
type t
val key_value: string -> string -> t -> t
end
open Text_parse.Syntax
open Text_parse.Cursor
module Make (F : Fn) = struct
type t = F.t
let s _cur c = letter c
let e _cur c = newline c
let parse cursor acc =
let colon_pos = match find_end (fun _cur c -> c = ':') cursor with
Some x -> x - cursor.pos - 1 | None -> 0 in (*todo:None shouldn't be allowed by scope*)
let key = segment_string { cursor with right_boundary = cursor.pos+colon_pos } in
let value = segment_string { cursor with pos = cursor.pos+colon_pos+1; right_boundary = cursor.right_boundary } in
F.key_value key value acc
end