Skip to content

Commit

Permalink
v0.17~preview.128.37+01
Browse files Browse the repository at this point in the history
  • Loading branch information
public-release committed Aug 30, 2023
1 parent 7d495fa commit 9f9c1ca
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 70 deletions.
1 change: 1 addition & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
profile=janestreet
74 changes: 37 additions & 37 deletions src/options.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Stable0 = struct
{ case_insensitive : bool [@sexp.bool]
; dot_nl : bool [@sexp.bool]
; encoding : Encoding.V1.t
[@sexp.default Encoding.V1.Utf8] [@sexp_drop_default.compare]
[@sexp.default Encoding.V1.Utf8] [@sexp_drop_default.compare]
; literal : bool [@sexp.bool]
; log_errors : bool [@sexp.bool]
; longest_match : bool [@sexp.bool]
Expand Down Expand Up @@ -116,33 +116,33 @@ module C_repr = struct
external case_sensitive : t -> bool = "mlre2__options__case_sensitive" [@@noalloc]

external set_case_sensitive : t -> bool -> unit = "mlre2__options__set_case_sensitive"
[@@noalloc]
[@@noalloc]

external dot_nl : t -> bool = "mlre2__options__dot_nl" [@@noalloc]
external set_dot_nl : t -> bool -> unit = "mlre2__options__set_dot_nl" [@@noalloc]
external encoding : t -> Encoding.C_repr.t = "mlre2__options__encoding" [@@noalloc]

external set_encoding : t -> Encoding.C_repr.t -> unit = "mlre2__options__set_encoding"
[@@noalloc]
[@@noalloc]

external literal : t -> bool = "mlre2__options__literal" [@@noalloc]
external set_literal : t -> bool -> unit = "mlre2__options__set_literal" [@@noalloc]
external log_errors : t -> bool = "mlre2__options__log_errors" [@@noalloc]

external set_log_errors : t -> bool -> unit = "mlre2__options__set_log_errors"
[@@noalloc]
[@@noalloc]

external longest_match : t -> bool = "mlre2__options__longest_match" [@@noalloc]

external set_longest_match : t -> bool -> unit = "mlre2__options__set_longest_match"
[@@noalloc]
[@@noalloc]

external max_mem : t -> int = "mlre2__options__max_mem" [@@noalloc]
external set_max_mem : t -> int -> unit = "mlre2__options__set_max_mem" [@@noalloc]
external never_capture : t -> bool = "mlre2__options__never_capture" [@@noalloc]

external set_never_capture : t -> bool -> unit = "mlre2__options__set_never_capture"
[@@noalloc]
[@@noalloc]

external never_nl : t -> bool = "mlre2__options__never_nl" [@@noalloc]
external set_never_nl : t -> bool -> unit = "mlre2__options__set_never_nl" [@@noalloc]
Expand All @@ -151,17 +151,17 @@ module C_repr = struct
external perl_classes : t -> bool = "mlre2__options__perl_classes" [@@noalloc]

external set_perl_classes : t -> bool -> unit = "mlre2__options__set_perl_classes"
[@@noalloc]
[@@noalloc]

external posix_syntax : t -> bool = "mlre2__options__posix_syntax" [@@noalloc]

external set_posix_syntax : t -> bool -> unit = "mlre2__options__set_posix_syntax"
[@@noalloc]
[@@noalloc]

external word_boundary : t -> bool = "mlre2__options__word_boundary" [@@noalloc]

external set_word_boundary : t -> bool -> unit = "mlre2__options__set_word_boundary"
[@@noalloc]
[@@noalloc]
(*$*)

external create_quiet : unit -> t = "mlre2__options__create_quiet"
Expand Down Expand Up @@ -248,20 +248,20 @@ module Stable = struct
[@@deriving compare, hash, stable_witness]

let to_serialization
{ case_sensitive
; dot_nl
; encoding
; literal
; log_errors
; longest_match
; max_mem = _
; never_capture
; never_nl
; one_line
; perl_classes
; posix_syntax
; word_boundary
}
{ case_sensitive
; dot_nl
; encoding
; literal
; log_errors
; longest_match
; max_mem = _
; never_capture
; never_nl
; one_line
; perl_classes
; posix_syntax
; word_boundary
}
: Serialization.t
=
{ case_insensitive = not case_sensitive
Expand All @@ -280,20 +280,20 @@ module Stable = struct
;;

let of_serialization
({ case_insensitive
; dot_nl
; encoding
; literal
; log_errors
; longest_match
; never_capture
; never_nl
; one_line
; perl_classes
; posix_syntax
; word_boundary
} :
Serialization.t)
({ case_insensitive
; dot_nl
; encoding
; literal
; log_errors
; longest_match
; never_capture
; never_nl
; one_line
; perl_classes
; posix_syntax
; word_boundary
} :
Serialization.t)
=
{ case_sensitive = not case_insensitive
; dot_nl
Expand Down
25 changes: 12 additions & 13 deletions src/parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Body = struct
let map =
`Custom
(fun t ~f ->
{ t with to_result = (fun shift matches -> f (t.to_result shift matches)) })
{ t with to_result = (fun shift matches -> f (t.to_result shift matches)) })
;;

let apply tf tx =
Expand Down Expand Up @@ -163,10 +163,10 @@ module Body = struct
; num_submatches = t.num_submatches + 1
; to_result =
(fun shift matches ->
( t.to_result (shift + 1) matches
, Option.value_exn
~message:"Re2.Parser.capture bug: failed to capture"
matches.(shift) ))
( t.to_result (shift + 1) matches
, Option.value_exn
~message:"Re2.Parser.capture bug: failed to capture"
matches.(shift) ))
}
;;

Expand Down Expand Up @@ -204,8 +204,7 @@ module Body = struct
~f:(fun x y -> x ^ of_string "|" ^ y)
(List.map ts ~f:(fun t -> Rope.(of_string "()" ^ t.regex_string)))
^ of_string ")")
; num_submatches =
List.sum (module Int) ts ~f:(fun t -> t.num_submatches + 1)
; num_submatches = List.sum (module Int) ts ~f:(fun t -> t.num_submatches + 1)
; to_result =
(let rec go i matches = function
| [] -> failwith "Re2.Parser.or_.to_result bug: called on non-match"
Expand Down Expand Up @@ -248,7 +247,7 @@ module Body = struct
; num_submatches = t.num_submatches + 1
; to_result =
(fun shift matches ->
Option.map matches.(shift) ~f:(fun _ -> t.to_result (shift + 1) matches))
Option.map matches.(shift) ~f:(fun _ -> t.to_result (shift + 1) matches))
}
;;

Expand Down Expand Up @@ -308,11 +307,11 @@ module Body = struct
~f:
([%test_pred: int option * int option * string * string option]
(fun (min, max, inp, result) ->
let a's = capture (repeat ?min ~max (string "a")) in
0
= [%compare: string option]
result
(run (string "c" *> a's <* string "b") inp)))
let a's = capture (repeat ?min ~max (string "a")) in
0
= [%compare: string option]
result
(run (string "c" *> a's <* string "b") inp)))
[ None, None, "caaab", Some "aaa"
; None, None, "cb", Some ""
; Some 0, None, "cb", Some ""
Expand Down
4 changes: 2 additions & 2 deletions src/parser_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ module type Parser = sig

include
Applicative.Let_syntax
with type 'a t := 'a t
with module Open_on_rhs_intf := Open_on_rhs_intf
with type 'a t := 'a t
with module Open_on_rhs_intf := Open_on_rhs_intf

include Open_on_rhs_intf.S with type 'a t := 'a t
end
28 changes: 14 additions & 14 deletions src/regex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ external cre2__valid_rewrite_template
-> string
-> bool
= "mlre2__valid_rewrite_template"
[@@noalloc]
[@@noalloc]

external cre2__escape : string -> string = "mlre2__escape"

Expand Down Expand Up @@ -201,9 +201,9 @@ module Stable = struct
let hash_fold_t state t = Repr.hash_fold_t state (T.to_repr t)

include Comparable.V1.With_stable_witness.Make (struct
include T
include T_serializable_comparable
end)
include T
include T_serializable_comparable
end)
end

module V1_no_options = struct
Expand Down Expand Up @@ -369,7 +369,7 @@ module Substring = struct
(List.fold_left substrings ~init:0 ~f:(fun dst_pos { src; src_pos; len } ->
Bytes.From_string.blit ~src ~src_pos ~dst ~dst_pos ~len;
dst_pos + len)
: int);
: int);
Bytes.unsafe_to_string ~no_mutation_while_string_reachable:dst
;;
end
Expand Down Expand Up @@ -552,7 +552,7 @@ let%expect_test "roundtrip Stable.V2.t_of_sexp and Stable.V2.sexp_of_t" =
; "(cAse ((case_insensitive) (encoding Latin1)))"
]
|> List.iter ~f:(fun s ->
Sexp.of_string_conv_exn s Stable.V2.t_of_sexp |> Stable.V2.sexp_of_t |> print_s);
Sexp.of_string_conv_exn s Stable.V2.t_of_sexp |> Stable.V2.sexp_of_t |> print_s);
[%expect
{|
""
Expand Down Expand Up @@ -595,16 +595,16 @@ let%test_unit "t preserved via Stable.V2.sexp_of_t and Stable.V2.t_of_sexp" =
;;

include Comparable.Make_plain_using_comparator (struct
type nonrec t = t
type nonrec t = t

include Stable.V2.T_serializable_comparable
end)
include Stable.V2.T_serializable_comparable
end)

include Hashable.Make_plain (struct
type nonrec t = t
type nonrec t = t

include Stable.V2.T_serializable_comparable
include Stable.V2.T_serializable_comparable

let hash = Stable.V2.hash
let hash_fold_t = Stable.V2.hash_fold_t
end)
let hash = Stable.V2.hash
let hash_fold_t = Stable.V2.hash_fold_t
end)
6 changes: 2 additions & 4 deletions src/regex_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ runs even faster if nmatch == 0. v}

val find_first_exn : ?sub:id_t -> t -> string -> string


(** [find_submatches t input] finds the first match and returns all submatches.
Element 0 is the whole match and element 1 is the first parenthesized submatch, etc.
*)
Expand Down Expand Up @@ -196,7 +195,6 @@ runs even faster if nmatch == 0. v}
val get_pos_exn : sub:id_t -> t -> int * int
end


(** [get_matches pattern input] returns all non-overlapping matches of [pattern]
against [input]
Expand Down Expand Up @@ -286,8 +284,8 @@ runs even faster if nmatch == 0. v}

include
Stable_comparable.With_stable_witness.V1
with type t := t
and type comparator_witness = comparator_witness
with type t := t
and type comparator_witness = comparator_witness
end

(** [V1_no_options] is the legacy serialization: pattern only, options are lost. *)
Expand Down

0 comments on commit 9f9c1ca

Please sign in to comment.