utils/lrewrap

Types

ExecContext = object
REBytecode = distinct ptr uint8
Regex = object
  bytecode*: string

Procs

proc bytecodeToRegex(p: REBytecode; plen: cint): Regex {....raises: [], tags: [],
    forbids: [].}
proc cap(ctx: ExecContext; i: int): tuple[s, e: int] {....raises: [], tags: [],
    forbids: [].}
proc compileMatchRegex(buf: string): Result[Regex, string] {....raises: [],
    tags: [], forbids: [].}
proc compileRegex(buf: string; flags: LREFlags; regex: var Regex): bool {.
    ...raises: [], tags: [], forbids: [].}

Compile a regular expression using QuickJS's libregexp library. If the result is false, regex.bytecode stores the error message emitted by libregexp instead.

Use exec to actually use the resulting bytecode on a string.

proc initContext(bytecode: REBytecode): ExecContext {....raises: [], tags: [],
    forbids: [].}
proc initContext(regex: Regex): ExecContext {....raises: [], tags: [], forbids: [].}
proc match[T: Regex | REBytecode](regex: T; s: openArray[char]; start = 0): bool {.
    ...raises: [].}
proc matchFirst[T: Regex | REBytecode](regex: T; str: openArray[char]; start = 0): tuple[
    s, e: int] {....raises: [].}
proc matchLast[T: Regex | REBytecode](regex: T; str: openArray[char]; start = 0): tuple[
    s, e: int] {....raises: [].}

Iterators

iterator caps(ctx: ExecContext): tuple[s, e: int] {....raises: [], tags: [],
    forbids: [].}
iterator exec(ctx: var ExecContext; s: openArray[char]; start = 0): cint {.
    ...raises: [], tags: [], forbids: [].}
iterator matchCap(regex: Regex; s: openArray[char]; cap: int; start = 0): tuple[
    s, e: int] {....raises: [], tags: [], forbids: [].}