|
1 | 1 | (* -------------------------------------------------------------------- *) |
2 | 2 | open EcUtils |
3 | 3 |
|
| 4 | +(* -------------------------------------------------------------------- *) |
| 5 | +module PcreBck = Pcre2 |
| 6 | + |
4 | 7 | (* -------------------------------------------------------------------- *) |
5 | 8 | type split = |
6 | 9 | | Text of string |
|
33 | 36 |
|
34 | 37 | (* -------------------------------------------------------------------- *) |
35 | 38 | module PcreCore : CORE = struct |
36 | | - type regexp = Pcre.regexp |
37 | | - type subst = Pcre.substitution |
38 | | - type match_ = Pcre.substrings |
| 39 | + type regexp = PcreBck.regexp |
| 40 | + type subst = PcreBck.substitution |
| 41 | + type match_ = PcreBck.substrings |
39 | 42 |
|
40 | 43 | type error = |
41 | | - | PCREError of Pcre.error |
| 44 | + | PCREError of PcreBck.error |
42 | 45 | | InvalidSubString of int |
43 | 46 | | InvalidBackRef |
44 | 47 |
|
45 | 48 | exception Error of error |
46 | 49 |
|
47 | 50 | let wrap (f : 'a -> 'b) (x : 'a) = |
48 | 51 | try f x |
49 | | - with Pcre.Error err -> raise (Error (PCREError err)) |
| 52 | + with PcreBck.Error err -> raise (Error (PCREError err)) |
50 | 53 |
|
51 | | - let quote (x : string) = (wrap Pcre.quote ) x |
52 | | - let regexp (x : string) = (wrap Pcre.regexp) x |
53 | | - let subst (x : string) = (wrap Pcre.subst ) x |
| 54 | + let quote (x : string) = (wrap PcreBck.quote ) x |
| 55 | + let regexp (x : string) = (wrap PcreBck.regexp) x |
| 56 | + let subst (x : string) = (wrap PcreBck.subst ) x |
54 | 57 |
|
55 | 58 | let exec ?(pos = 0) (rex : regexp) (x : string) = |
56 | | - try Some (wrap (Pcre.exec ~pos ~rex) x) |
| 59 | + try Some (wrap (PcreBck.exec ~pos ~rex) x) |
57 | 60 | with Not_found -> None |
58 | 61 |
|
59 | 62 | let split ?(pos = 0) (rex : regexp) (x : string) = |
60 | 63 | let convert = function |
61 | | - | Pcre.Text s -> Some (Text s) |
62 | | - | Pcre.Delim s -> Some (Delim s) |
| 64 | + | PcreBck.Text s -> Some (Text s) |
| 65 | + | PcreBck.Delim s -> Some (Delim s) |
63 | 66 | | _ -> None |
64 | 67 |
|
65 | | - in List.pmap convert (wrap (Pcre.full_split ~pos ~rex) x) |
| 68 | + in List.pmap convert (wrap (PcreBck.full_split ~pos ~rex) x) |
66 | 69 |
|
67 | 70 | let sub (rex : regexp) (subst : subst) (x : string) = |
68 | | - try wrap (Pcre.replace ~rex ~itempl:subst) x |
| 71 | + try wrap (PcreBck.replace ~rex ~itempl:subst) x |
69 | 72 | with Failure _ -> raise (Error InvalidBackRef) |
70 | 73 |
|
71 | 74 | let extract (rex : regexp) (x : string) = |
72 | | - try wrap (Pcre.extract_all_opt ~full_match:true ~rex) x |
| 75 | + try wrap (PcreBck.extract_all_opt ~full_match:true ~rex) x |
73 | 76 | with Not_found -> [||] |
74 | 77 |
|
75 | 78 | module Match = struct |
76 | 79 | let count (m : match_) : int = |
77 | | - (wrap Pcre.num_of_subs) m |
| 80 | + (wrap PcreBck.num_of_subs) m |
78 | 81 |
|
79 | 82 | let group (m : match_) (i : int) : string option = |
80 | | - try Some (wrap (Pcre.get_substring m) i) |
| 83 | + try Some (wrap (PcreBck.get_substring m) i) |
81 | 84 | with |
82 | 85 | | Invalid_argument _ -> raise (Error (InvalidSubString i)) |
83 | 86 | | Not_found -> None |
84 | 87 |
|
85 | 88 | let groups (m : match_) : (string option) array = |
86 | | - wrap (Pcre.get_opt_substrings ~full_match:true) m |
| 89 | + wrap (PcreBck.get_opt_substrings ~full_match:true) m |
87 | 90 |
|
88 | 91 | let offset (m : match_) (i : int) : (int * int) option = |
89 | | - try Some (wrap (Pcre.get_substring_ofs m) i) |
| 92 | + try Some (wrap (PcreBck.get_substring_ofs m) i) |
90 | 93 | with |
91 | 94 | | Invalid_argument _ -> raise (Error (InvalidSubString i)) |
92 | 95 | | Not_found -> None |
|
0 commit comments