Skip to content

Commit

Permalink
refactor: remove some pointless aliases in [Str] (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrinberg authored Aug 30, 2024
1 parent d29a5aa commit 0113a0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
1 change: 0 additions & 1 deletion lib/cset.mli
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ val cntrl : t
val graph : t
val print : t
val punct : t

val pp : Format.formatter -> t -> unit
val one_char : t -> c option
val fold_right : t -> init:'acc -> f:(c * c -> 'acc -> 'acc) -> 'acc
Expand Down
31 changes: 20 additions & 11 deletions lib/str.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,32 @@

(* $Id: re_str.ml,v 1.3 2002/07/03 15:47:54 vouillon Exp $ *)

module Re = Core
module Ast = Ast.Export

include struct
open Core

let exec = exec
let exec_partial = exec_partial
end

type regexp =
{ mtch : Re.re Lazy.t
; srch : Re.re Lazy.t
{ mtch : Compile.re Lazy.t
; srch : Compile.re Lazy.t
}

let compile_regexp s c =
let re = Emacs.re ~case:(not c) s in
{ mtch = lazy (Re.compile (Re.seq [ Re.start; re ])); srch = lazy (Re.compile re) }
{ mtch = lazy (Compile.compile (Ast.seq [ Ast.start; re ]))
; srch = lazy (Compile.compile re)
}
;;

let state = ref None

let string_match re s p =
try
state := Some (Re.exec ~pos:p (Lazy.force re.mtch) s);
state := Some (exec ~pos:p (Lazy.force re.mtch) s);
true
with
| Not_found ->
Expand All @@ -40,17 +49,17 @@ let string_match re s p =
;;

let string_partial_match re s p =
match Re.exec_partial ~pos:p (Lazy.force re.mtch) s with
match exec_partial ~pos:p (Lazy.force re.mtch) s with
| `Full -> string_match re s p
| `Partial -> true
| `Mismatch -> false
;;

let search_forward re s p =
try
let res = Re.exec ~pos:p (Lazy.force re.srch) s in
let res = exec ~pos:p (Lazy.force re.srch) s in
state := Some res;
fst (Re.Group.offset res 0)
fst (Group.offset res 0)
with
| Not_found ->
state := None;
Expand All @@ -59,7 +68,7 @@ let search_forward re s p =

let rec search_backward re s p =
try
let res = Re.exec ~pos:p (Lazy.force re.mtch) s in
let res = exec ~pos:p (Lazy.force re.mtch) s in
state := Some res;
p
with
Expand All @@ -74,12 +83,12 @@ let valid_group n =
&&
match !state with
| None -> false
| Some m -> n < Re.Group.nb_groups m
| Some m -> n < Group.nb_groups m
;;

let offset_group i =
match !state with
| Some m -> Re.Group.offset m i
| Some m -> Group.offset m i
| None -> raise Not_found
;;

Expand Down

0 comments on commit 0113a0c

Please sign in to comment.