Expand description
Extended regular-expression terms with Brzozowski derivatives (architecture section 3, FR-B01, FR-B02, FR-B07, FR-B08).
Contract: terms live in a TermStore that interns them, so equal terms
share one TermId. Smart constructors keep terms normalised: unions and
intersections are flattened, sorted and de-duplicated, concatenation is
right-nested, Empty/Epsilon are absorbed, and Star(Star(x)) = Star(x),
Not(Not(x)) = x. Derivatives of normalised terms stay inside a finite set,
which is what makes the automaton construction terminate.
Zero-width constructs (M6):
Assert(anchors, word boundaries) are evaluated against aCtxthat remembers whether the input just started, which auxiliary character sets the previous character belonged to, and the state of every lookbehind tracker. The derivative therefore takes the context and the next character; at the end of input, acceptance is evaluated with no next character.LookAhead(X)has no meaning on its own: whatever follows it in the enclosing pattern decides. Its derivative is therefore computed with an explicit continuationk(everything that follows):(?=X)·khas the language(X·Σ*) ∩ kand(?!X)·khas¬(X·Σ*) ∩ k, sod((?=X)·k) = d(X·Σ*) ∩ d(k). A lookahead left at the very end of a term holds iffXaccepts the empty remainder. Recursion through zero-width loops is cut with a re-entrancy guard that returns the empty language, which is the least fixpoint of the (monotone) equations.LookBehind(X)holds iff the consumed input ends with a match ofX. It is answered by a tracker automaton forΣ*·Xkept in the context.
Invariants: every Class set is non-empty and a subset of the universe;
Not complements relative to universe*; lookbehind bodies contain no
context-dependent construct.
Failure modes: constructors are total and never panic. Registering more
than MAX_AUX distinct auxiliary sets or MAX_TRACKERS lookbehinds
returns None so the caller can report RX-U005.
Structs§
- Ctx
- What the matcher has seen before the current position.
- TermId
- Handle to an interned term.
- Term
Store - Interning store and derivative engine.
Enums§
- Assert
Kind - Zero-width assertions on the neighbouring characters.
- Term
Kind - Shape of a term.
Constants§
- MAX_AUX
- Most distinct auxiliary sets (word / newline definitions) in one store.
- MAX_
TRACKERS - Most lookbehind trackers in one store.
- NO_AUX
- Marks an unused auxiliary-set slot in an assertion.
- NO_CTX
- Id of the context used for terms that do not depend on context.