sysl

Module

sysl.regex

Matching text against a pattern: compile one, then find, replace or split with it.

Import import sysl.regex

Compiling is separated from matching because it is the expensive half and a pattern is usually used more than once. Every span a match reports is a byte offset into the input and is always on a character boundary, so s[a..<b] takes one without a boundary check failing; a group that took no part in the match has no span rather than an empty one.

This module is the surface. parse, compile and vm beside it are the engine.

Index

max_program char_class compile compile_pattern describe dump exec exec_from named_class parse parse_counted regex show CharClass CharRange Inst Match NamedClass Node Program Regex RegexError

Constants

max_program

const max_program: u32 = 100000

Functions

char_class

char_class() -> CharClass

compile

compile(root: &Node, groups: int) -> Result[Program, RegexError]

compile_pattern

compile_pattern(pattern: string) -> Result[Program, RegexError]

describe

describe(e: RegexError) -> string

dump

dump(p: Program) -> string

exec

exec(prog: Program, input: string) -> Option[[]int]

exec_from

exec_from(prog: Program, input: string, from: usize) -> Option[[]int]

named_class

named_class(name: string) -> Option[NamedClass]

parse

parse(pattern: string) -> Result[&Node, RegexError]

parse_counted

parse_counted(pattern: string) -> Result[(&Node, int), RegexError]

regex

regex(pattern: string) -> Result[Regex, RegexError]

show

show(n: &Node) -> string

Types

CharClass

struct CharClass
    ranges: &Buf[CharRange]
    names: &Buf[NamedClass]
    negated: bool
MemberSignatureDescription
admitsadmits(self, c: char) -> bool

CharRange

struct CharRange
    lo: u32
    hi: u32

Inst

enum Inst
    MatchChar(ch: char)
    MatchAny
    MatchSet(of: CharClass)
    Accept
    Jump(to: usize)
    Split(first: usize, second: usize)
    Save(slot: usize)
    AssertStart
    AssertEnd

Match

struct Match
    src: string
    slots: []int
MemberSignatureDescription
group_countgroup_count(self) -> usize
spanspan(self, i: usize) -> Option[(usize, usize)]
groupgroup(self, i: usize) -> Option[string]
texttext(self) -> string
startstart(self) -> usize
endend(self) -> usize

NamedClass

enum NamedClass
    Alpha
    Digit
    Alnum
    Upper
    Lower
    Space
    Blank
    Print
    Graph
    Cntrl
    Punct
    XDigit

Node

enum Node
    Empty
    Lit(ch: char)
    AnyChar
    AtStart
    AtEnd
    InSet(of: CharClass)
    Seq(left: &Node, right: &Node)
    Alt(left: &Node, right: &Node)
    Star(inner: &Node)
    Plus(inner: &Node)
    Quest(inner: &Node)
    Group(inner: &Node, index: int)

Program

struct Program
    code: &Buf[Inst]
    groups: int
    over: bool
MemberSignatureDescription
lenlen(self) -> usize
atat(self, pc: usize) -> Inst
slotsslots(self) -> usize
emitemit(*self, i: Inst) -> usize
patchpatch(*self, pc: usize, i: Inst)

Regex

struct Regex
    pattern: string
    prog: Program
MemberSignatureDescription
group_countgroup_count(self) -> int
findfind(self, s: string) -> Option[Match]
find_atfind_at(self, s: string, from: usize) -> Option[Match]
is_matchis_match(self, s: string) -> bool
find_allfind_all(self, s: string) -> &Buf[Match]
replace_allreplace_all(self, s: string, with: string) -> string
splitsplit(self, s: string) -> &Buf[string]

RegexError

enum RegexError
    TrailingBackslash(at: usize)
    UnterminatedClass(at: usize)
    UnterminatedClassName(at: usize)
    UnknownClassName(at: usize, name: string)
    UnterminatedGroup(at: usize)
    UnmatchedParen(at: usize)
    UnterminatedInterval(at: usize)
    MissingIntervalCount(at: usize)
    BackwardsInterval(at: usize)
    BackwardsRange(at: usize)
    NothingToRepeat(at: usize)
    PatternTooLarge

Search

Esc
↑↓ to navigate ↵ to open Esc to close