The unpac monorepo manager self-hosting as a monorepo using unpac

feature: add some re parser that don't raise (#542)

authored by

Rudi Grinberg and committed by
GitHub
9d58581b de9bd965

+62
+3
CHANGES.md
··· 4 4 * Introduce [Re.Pcre.get_named_substring_opt]. A non raising version of 5 5 [Re.Pcre.get_named_substring] (#525) 6 6 7 + * Introduce parsing functions in `Re.{Perl,Pcre,Emacs,Glob}` that return a 8 + result instead of raising. (#542) 9 + 7 10 1.13.1 (30-Sep-2024) 8 11 -------------------- 9 12
+7
lib/emacs.ml
··· 121 121 if case then r else Re.no_case r 122 122 ;; 123 123 124 + 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 + 124 131 let compile = Re.compile 125 132 let compile_pat ?(case = true) s = compile (re ~case s)
+2
lib/emacs.mli
··· 30 30 (** Parsing of an Emacs-style regular expression *) 31 31 val re : ?case:bool -> string -> Core.t 32 32 33 + val re_result : ?case:bool -> string -> (Core.t, [ `Not_supported | `Parse_error ]) result 34 + 33 35 (** Regular expression compilation *) 34 36 val compile : Core.t -> Core.re 35 37
+16
lib/glob.ml
··· 316 316 if expand_braces then Re.alt (List.map to_re (explode s)) else to_re s 317 317 ;; 318 318 319 + 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 + 319 335 let glob' ?anchored period s = glob ?anchored ~period s 320 336 let globx ?anchored s = glob ?anchored ~expand_braces:true s 321 337 let globx' ?anchored period s = glob ?anchored ~expand_braces:true ~period s
+10
lib/glob.mli
··· 68 68 -> string 69 69 -> Core.t 70 70 71 + 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 + 71 81 (** Same, but allows to choose whether dots at the beginning of a 72 82 file name need to be explicitly matched (true) or not (false) 73 83
+7
lib/pcre.ml
··· 33 33 Perl.re ~opts pat 34 34 ;; 35 35 36 + 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 + 36 43 let regexp ?flags pat = Re.compile (re ?flags pat) 37 44 let extract ~rex s = Re.Group.all (Re.exec rex s) 38 45 let exec ~rex ?pos s = Re.exec rex ?pos s
+5
lib/pcre.mli
··· 24 24 (** [re ~flags s] creates the regexp [s] using the pcre syntax. *) 25 25 val re : ?flags:flag list -> string -> Core.t 26 26 27 + val re_result 28 + : ?flags:flag list 29 + -> string 30 + -> (Core.t, [ `Not_supported | `Parse_error ]) result 31 + 27 32 (** [re ~flags s] compiles the regexp [s] using the pcre syntax. *) 28 33 val regexp : ?flags:flag list -> string -> regexp 29 34
+7
lib/perl.ml
··· 338 338 339 339 let compile = Re.compile 340 340 let compile_pat ?(opts = []) s = compile (re ~opts s) 341 + 342 + let re_result ?opts s = 343 + match re ?opts s with 344 + | s -> Ok s 345 + | exception Not_supported -> Error `Not_supported 346 + | exception Parse_error -> Error `Parse_error 347 + ;;
+5
lib/perl.mli
··· 39 39 (** Parsing of a Perl-style regular expression *) 40 40 val re : ?opts:opt list -> string -> Core.t 41 41 42 + val re_result 43 + : ?opts:opt list 44 + -> string 45 + -> (Core.t, [ `Not_supported | `Parse_error ]) result 46 + 42 47 (** (Same as [Re.compile]) *) 43 48 val compile : Core.t -> Core.re 44 49