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
Equations
- BoundedBacktracker.CharPos.posInRange s pos = (s.startPos ≤ pos ∧ pos ≤ s.stopPos)
Instances For
Char position in a substring
- pos : String.Pos
current position
char at current position
char at previous position
- isPosInRange : posInRange s self.pos
pos
is in range of substrings
- isValidPos : String.Pos.Valid s.str self.pos
pos
is valid string position ins.str
- isValidSubstring : s.Valid
s
is a valid substring
Instances For
Equations
- BoundedBacktracker.CharPos.PosInRange s = { pos : String.Pos // BoundedBacktracker.CharPos.posInRange s pos ∧ String.Pos.Valid s.str pos }
Instances For
Equations
- BoundedBacktracker.CharPos.Pair s = { p : BoundedBacktracker.CharPos.PosInRange s × BoundedBacktracker.CharPos.PosInRange s // p.fst.val ≤ p.snd.val }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- «at».toSlotEntry = ⟨«at».pos, ⋯⟩
Instances For
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.prevn offset cp = if offset ≤ cp.pos.byteIdx then BoundedBacktracker.CharPos.prevn.loop offset (some cp) else none
Instances For
to next position of cp
Equations
- One or more equations did not get rendered due to their size.
Instances For
Represents a stack frame on the heap while doing backtracking.
- Step
{n : Nat}
{s : Substring}
(sid : Fin n)
(«at» : CharPos s)
: Frame n s
Look for a match starting at
sid
and the given position in the haystack. - RestoreCapture
{n : Nat}
{s : Substring}
(role : NFA.Capture.Role)
(slot : Nat)
(pos : Option (CharPos.PosInRange s))
: Frame n s
Reset the given
slot
to the givenpos
(which might beNone
).
Instances For
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
Equations
- BoundedBacktracker.instInhabitedStackDefaultNatSubstring = { 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
SlotEntry consists of slot, group and char pos in s
Equations
Instances For
Equations
- BoundedBacktracker.SlotsValid s = { slots : Array (BoundedBacktracker.SlotEntry s) // BoundedBacktracker.SearchState.Slots.Valid slots = true }
Instances For
State of the backtracking search
- stack : Stack n input
Stack used on the heap for doing backtracking
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
- at : CharPos input
position in input string
slots, positions of captures in
input
- slotsValid : Slots.Valid self.slots = true
slots are valid
- recentCaptures : Array (Option (String.Pos × String.Pos))
recent captures of capture groups
- logEnabled : Bool
is logging enabled
log msgs
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 and 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
capture groups of consecutive slots are equal
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 matches of each capture group.
Equations
- One or more equations did not get rendered due to their size.