Skip to content

Commit 85f2faf

Browse files
committed
EcRegexp: PCRE -> PCRE2
1 parent 41d8e7b commit 85f2faf

2 files changed

Lines changed: 23 additions & 20 deletions

File tree

src/dune

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
(public_name easycrypt.ecLib)
1616
(foreign_stubs (language c) (names eunix))
1717
(modules :standard \ ec)
18-
(libraries batteries camlp-streams dune-build-info dune-site inifiles why3 yojson zarith)
18+
(libraries batteries camlp-streams dune-build-info dune-site inifiles pcre2 why3 yojson zarith)
1919
)
2020

2121
(executable
2222
(public_name easycrypt)
2323
(name ec)
2424
(modules ec)
2525
(promote (until-clean))
26-
(libraries batteries camlp-streams dune-build-info dune-site inifiles why3 yojson zarith ecLib))
26+
(libraries batteries camlp-streams dune-build-info dune-site inifiles pcre2 why3 yojson zarith ecLib))
2727

2828
(ocamllex ecLexer)
2929

src/ecRegexp.ml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
(* -------------------------------------------------------------------- *)
22
open EcUtils
33

4+
(* -------------------------------------------------------------------- *)
5+
module PcreBck = Pcre2
6+
47
(* -------------------------------------------------------------------- *)
58
type split =
69
| Text of string
@@ -33,60 +36,60 @@ end
3336

3437
(* -------------------------------------------------------------------- *)
3538
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
3942

4043
type error =
41-
| PCREError of Pcre.error
44+
| PCREError of PcreBck.error
4245
| InvalidSubString of int
4346
| InvalidBackRef
4447

4548
exception Error of error
4649

4750
let wrap (f : 'a -> 'b) (x : 'a) =
4851
try f x
49-
with Pcre.Error err -> raise (Error (PCREError err))
52+
with PcreBck.Error err -> raise (Error (PCREError err))
5053

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
5457

5558
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)
5760
with Not_found -> None
5861

5962
let split ?(pos = 0) (rex : regexp) (x : string) =
6063
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)
6366
| _ -> None
6467

65-
in List.pmap convert (wrap (Pcre.full_split ~pos ~rex) x)
68+
in List.pmap convert (wrap (PcreBck.full_split ~pos ~rex) x)
6669

6770
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
6972
with Failure _ -> raise (Error InvalidBackRef)
7073

7174
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
7376
with Not_found -> [||]
7477

7578
module Match = struct
7679
let count (m : match_) : int =
77-
(wrap Pcre.num_of_subs) m
80+
(wrap PcreBck.num_of_subs) m
7881

7982
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)
8184
with
8285
| Invalid_argument _ -> raise (Error (InvalidSubString i))
8386
| Not_found -> None
8487

8588
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
8790

8891
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)
9093
with
9194
| Invalid_argument _ -> raise (Error (InvalidSubString i))
9295
| Not_found -> None

0 commit comments

Comments
 (0)