-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows us to partially match a string and then resume a match from where we've ended.
- Loading branch information
Showing
9 changed files
with
533 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,3 +170,4 @@ include struct | |
end | ||
|
||
module Seq = Search | ||
module Stream = Compile.Stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
open Import | ||
|
||
type t = | ||
{ s : string | ||
; pos : int | ||
; len : int | ||
} | ||
|
||
module L = struct | ||
type nonrec t = t list | ||
|
||
let get_substring slices ~start ~stop = | ||
if stop = start | ||
then "" | ||
else ( | ||
let slices = | ||
let rec drop slices remains = | ||
if remains = 0 | ||
then slices | ||
else ( | ||
match slices with | ||
| [] -> assert false | ||
| ({ s = _; pos; len } as slice) :: xs -> | ||
let remains' = remains - len in | ||
if remains' >= 0 | ||
then drop xs remains' | ||
else ( | ||
let pos = pos + remains in | ||
let len = len - remains in | ||
{ slice with pos; len } :: xs)) | ||
in | ||
drop slices start | ||
in | ||
let buf = Buffer.create (stop - start) in | ||
let rec take slices remains = | ||
if remains > 0 | ||
then ( | ||
match slices with | ||
| [] -> assert false | ||
| { s; pos; len } :: xs -> | ||
let remains' = remains - len in | ||
if remains' > 0 | ||
then ( | ||
Buffer.add_substring buf s pos len; | ||
take xs remains') | ||
else Buffer.add_substring buf s pos remains) | ||
in | ||
take slices (stop - start); | ||
Buffer.contents buf) | ||
;; | ||
|
||
let rec drop t remains = | ||
if remains = 0 | ||
then t | ||
else ( | ||
match t with | ||
| [] -> [] | ||
| ({ s = _; pos; len } as slice) :: t -> | ||
if remains >= len | ||
then drop t (remains - len) | ||
else ( | ||
let delta = len - remains in | ||
{ slice with pos = pos + delta; len = len - delta } :: t)) | ||
;; | ||
|
||
let drop_rev t remains = | ||
(* TODO Use a proper functional queue *) | ||
if remains = 0 then t else List.rev (drop (List.rev t) remains) | ||
;; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
type t = | ||
{ s : string | ||
; pos : int | ||
; len : int | ||
} | ||
|
||
module L : sig | ||
type nonrec t = t list | ||
|
||
val get_substring : t -> start:int -> stop:int -> string | ||
val drop_rev : t -> int -> t | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.