Regex

lib/Regex.gob

A Builder describes a pattern, compile assembles one into a Pattern, and fullMatch runs a Pattern against a whole string. Capture values are recipes, evaluated only after a successful match. See examples/regex/README.md for semantics, examples, and current limits.

type Builder a
type Pattern a
type Capture a
type Captures

One scope of a match: the entries of the log strictly inside it. It has no Eq: the log holds the whole match, so comparing two would compare far more than the scope.

class Combining f : Applicative f
fun map2 : [Combining f] fun(f a, f b, fun(a, b) -> c) -> f c
class Resolve r
fun resolve : [Resolve r] fun(r, Captures) -> Output r
type Output r
fun capture : fun(Regex.Builder a) -> Regex.Builder (Capture String)

Capture the complete text of a fragment, ignoring its extraction recipe.

fun literal : fun(String) -> Regex.Builder (Capture String)
fun satisfy : fun(fun(Char) -> Bool) -> Regex.Builder (Capture Char)
fun choice : [Resolve a, Resolve b] fun(Regex.Builder a, Regex.Builder b) -> Regex.Builder (Capture (Either (Output a) (Output b)))
infix Choice (<|>) = orElse -- left-associative

a <|> b is orElse(a, b). Both operands are evaluated, which is harmless here: evaluating a Builder only describes a pattern, and nothing runs until it is compiled and matched.

fun orElse : [Resolve a] fun(Regex.Builder a, Regex.Builder a) -> Regex.Builder (Capture (Output a))
fun optional : [Resolve a] fun(Regex.Builder a) -> Regex.Builder (Capture (Option (Output a)))
fun many : [Resolve a] fun(Regex.Builder a) -> Regex.Builder (Capture (Vec (Output a)))
fun some : [Resolve a] fun(Regex.Builder a) -> Regex.Builder (Capture (Vec (Output a)))
fun compile : [Resolve r] fun(Regex.Builder r) -> Pattern r

Assemble b once. Jumps and splits are pointed past any chain of jumps they lead to, so that matching never follows one jump to reach another.

let defaultBudget : Int

How many (instruction, position) pairs the backtracker may keep a bit for by default: 256 KiB of visited set. The set grows with the text, so its cost per character does not; past the budget the Pike VM is about half as fast but needs memory for the pattern alone.

fun fullMatch : [Resolve r] fun(Pattern r, String) -> Option (Output r)
fun fullMatchWithin : [Resolve r] fun(Pattern r, String, Int) -> Option (Output r)

fullMatch, backtracking only if the visited set fits in budget pairs of instruction and position, and otherwise running the Pike VM, whose space is linear in the pattern alone. The two give the same results; the budget trades memory for speed and nothing else.

instance Functor Regex.Builder
instance Applicative Regex.Builder
instance Monad Regex.Builder
instance Functor Capture
instance Applicative Capture
instance Combining Capture
instance Resolve (Capture a)
instance Resolve (a, b) : Resolve a, Resolve b
instance Resolve (a, b, c) : Resolve a, Resolve b, Resolve c
instance Resolve Unit