Skip to main content

Module term

Module term 

Source
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 a Ctx that 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 continuation k (everything that follows): (?=X)·k has the language (X·Σ*) ∩ k and (?!X)·k has ¬(X·Σ*) ∩ k, so d((?=X)·k) = d(X·Σ*) ∩ d(k). A lookahead left at the very end of a term holds iff X accepts 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 of X. It is answered by a tracker automaton for Σ*·X kept 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.
TermStore
Interning store and derivative engine.

Enums§

AssertKind
Zero-width assertions on the neighbouring characters.
TermKind
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.