src/regex/nfatype

    Dark Mode
Search:
Group by:

Types used by the NFA

Types

Bounds = Slice[int]
CaptIdx = int32
CaptNode = object
  parent*: CaptIdx
  bound*: int
  idx*: int16
Capts = seq[CaptNode]
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
NodeIdx = int16
PState = tuple[ni: NodeIdx, ci: CaptIdx, bounds: Bounds]
Regex = object
  nfa*: Nfa
  groupsCount*: int16
  namedGroups*: OrderedTable[string, int16]
  flags*: RegexFlags
  litOpt*: LitOpt
deprecated
Regex2 = distinct Regex
a compiled regular expression
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 `[]`(capts: Capts3; i, j: Natural): Slice[int] {.inline, ...raises: [],
    tags: [].}
func `[]`(capts: var Capts3; i, j: Natural): var Slice[int] {.inline,
    ...raises: [], tags: [].}
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(capts: var Capts3) {....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 diverge(capts: var Capts3; captIdx: CaptIdx): CaptIdx {....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 keepAlive(capts: var Capts3; captIdx: CaptIdx) {.inline, ...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: [].}
func unfreeze(capts: var Capts3; freezeId: CaptState) {....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