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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
type _ t
type 'enc regex = 'enc t
exception Error of string
external initialize : unit -> unit = "ocaml_onig_initialize"
external cleanup : unit -> unit = "ocaml_onig_end"
let () =
Callback.register_exception "Oniguruma.Error" (Error "");
Callback.register_exception "Oniguruma.Invalid_argument" (Invalid_argument "");
Callback.register_exception "Oniguruma.Failure" (Failure "");
initialize ();
at_exit cleanup
module Encoding = struct
type _ t
type ascii
external get_ascii : unit -> ascii t = "ocaml_get_onig_encoding_ascii"
let ascii = get_ascii ()
type iso_8859_1
external get_iso_8859_1 : unit -> iso_8859_1 t
= "ocaml_get_onig_encoding_iso_8859_1"
let iso_8859_1 = get_iso_8859_1 ()
type iso_8859_2
external get_iso_8859_2 : unit -> iso_8859_2 t
= "ocaml_get_onig_encoding_iso_8859_2"
let iso_8859_2 = get_iso_8859_2 ()
type iso_8859_3
external get_iso_8859_3 : unit -> iso_8859_3 t
= "ocaml_get_onig_encoding_iso_8859_3"
let iso_8859_3 = get_iso_8859_3 ()
type iso_8859_4
external get_iso_8859_4 : unit -> iso_8859_4 t
= "ocaml_get_onig_encoding_iso_8859_4"
let iso_8859_4 = get_iso_8859_4 ()
type iso_8859_5
external get_iso_8859_5 : unit -> iso_8859_5 t
= "ocaml_get_onig_encoding_iso_8859_5"
let iso_8859_5 = get_iso_8859_5 ()
type iso_8859_6
external get_iso_8859_6 : unit -> iso_8859_6 t
= "ocaml_get_onig_encoding_iso_8859_6"
let iso_8859_6 = get_iso_8859_6 ()
type iso_8859_7
external get_iso_8859_7 : unit -> iso_8859_7 t
= "ocaml_get_onig_encoding_iso_8859_7"
let iso_8859_7 = get_iso_8859_7 ()
type iso_8859_8
external get_iso_8859_8 : unit -> iso_8859_8 t
= "ocaml_get_onig_encoding_iso_8859_8"
let iso_8859_8 = get_iso_8859_8 ()
type iso_8859_9
external get_iso_8859_9 : unit -> iso_8859_9 t
= "ocaml_get_onig_encoding_iso_8859_9"
let iso_8859_9 = get_iso_8859_9 ()
type iso_8859_10
external get_iso_8859_10 : unit -> iso_8859_10 t
= "ocaml_get_onig_encoding_iso_8859_10"
let iso_8859_10 = get_iso_8859_10 ()
type iso_8859_11
external get_iso_8859_11 : unit -> iso_8859_11 t
= "ocaml_get_onig_encoding_iso_8859_11"
let iso_8859_11 = get_iso_8859_11 ()
type iso_8859_13
external get_iso_8859_13 : unit -> iso_8859_13 t
= "ocaml_get_onig_encoding_iso_8859_13"
let iso_8859_13 = get_iso_8859_13 ()
type iso_8859_14
external get_iso_8859_14 : unit -> iso_8859_14 t
= "ocaml_get_onig_encoding_iso_8859_14"
let iso_8859_14 = get_iso_8859_14 ()
type iso_8859_15
external get_iso_8859_15 : unit -> iso_8859_15 t
= "ocaml_get_onig_encoding_iso_8859_15"
let iso_8859_15 = get_iso_8859_15 ()
type iso_8859_16
external get_iso_8859_16 : unit -> iso_8859_16 t
= "ocaml_get_onig_encoding_iso_8859_16"
let iso_8859_16 = get_iso_8859_16 ()
type utf8
external get_utf8 : unit -> utf8 t = "ocaml_get_onig_encoding_utf8"
let utf8 = get_utf8 ()
type utf16_be
external get_utf16_be : unit -> utf16_be t
= "ocaml_get_onig_encoding_utf16_be"
let utf16_be = get_utf16_be ()
type utf16_le
external get_utf16_le : unit -> utf16_le t
= "ocaml_get_onig_encoding_utf16_le"
let utf16_le = get_utf16_le ()
type utf32_be
external get_utf32_be : unit -> utf32_be t
= "ocaml_get_onig_encoding_utf32_be"
let utf32_be = get_utf32_be ()
type utf32_le
external get_utf32_le : unit -> utf32_le t
= "ocaml_get_onig_encoding_utf32_le"
let utf32_le = get_utf32_le ()
type euc_jp
external get_euc_jp : unit -> euc_jp t = "ocaml_get_onig_encoding_euc_jp"
let euc_jp = get_euc_jp ()
type euc_tw
external get_euc_tw : unit -> euc_tw t = "ocaml_get_onig_encoding_euc_tw"
let euc_tw = get_euc_tw ()
type euc_kr
external get_euc_kr : unit -> euc_kr t = "ocaml_get_onig_encoding_euc_kr"
let euc_kr = get_euc_kr ()
type euc_cn
external get_euc_cn : unit -> euc_cn t = "ocaml_get_onig_encoding_euc_cn"
let euc_cn = get_euc_cn ()
type sjis
external get_sjis : unit -> sjis t = "ocaml_get_onig_encoding_sjis"
let sjis = get_sjis ()
type koi8_r
external get_koi8_r : unit -> koi8_r t = "ocaml_get_onig_encoding_koi8_r"
let koi8_r = get_koi8_r ()
type cp1251
external get_cp1251 : unit -> cp1251 t = "ocaml_get_onig_encoding_cp1251"
let cp1251 = get_cp1251 ()
type big5
external get_big5 : unit -> big5 t = "ocaml_get_onig_encoding_big5"
let big5 = get_big5 ()
type gb18030
external get_gb18030 : unit -> gb18030 t = "ocaml_get_onig_encoding_gb18030"
let gb18030 = get_gb18030 ()
end
module Options = struct
type _ t = int
external option : int -> 'a t = "ocaml_onig_option"
let ( <+> ) = ( lor )
let none = option 0
type compile_time
let singleline = option 1
let multiline = option 2
let ignorecase = option 3
let extend = option 4
let find_longest = option 5
let find_not_empty = option 6
let negate_singleline = option 7
let dont_capture_group = option 8
let capture_group = option 9
type search_time
let ignorecase_is_ascii = option 13
let word_is_ascii = option 14
let digit_is_ascii = option 15
let space_is_ascii = option 16
let posix_is_ascii = option 17
let text_segment_extended_grapheme_cluster = option 18
let text_segment_word = option 19
let notbol = option 10
let noteol = option 11
let not_begin_position = option 12
let not_begin_string = option 20
let not_end_string = option 21
let posix_region = option 22
let check_validity_of_string = option 23
let callback_each_match = option 24
end
module Syntax = struct
type t
external get_asis : unit -> t = "ocaml_get_onig_syntax_asis"
let asis = get_asis ()
external get_posix_basic : unit -> t = "ocaml_get_onig_syntax_posix_basic"
let posix_basic = get_posix_basic ()
external get_posix_extended : unit -> t
= "ocaml_get_onig_syntax_posix_extended"
let posix_extended = get_posix_extended ()
external get_emacs : unit -> t = "ocaml_get_onig_syntax_emacs"
let emacs = get_emacs ()
external get_grep : unit -> t = "ocaml_get_onig_syntax_grep"
let grep = get_grep ()
external get_gnu_regex : unit -> t = "ocaml_get_onig_syntax_gnu_regex"
let gnu_regex = get_gnu_regex ()
external get_java : unit -> t = "ocaml_get_onig_syntax_java"
let java = get_java ()
external get_perl : unit -> t = "ocaml_get_onig_syntax_perl"
let perl = get_perl ()
external get_perl_ng : unit -> t = "ocaml_get_onig_syntax_perl_ng"
let perl_ng = get_perl_ng ()
external get_default : unit -> t = "ocaml_get_onig_syntax_default"
let default = get_default ()
end
module Region = struct
type t
external length : t -> int = "ocaml_onig_region_length"
external capture_beg : t -> int -> int = "ocaml_onig_capture_beg"
external capture_end : t -> int -> int = "ocaml_onig_capture_end"
end
module MatchParam = struct
type t
external create : unit -> t = "ocaml_onig_new_match_param"
external set_match_stack_limit_size : t -> int -> unit
= "ocaml_onig_match_param_set_match_stack_limit"
external set_retry_limit_in_match : t -> int -> unit
= "ocaml_onig_match_param_set_retry_limit_in_match"
external set_retry_limit_in_search : t -> int -> unit
= "ocaml_onig_match_param_set_retry_limit_in_search"
end
module RegSet = struct
type t
external create : _ regex array -> t = "ocaml_onig_regset_new"
external search :
t ->
string ->
int ->
int ->
Options.search_time Options.t ->
(int * Region.t) option = "ocaml_onig_regset_search"
end
external create :
string ->
Options.compile_time Options.t ->
'enc Encoding.t ->
Syntax.t ->
('enc t, string) result = "ocaml_onig_new"
external search :
'enc t ->
string ->
int ->
int ->
Options.search_time Options.t ->
Region.t option = "ocaml_onig_search"
external match_ :
'enc t -> string -> int -> Options.search_time Options.t -> Region.t option
= "ocaml_onig_match"
external search_with_param :
'enc t ->
string ->
int ->
int ->
Options.search_time Options.t ->
MatchParam.t ->
Region.t option
= "ocaml_onig_search_with_param_bc" "ocaml_onig_search_with_param"
external match_with_param :
'enc t ->
string ->
int ->
Options.search_time Options.t ->
MatchParam.t ->
Region.t option = "ocaml_onig_match_with_param"
external scan :
_ t ->
string ->
Options.search_time Options.t ->
(int -> int -> Region.t -> bool) ->
int = "ocaml_onig_scan"
external num_captures : _ t -> int = "ocaml_onig_num_captures"
external name_to_group_numbers : _ t -> string -> int array
= "ocaml_onig_name_to_group_numbers"
external number_of_names : _ t -> int = "ocaml_onig_number_of_names"
external number_of_capture_histories : _ t -> int
= "ocaml_onig_number_of_capture_histories"
external noname_group_capture_is_active : _ t -> bool
= "ocaml_onig_noname_group_capture_is_active"
external get_options : _ t -> Options.compile_time Options.t
= "ocaml_onig_get_options"
external foreach_name : _ t -> (string -> int array -> bool) -> unit
= "ocaml_onig_foreach_name"
external name_to_backref_number : _ t -> string -> Region.t -> int
= "ocaml_onig_name_to_backref_number"
external get_match_stack_limit_size : unit -> int
= "ocaml_onig_get_match_stack_limit_size"
external set_match_stack_limit_size : int -> unit
= "ocaml_onig_set_match_stack_limit_size"
external get_retry_limit_in_match : unit -> int
= "ocaml_onig_get_retry_limit_in_match"
external set_retry_limit_in_match : int -> unit
= "ocaml_onig_set_retry_limit_in_match"
external get_retry_limit_in_search : unit -> int
= "ocaml_onig_get_retry_limit_in_search"
external set_retry_limit_in_search : int -> unit
= "ocaml_onig_set_retry_limit_in_search"
external get_parse_depth_limit : unit -> int
= "ocaml_onig_get_parse_depth_limit"
external set_parse_depth_limit : int -> unit
= "ocaml_onig_set_parse_depth_limit"
external set_capture_num_limit : int -> unit
= "ocaml_onig_set_capture_num_limit"
external get_subexp_call_limit_in_search : unit -> int
= "ocaml_onig_get_subexp_call_limit_in_search"
external set_subexp_call_limit_in_search : int -> unit
= "ocaml_onig_set_subexp_call_limit_in_search"
external get_subexp_call_max_nest_level : unit -> int
= "ocaml_onig_get_subexp_call_max_nest_level"
external set_subexp_call_max_nest_level : int -> unit
= "ocaml_onig_set_subexp_call_max_nest_level"
external version_f : unit -> string = "ocaml_onig_version"
let version = version_f ()