···4* Introduce [Re.Pcre.get_named_substring_opt]. A non raising version of
5 [Re.Pcre.get_named_substring] (#525)
600071.13.1 (30-Sep-2024)
8--------------------
9
···4* Introduce [Re.Pcre.get_named_substring_opt]. A non raising version of
5 [Re.Pcre.get_named_substring] (#525)
67+* Introduce parsing functions in `Re.{Perl,Pcre,Emacs,Glob}` that return a
8+ result instead of raising. (#542)
9+101.13.1 (30-Sep-2024)
11--------------------
12
+7
lib/emacs.ml
···121 if case then r else Re.no_case r
122;;
1230000000124let compile = Re.compile
125let compile_pat ?(case = true) s = compile (re ~case s)
···121 if case then r else Re.no_case r
122;;
123124+let re_result ?case s =
125+ match re ?case s with
126+ | s -> Ok s
127+ | exception Not_supported -> Error `Not_supported
128+ | exception Parse_error -> Error `Parse_error
129+;;
130+131let compile = Re.compile
132let compile_pat ?(case = true) s = compile (re ~case s)
+2
lib/emacs.mli
···30(** Parsing of an Emacs-style regular expression *)
31val re : ?case:bool -> string -> Core.t
320033(** Regular expression compilation *)
34val compile : Core.t -> Core.re
35
···316 if expand_braces then Re.alt (List.map to_re (explode s)) else to_re s
317;;
3180000000000000000319let glob' ?anchored period s = glob ?anchored ~period s
320let globx ?anchored s = glob ?anchored ~expand_braces:true s
321let globx' ?anchored period s = glob ?anchored ~expand_braces:true ~period s
···316 if expand_braces then Re.alt (List.map to_re (explode s)) else to_re s
317;;
318319+let glob_result
320+ ?anchored
321+ ?pathname
322+ ?match_backslashes
323+ ?period
324+ ?expand_braces
325+ ?double_asterisk
326+ s
327+ =
328+ match
329+ glob ?anchored ?pathname ?match_backslashes ?period ?expand_braces ?double_asterisk s
330+ with
331+ | re -> Ok re
332+ | exception Parse_error -> Error `Parse_error
333+;;
334+335let glob' ?anchored period s = glob ?anchored ~period s
336let globx ?anchored s = glob ?anchored ~expand_braces:true s
337let globx' ?anchored period s = glob ?anchored ~expand_braces:true ~period s
+10
lib/glob.mli
···68 -> string
69 -> Core.t
70000000000071(** Same, but allows to choose whether dots at the beginning of a
72 file name need to be explicitly matched (true) or not (false)
73
···68 -> string
69 -> Core.t
7071+val glob_result
72+ : ?anchored:bool
73+ -> ?pathname:bool
74+ -> ?match_backslashes:bool
75+ -> ?period:bool
76+ -> ?expand_braces:bool
77+ -> ?double_asterisk:bool
78+ -> string
79+ -> (Core.t, [ `Parse_error ]) result
80+81(** Same, but allows to choose whether dots at the beginning of a
82 file name need to be explicitly matched (true) or not (false)
83
+7
lib/pcre.ml
···33 Perl.re ~opts pat
34;;
35000000036let regexp ?flags pat = Re.compile (re ?flags pat)
37let extract ~rex s = Re.Group.all (Re.exec rex s)
38let exec ~rex ?pos s = Re.exec rex ?pos s
···33 Perl.re ~opts pat
34;;
3536+let re_result ?flags s =
37+ match re ?flags s with
38+ | s -> Ok s
39+ | exception Not_supported -> Error `Not_supported
40+ | exception Parse_error -> Error `Parse_error
41+;;
42+43let regexp ?flags pat = Re.compile (re ?flags pat)
44let extract ~rex s = Re.Group.all (Re.exec rex s)
45let exec ~rex ?pos s = Re.exec rex ?pos s
+5
lib/pcre.mli
···24(** [re ~flags s] creates the regexp [s] using the pcre syntax. *)
25val re : ?flags:flag list -> string -> Core.t
260000027(** [re ~flags s] compiles the regexp [s] using the pcre syntax. *)
28val regexp : ?flags:flag list -> string -> regexp
29
···24(** [re ~flags s] creates the regexp [s] using the pcre syntax. *)
25val re : ?flags:flag list -> string -> Core.t
2627+val re_result
28+ : ?flags:flag list
29+ -> string
30+ -> (Core.t, [ `Not_supported | `Parse_error ]) result
31+32(** [re ~flags s] compiles the regexp [s] using the pcre syntax. *)
33val regexp : ?flags:flag list -> string -> regexp
34