forked from avsm/ocaml-abnf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimap_terms.ml
115 lines (87 loc) · 2.62 KB
/
imap_terms.ml
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
(** Copyright (c) 2008,2009 Anil Madhavapeddy <anil@recoil.org>
** See the COPYING file included in this distribution for licensing details *)
open Printf
exception Parse_error of string
module Terminal = struct
module DIGIT = struct
(* Decimal digits (0–9) *)
type t = int
let of_char = function
|'\x30' -> 0 |'\x31' -> 1 |'\x32' -> 2
|'\x33' -> 3 |'\x34' -> 4 |'\x35' -> 5
|'\x36' -> 6 |'\x37' -> 7 |'\x38' -> 8
|'\x39' -> 9
|x -> raise (Parse_error (sprintf "Terminal.DIGIT.of_char %c" x))
let to_int x = x
let of_string = int_of_string
let to_string (x:t) = string_of_int x
let test = function
|'\x30'..'\x39' -> true
|_ -> false
let one = Imap_parser.one test of_char
end
module SP = struct
type t = unit
let test = function
|'\x22' -> true
|_ -> false
let of_char (x:char) : t = ()
let to_string (x:t) = "SP"
let one = Imap_parser.one test of_char
end
module DQUOTE = struct
type t = unit
let test = function
|'\x22' -> true
|_ -> false
let of_char (x:char) : t = ()
let to_string (x:t) = "DQUOTE"
let one = Imap_parser.one test of_char
end
module ALPHA = struct
type t = char
let test = function
|'\x41'..'\x5A' -> true
|'\x61'..'\x7A' -> true
|_ -> false
let of_char (x:char) : t = x
let to_string (x:t) = sprintf "%c" x
let one = Imap_parser.one test of_char
end
module CHAR = struct
type t = char
let test = function
|'\x01'..'\x7f' -> true
|_ -> false
let of_char (x:char) : t = x
let to_string (x:t) = sprintf "%c" x
let one = Imap_parser.one test of_char
end
module CTL = struct
type t = char
let test = function
|'\x00'..'\x1f' | '\x7f' -> true
|_ -> false
let of_char (x:char) : t = x
let to_string (x:t) = "CTL"
let one = Imap_parser.one test of_char
end
module CRLF = struct
type t = unit
let test = function
|'\x0D' -> true
|'\x0a' -> true
|_ -> false
let of_char (x:char) : t = ()
let to_string (x:t) = "CRLF"
let one = Imap_parser.one test of_char
end
type t =
| CRLF
| CTL of CTL.t
| CHAR of CHAR.t
| ALPHA of ALPHA.t
| DQUOTE
| SP
| DIGIT of DIGIT.t
end