text_parse/parsers/heading.ml
fox 77bc45eb1b Applicative text parser
TODO: markdown & gemini coming

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/text_parse/trunk@1 cb476dc4-a1c2-9446-a177-162899b6b847
2021-02-25 23:22:35 +00:00

18 lines
537 B
OCaml

module type Fn = sig
type t
val heading_hashbang: int -> string -> t -> t
end
open Text_parse.Syntax
open Text_parse.Cursor
module Hashbang (F : Fn) = struct
type t = F.t
let s _cur = function '#' -> true | _ -> false
let e _cur = newline
let parse cursor acc =
let level = match find_end (fun _cur c -> c <> '#') cursor with
Some x -> x - cursor.pos - 1 | None -> 0 in
F.heading_hashbang level (segment_string { cursor with pos = cursor.pos + level + 1; right_boundary = cursor.right_boundary-1 }) acc
end