22. Regular expression library

The experimental REGEX module implement regular expression parser and pattern matching functionality.

Currently its in very early stage and implements only very few basic regex operations.

All functions and symbols are in “regex” module, use require to get access to it.

require daslib/regex

22.1. Type aliases

CharSet = uint[8]

Bit array which represents an 8-bit character set.

MaybeReNode is a variant type

value

regex::ReNode ?

nothing

void?

Single regular expression node or nothing.

22.2. Enumerations

ReOp

Char

0

Set

1

Any

2

Eos

3

Group

4

Plus

5

Star

6

Question

7

Concat

8

Union

9

Type of regular expression operation.

ReNode

ReNode fields are

op

regex::ReOp

id

int

fun2

function<(regex: regex::Regex ;node: regex::ReNode ?;str:uint8? const):uint8?>

at

range

text

string

textLen

int

all

array< regex::ReNode ?>

left

regex::ReNode ?

right

regex::ReNode ?

subexpr

regex::ReNode ?

next

regex::ReNode ?

cset

CharSet

index

int

tail

uint8?

Single node in regular expression parsing tree.

Regex

Regex fields are

root

regex::ReNode ?

match

uint8?

groups

array<tuple<range;string>>

earlyOut

CharSet

canEarlyOut

bool

Regular expression.

22.3. Compilation and validation

is_valid(re: Regex)

is_valid returns bool

argument

argument type

re

regex::Regex

returns true if enumeration compiled correctly

regex_compile(re: Regex; expr: string const)

regex_compile returns bool

argument

argument type

re

regex::Regex

expr

string const

Compile regular expression. Validity of the compiled expression is checked by is_valid.

regex_compile(expr: string const)

regex_compile returns regex::Regex

argument

argument type

expr

string const

Compile regular expression. Validity of the compiled expression is checked by is_valid.

regex_compile(re: Regex)

regex_compile returns regex::Regex

argument

argument type

re

regex::Regex

Compile regular expression. Validity of the compiled expression is checked by is_valid.

regex_debug(regex: Regex const)

argument

argument type

regex

regex::Regex const

Prints regular expression and its related information in human readable form.

debug_set(cset: CharSet)

argument

argument type

cset

CharSet

Prints character set in human readable form.

22.4. Access

regex_group(regex: Regex const; index: int const; match: string const)

regex_group returns string

argument

argument type

regex

regex::Regex const

index

int const

match

string const

Returns string for the given group index and match result.

regex_foreach(regex: Regex; str: string const; blk: block<(at:range const):bool> const)

argument

argument type

regex

regex::Regex

str

string const

blk

block<(at:range const):bool> const

Iterates through all matches for the given regular expression in str.

22.5. Match

regex_match(regex: Regex; str: string const; offset: int const)

regex_match returns int

argument

argument type

regex

regex::Regex

str

string const

offset

int const

Returns first match for the regular expression in str. If offset is specified, first that many number of symbols will not be matched.