BoundedBacktracker #
An NFA backed bounded backtracker for executing regex searches with capturing
groups (BoundedBacktracker.slots
).
This regex engine only implements leftmost-first match semantics and only supports leftmost searches. By design, this backtracking regex engine is bounded. This bound is implemented by not visiting any combination of NFA state ID and position in a haystack more than once.
All searches execute in linear time with respect to the size of the regular expression and search text.
make reference of array
Equations
- BoundedBacktracker.Array.Ref.mkRef arr = match ST.Prim.mkRef arr default with | EStateM.Result.ok r a => r
Instances For
get array of reference
Equations
- BoundedBacktracker.Array.Ref.getRefValue ref = match ST.Prim.Ref.get ref default with | EStateM.Result.ok r a => r
Instances For
modify array, try to perform the update destructively
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- BoundedBacktracker.Array.Ref.instInhabitedRefArray_regex = { default := BoundedBacktracker.Array.Ref.mkRef #[] }
Char position in a substring
- s : Substring
substring
- pos : String.Pos
current position
char at current position
char at previous position
Instances For
Equations
- BoundedBacktracker.instInhabitedCharPos = { default := { s := default, pos := default, curr? := none, prev? := none } }
Equations
- One or more equations did not get rendered due to their size.
Equations
- BoundedBacktracker.CharPos.get? s «at» = if «at» < s.stopPos then some (s.get «at») else none
Instances For
create a CharPos from s
and position «at»
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- BoundedBacktracker.CharPos.prevOf offset cp = if offset ≤ cp.pos.byteIdx then let pos := cp.s.prevn offset cp.pos; some (BoundedBacktracker.CharPos.create cp.s pos) else none
Instances For
to next position CharPos of cp
Equations
- One or more equations did not get rendered due to their size.
Instances For
is CharPos at start position
Instances For
is CharPos at stop position
Instances For
Represents a stack frame on the heap while doing backtracking.
- Step: {n : Nat} → Fin n → BoundedBacktracker.CharPos → BoundedBacktracker.Frame n
Look for a match starting at
sid
and the given position in the haystack. - RestoreCapture: {n : Nat} → NFA.Capture.Role → Nat → Nat × Nat × Option String.Pos → BoundedBacktracker.Frame n
Reset the given
slot
to the givenoffset
(which might beNone
).
Instances For
Equations
- One or more equations did not get rendered due to their size.
A representation of "half" of a match reported by a DFA.
- pattern : NFA.PatternID
The pattern ID.
- offset : String.Pos
The offset of the match.
Instances For
Equations
- BoundedBacktracker.instInhabitedHalfMatch = { default := { pattern := 0, offset := 0 } }
Equations
- One or more equations did not get rendered due to their size.
The stack of frames
Equations
Instances For
Push frame to stack
Instances For
pop head frame from stack
Equations
- BoundedBacktracker.Stack.pop? [] = none
- BoundedBacktracker.Stack.pop? (head :: tail) = some (head, tail)
Instances For
append stacks
Equations
- stack1.append [v1, v2] = v2 :: v1 :: stack1
- stack1.append stack2 = (List.reverse stack2).append stack1
Instances For
Equations
- BoundedBacktracker.Stack.toStack arr = arr.toList
Instances For
Equations
- BoundedBacktracker.instInhabitedStackOfNatNat = { default := [] }
The encoded set of (Fin n, HaystackOffset) pairs that have been visited by the backtracker within a single search. Optimization: encode as bits
Equations
Instances For
State of the backtracking search
- stack : BoundedBacktracker.Stack n
Stack used on the heap for doing backtracking
- visited : ST.Ref Nat BoundedBacktracker.Visited
The encoded set of (Fin n, HaystackOffset) pairs that have been visited by the backtracker within a single search.
- countVisited : Nat
count of pairs that have been visited
- sid : Fin n
current state
- input : Substring
input string
position in input string
slots, positions of captures in haystack
- recentCaptures : Array (Option (String.Pos × String.Pos))
recent captures of capture groups
- logEnabled : Bool
is logging enabled
log msgs
- halfMatch : Option BoundedBacktracker.HalfMatch
HalfMatch
- backtracks : Nat
count of backtracks
Instances For
create the SearchState from an NFA
Equations
- One or more equations did not get rendered due to their size.
Instances For
get encoded index of Fin n an CharPos in visited array
Equations
Instances For
Check if current Fin n and CharPos in SearchState is already visited. If not visited mark pair as visited.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check if current Fin n and CharPos in SearchState is already visited. If not visited mark pair as visited.
Equations
- One or more equations did not get rendered due to their size.
Instances For
execute next steps in NFA.
Equations
- BoundedBacktracker.steps nfa state = match BoundedBacktracker.toNextStepChecked nfa state with | (true, state) => BoundedBacktracker.steps.loop nfa state | (false, state) => state
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
BoundedBacktrack search
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Search for the first match of this regex in the haystack given and return log msgs and the slots of each capture group.
Equations
- One or more equations did not get rendered due to their size.