diff options
author | Ryan Kavanagh <rak@rak.ac> | 2020-06-02 14:27:47 -0400 |
---|---|---|
committer | Ryan Kavanagh <rak@rak.ac> | 2020-06-07 11:39:58 -0400 |
commit | 5833971a52a4e6e078988fa88738e5a5180cce36 (patch) | |
tree | c9907a47fdc0c0b364161826668752d637a3f9aa /gemini/parseCommon.ml | |
parent | string_to_request -> make_request (diff) |
Split common parsing functions into separate function
Diffstat (limited to 'gemini/parseCommon.ml')
-rw-r--r-- | gemini/parseCommon.ml | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/gemini/parseCommon.ml b/gemini/parseCommon.ml new file mode 100644 index 0000000..999cd83 --- /dev/null +++ b/gemini/parseCommon.ml @@ -0,0 +1,43 @@ +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_cr : 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_cr = take_till is_cr <* string "\r\n" +end |