Types used by the NFA
Types
Bounds = Slice[int]
CaptIdx = int32
Capts3 = object s: seq[Slice[int]] groupsLen: Natural blockSize: Natural blockSizeL2: Natural states: seq[CaptState] free: seq[CaptIdx] freezeId: CaptState
- Seq of captures divided into blocks of power of 2 len. One block per parallel state. A seq/set to keep track of used blocks. A seq of free blocks for reusing
CaptState = uint8
Captures = seq[seq[Slice[int]]]
MatchFlag = enum mfShortestMatch, mfNoCaptures, mfFindMatch, mfFindMatchOpt, mfAnchored, mfBwMatch, mfReverseCapts, mfBytesInput
MatchFlags = set[MatchFlag]
NodeIdx = int16
Regex = object nfa*: Nfa groupsCount*: int16 namedGroups*: OrderedTable[string, int16] flags*: RegexFlags litOpt*: LitOpt
- deprecated
RegexLit = distinct string
- raw regex literal string
RegexMatch = object captures*: Captures namedGroups*: OrderedTable[string, int16] boundaries*: Slice[int]
- deprecated
RegexMatch2 = object captures*: seq[Slice[int]] namedGroups*: OrderedTable[string, int16] boundaries*: Slice[int]
- result from matching operations
SmLookaround = object s: seq[SmLookaroundItem] i: int
SmLookaroundItem = object a, b: Submatches
Submatches = ref object sx: seq[PState] ss: seq[int16] si: int16
- Parallel states would be a better name. This is a sparse set
Consts
nonCapture = (a: -1, b: -2)
Procs
func `[]`(sm: Submatches; i: int): PState {.inline, ...raises: [], tags: [].}
func add(sm: var Submatches; item: PState) {.inline, ...raises: [], tags: [].}
func cap(sm: Submatches): int {.inline, ...raises: [], tags: [].}
func clear(m: var RegexMatch) {.inline, ...raises: [], tags: [].}
func clear(m: var RegexMatch2) {.inline, ...raises: [], tags: [].}
func clear(sm: var Submatches) {.inline, ...raises: [], tags: [].}
func constructSubmatches(captures: var Captures; capts: Capts; capt, size: int) {. inline, ...raises: [], tags: [].}
func freeze(capts: var Capts3): CaptState {....raises: [], tags: [].}
- Freeze all in use capts. Return freezeId
func grow(sm: var SmLookaround) {.inline, ...raises: [], tags: [].}
func hasState(sm: Submatches; n: int16): bool {.inline, ...raises: [], tags: [].}
func initCapts3(groupsLen: int): Capts3 {....raises: [], tags: [].}
func len(sm: Submatches): int {.inline, ...raises: [], tags: [].}
func newSubmatches(size: int): Submatches {.inline, ...raises: [], tags: [].}
func notRecyclable(capts: var Capts3; captIdx: CaptIdx) {....raises: [], tags: [].}
func recyclable(capts: var Capts3; captIdx: CaptIdx) {.inline, ...raises: [], tags: [].}
func recycle(capts: var Capts3) {....raises: [], tags: [].}
- Free recyclable entries Set initial/keepAlive entries to recyclable
func removeLast(sm: var SmLookaround) {.inline, ...raises: [], tags: [].}
func reverse(capts: var Capts; a, b: CaptIdx): CaptIdx {....raises: [], tags: [].}
- reverse capture indices from a to b; return head
func setLen(item: var SmLookaroundItem; size: int) {.inline, ...raises: [], tags: [].}
func setLen(sm: var Submatches; size: int) {.inline, ...raises: [], tags: [].}
func toMatchFlags(f: RegexFlags): MatchFlags {....raises: [], tags: [].}
Iterators
iterator items(sm: Submatches): PState {.inline, ...raises: [], tags: [].}
Templates
template last(sm: SmLookaround): untyped
template lastA(sm: SmLookaround): untyped
template lastB(sm: SmLookaround): untyped
template toRegex(r): untyped
template toRegex2(r): untyped