summaryrefslogtreecommitdiff
path: root/gemini/mimeTextGemini.ml
diff options
context:
space:
mode:
authorRyan Kavanagh <rak@rak.ac>2020-06-02 14:27:47 -0400
committerRyan Kavanagh <rak@rak.ac>2020-06-07 11:39:58 -0400
commit5833971a52a4e6e078988fa88738e5a5180cce36 (patch)
treec9907a47fdc0c0b364161826668752d637a3f9aa /gemini/mimeTextGemini.ml
parentstring_to_request -> make_request (diff)
Split common parsing functions into separate function
Diffstat (limited to 'gemini/mimeTextGemini.ml')
-rw-r--r--gemini/mimeTextGemini.ml17
1 files changed, 3 insertions, 14 deletions
diff --git a/gemini/mimeTextGemini.ml b/gemini/mimeTextGemini.ml
index e73be65..2f4d5ca 100644
--- a/gemini/mimeTextGemini.ml
+++ b/gemini/mimeTextGemini.ml
@@ -45,6 +45,8 @@ end
module MimeTextGemini : MIME_TEXT_GEMINI =
struct
+ open ParseCommon.ParseCommon
+
exception ParseError of string
type gemini_line =
@@ -96,24 +98,11 @@ struct
let (_, s) = List.fold_right f g (false, "") in
s
-
let parse_string p s =
match Angstrom.parse_string ~consume:All (p >>= return) s with
| Ok parsed -> parsed
| Error m -> raise (ParseError m)
- let is_space = function
- | ' ' | '\t' -> true
- | _ -> false
-
- let is_cr = function
- | '\r' -> true
- | _ -> false
-
- let skip_spaces = skip_while is_space
-
- let take_till_cr = take_till is_cr <* string "\r\n"
-
let header_parser =
lift (fun x -> H3 x) (string "###" *> skip_spaces *> take_till_cr)
<|> lift (fun x -> H2 x) (string "##" *> skip_spaces *> take_till_cr)
@@ -123,7 +112,7 @@ struct
let str_to_header_line = parse_string header_parser
let link_parser =
- let end_of_url b = is_space b || is_cr b in
+ let end_of_url b = is_whitespace b || is_cr b in
let to_link s = function
| "" -> Link (s, None)
| n -> Link (s, Some n)