summaryrefslogtreecommitdiff
path: root/gemini/parseCommon.ml
blob: 3df2c557925c3e3faaa785f2c51a896bac09dcc7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module type PARSE_COMMON =
sig
  val is_letter : char -> bool

  val is_digit : char -> bool

  val is_whitespace : char -> bool

  val is_cr : char -> bool

  val lift_or : ('a -> bool) -> ('a -> bool) -> 'a -> bool

  val skip_spaces : unit Angstrom.t

  val take_till_crlf : string Angstrom.t

  val take_till_eol : string Angstrom.t
end

module ParseCommon : PARSE_COMMON =
struct
  open Angstrom

  let is_letter = function
    | 'a' .. 'z' | 'A' .. 'Z' -> true
    | _ -> false

  let is_digit = function
    | '0' .. '9' -> true
    | _ -> false

  let is_whitespace = function
    | ' ' | '\t' -> true
    | _ -> false

  let is_cr = function
    | '\r' -> true
    | _ -> false

  let lift_or p q b = p b || q b

  let skip_spaces = skip_while is_whitespace

  let take_till_crlf = take_till is_cr <* string "\r\n"

  let take_till_eol =
    let is_eol = function
      | '\n' | '\r' -> true
      | _ -> false in
    take_till is_eol <* end_of_line
end