···44* Introduce [Re.Pcre.get_named_substring_opt]. A non raising version of
55 [Re.Pcre.get_named_substring] (#525)
6677+* Introduce parsing functions in `Re.{Perl,Pcre,Emacs,Glob}` that return a
88+ result instead of raising. (#542)
99+7101.13.1 (30-Sep-2024)
811--------------------
912
+7
lib/emacs.ml
···121121 if case then r else Re.no_case r
122122;;
123123124124+let re_result ?case s =
125125+ match re ?case s with
126126+ | s -> Ok s
127127+ | exception Not_supported -> Error `Not_supported
128128+ | exception Parse_error -> Error `Parse_error
129129+;;
130130+124131let compile = Re.compile
125132let compile_pat ?(case = true) s = compile (re ~case s)
···316316 if expand_braces then Re.alt (List.map to_re (explode s)) else to_re s
317317;;
318318319319+let glob_result
320320+ ?anchored
321321+ ?pathname
322322+ ?match_backslashes
323323+ ?period
324324+ ?expand_braces
325325+ ?double_asterisk
326326+ s
327327+ =
328328+ match
329329+ glob ?anchored ?pathname ?match_backslashes ?period ?expand_braces ?double_asterisk s
330330+ with
331331+ | re -> Ok re
332332+ | exception Parse_error -> Error `Parse_error
333333+;;
334334+319335let glob' ?anchored period s = glob ?anchored ~period s
320336let globx ?anchored s = glob ?anchored ~expand_braces:true s
321337let globx' ?anchored period s = glob ?anchored ~expand_braces:true ~period s
+10
lib/glob.mli
···6868 -> string
6969 -> Core.t
70707171+val glob_result
7272+ : ?anchored:bool
7373+ -> ?pathname:bool
7474+ -> ?match_backslashes:bool
7575+ -> ?period:bool
7676+ -> ?expand_braces:bool
7777+ -> ?double_asterisk:bool
7878+ -> string
7979+ -> (Core.t, [ `Parse_error ]) result
8080+7181(** Same, but allows to choose whether dots at the beginning of a
7282 file name need to be explicitly matched (true) or not (false)
7383
+7
lib/pcre.ml
···3333 Perl.re ~opts pat
3434;;
35353636+let re_result ?flags s =
3737+ match re ?flags s with
3838+ | s -> Ok s
3939+ | exception Not_supported -> Error `Not_supported
4040+ | exception Parse_error -> Error `Parse_error
4141+;;
4242+3643let regexp ?flags pat = Re.compile (re ?flags pat)
3744let extract ~rex s = Re.Group.all (Re.exec rex s)
3845let exec ~rex ?pos s = Re.exec rex ?pos s
+5
lib/pcre.mli
···2424(** [re ~flags s] creates the regexp [s] using the pcre syntax. *)
2525val re : ?flags:flag list -> string -> Core.t
26262727+val re_result
2828+ : ?flags:flag list
2929+ -> string
3030+ -> (Core.t, [ `Not_supported | `Parse_error ]) result
3131+2732(** [re ~flags s] compiles the regexp [s] using the pcre syntax. *)
2833val regexp : ?flags:flag list -> string -> regexp
2934
+7
lib/perl.ml
···338338339339let compile = Re.compile
340340let compile_pat ?(opts = []) s = compile (re ~opts s)
341341+342342+let re_result ?opts s =
343343+ match re ?opts s with
344344+ | s -> Ok s
345345+ | exception Not_supported -> Error `Not_supported
346346+ | exception Parse_error -> Error `Parse_error
347347+;;
+5
lib/perl.mli
···3939(** Parsing of a Perl-style regular expression *)
4040val re : ?opts:opt list -> string -> Core.t
41414242+val re_result
4343+ : ?opts:opt list
4444+ -> string
4545+ -> (Core.t, [ `Not_supported | `Parse_error ]) result
4646+4247(** (Same as [Re.compile]) *)
4348val compile : Core.t -> Core.re
4449