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.

ReGenRandom = iterator<uint>

random generator input for the regular expression generation

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?>

gen2

function<(node: regex::ReNode ?;rnd: ReGenRandom ;str: strings::StringBuilderWriter ):void>

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

visit_top_down(node: ReNode?; blk: block<(var n:ReNode?):void> const)

argument

argument type

node

regex::ReNode ?

blk

block<(n: regex::ReNode ?):void> const

visits parsed regular expression tree, parents first

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.

22.6. Generation

re_gen_get_rep_limit()

re_gen_get_rep_limit returns uint

repetition limit for the ‘+’ and ‘*’ operations of the regex generation

re_gen(re: Regex; rnd: ReGenRandom)

re_gen returns string

argument

argument type

re

regex::Regex

rnd

ReGenRandom

generates random string which would match regular expression

22.7. Uncategorized

regex_replace(regex: Regex; str: string const; blk: block<(at:string const):string> const)

regex_replace returns string const

argument

argument type

regex

regex::Regex

str

string const

blk

block<(at:string const):string> const

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