-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.ml
44 lines (37 loc) · 1.27 KB
/
Main.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
open Warblre.Engines
open Warblre.Printers
(* Parameters for the engine we will use. *)
module Parameters = Warblre.OCamlEngineParameters.UnicodeParameters
module StringLike = Warblre.OCamlEngineParameters.Utf16StringLike
(* Instantiate the engine, and setup some utilities. *)
module Engine = Engine(Parameters)
module Printer = Printer(Parameters)(StringLike)
open Warblre.Notations.CharNotations(Parameters)(StringLike)
(* Let's create a regex using the notations we just imported. *)
(* Disregard the spaces *)
(* ( (?: (?<G>a) | (b) | π | (🧭) )* ) *)
let regex =
group !* (
ngroup ("G", char "a") ||
group (char "b") ||
(char "π") ||
(char "🧭"))
(* Flags are used to configure the engine; we will just enable reporting of capture indices (d). *)
let flags = Warblre.Extracted.RegExpFlags.({
d = true;
g = false;
i = false;
m = false;
s = false;
u = ();
y = false;
})
let input =
"aaaaabaπaa🧭aaccaa"
let () =
Printf.printf "Regex: %s\n" (Printer.regex_to_string regex);
Printf.printf "Input: '%s'\n" input;
let instance = Engine.initialize regex flags in
match Engine.exec instance (StringLike.of_string input) with
| Null _ -> Printf.printf "No match.\n"
| Exotic (result, _) -> Printf.printf "%s\n" (Printer.array_exotic_to_string result)