Source file omega_comments.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
open Core_kernel
open Vangstrom
let (|>>) p f =
p >>= fun x -> return (f x)
let any_char_except ~reserved =
List.fold reserved
~init:(return `OK)
~f:(fun acc reserved_sequence ->
option `End_of_input
(peek_string (String.length reserved_sequence)
>>= fun s ->
if String.equal s reserved_sequence then
return `Reserved_sequence
else
acc))
>>= function
| `OK -> any_char
| `End_of_input -> any_char
| `Reserved_sequence -> fail "reserved sequence hit"
let between left right p =
left *> p <* right
let to_string from until between : string =
from ^ (String.of_char_list between) ^ until
let anything_including_newlines ~until =
many (any_char_except ~reserved:[until])
let anything_excluding_newlines () =
anything_including_newlines ~until:"\n"
let from until =
between
(string from)
(string until)
(anything_including_newlines ~until)
|>> to_string from until
module Multiline = struct
module type S = sig
val left : string
val right : string
end
module Make (M : S) = struct
let = non_nested_comment M.left M.right
end
end
let until_newline start =
(string start *> anything_excluding_newlines ()
|>> fun l -> start^(String.of_char_list l))
module Until_newline = struct
module type S = sig
val start : string
end
module Make (M : S) = struct
let = until_newline M.start
end
end