Skip to content

Regex Compiler

Spice
import "std/text/regex-compiler";

Functions

compileToProgram

Spice
public f<RegexProgram> compileToProgram(RegexNode* root, long groupCount)

Thompson-construction compiler: turns a regex AST (see "std/text/regex/regex-ast") into a RegexProgram (see "std/text/regex/regex-program") that "std/text/regex/regex-matcher" can run.

Instructions are appended directly to the program's instruction list (rather than compiling each sub-expression into its own fragment and splicing it in), with forward jump/split targets back-patched once they become known - this keeps every local in this file a plain long index, so there is nothing here that a mid-function return could leak.

Parameters

Name Type Description
root RegexNode*
groupCount long

Returns: RegexProgram