Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230//! What: The derivative-regex node algebra.//! Why: This file is the Rust module that groups the node implementation, so the//! compiler gives those items one namespace and sibling modules can import that name.//!//! In TS you'd write (pseudocode)://! ```ts//! // module node: see exported functions and types below.//! ```
/// What: Imports the byte-set leaf type used by `Class` nodes./// Why: The code below uses `ByteSet` directly; importing from `crate/charset` keeps each/// call site focused on the matcher logic instead of the full Rust path.////// In TS you'd write (pseudocode):/// ```ts/// import { ByteSet } from "crate/charset";/// ```use crate::charset::ByteSet;
/// A regular expression as a value that derivatives transform.////// What: a small algebra closed under Brzozowski derivatives, including the/// boolean operators `Inter` (intersection) and `Comp` (complement) plus the/// distinguished constants `Empty` (epsilon), `Fail` (the empty language), and/// `Top` (every string). Why: derivatives map each variant to another node, so/// the same type represents both the parsed pattern and every residual state;/// `Eq`/`Ord`/`Hash` let smart constructors dedup and sort, and let the DFA/// builder intern states.////// In TS you'd write (pseudocode):/// ```ts/// type Node =/// | { kind: "variant" };/// ```#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]pub enum Node { /// What: Matches the empty string (epsilon). /// Why: The surrounding function uses this step to keep the matcher behavior correct /// at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Empty, /// What: Matches nothing (the empty language); arises as a dead derivative. /// Why: The surrounding function uses this step to keep the matcher behavior correct /// at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Fail, /// What: Matches every string (sigma star); arises from complement and as the /// unanchored-search prefix. /// Why: The surrounding function uses this step to keep the matcher behavior correct /// at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Top, /// What: Matches one byte drawn from the set. What: literals, `.`, `[...]`, and the /// shorthands all reduce to this. /// Why: The surrounding function uses this step to keep the matcher behavior correct /// at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Class( /// What: Byte set the matched byte must belong to. /// Why: The surrounding function uses this step to keep the matcher behavior /// correct at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` ByteSet, ), /// What: Sequence: each child matches in order. /// Why: The surrounding function uses this step to keep the matcher behavior correct /// at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Concat( /// What: Ordered factors matched one after another. /// Why: The surrounding function uses this step to keep the matcher behavior /// correct at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Vec<Node>, ), /// What: Alternation: any one child matches. /// Why: The surrounding function uses this step to keep the matcher behavior correct /// at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Alt( /// What: Branches, any one of which may match. /// Why: The surrounding function uses this step to keep the matcher behavior /// correct at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Vec<Node>, ), /// What: Intersection: every child must match the same input. /// Why: The surrounding function uses this step to keep the matcher behavior correct /// at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Inter( /// What: Operands that must all match the same input. /// Why: The surrounding function uses this step to keep the matcher behavior /// correct at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Vec<Node>, ), /// What: Complement: matches exactly the strings the child does not. /// Why: The surrounding function uses this step to keep the matcher behavior correct /// at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Comp( /// What: Inner expression whose language is complemented. /// Why: The surrounding function uses this step to keep the matcher behavior /// correct at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Box<Node>, ), /// Bounded repetition: match the child between `min` and `max` times. /// /// What: kept un-unrolled so a counter register, not DFA states, carries the /// count. Why: unrolling `{n,m}` bakes the count into the automaton and blows /// it up exponentially under unanchored search. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` Repeat { /// What: Repeated sub-expression. /// Why: `node` stores repeated sub-expression, so matcher code reads that /// precomputed state by name instead of recomputing or passing it separately. /// /// In TS you'd write (pseudocode): /// ```ts /// node: Node; /// ``` node: Box<Node>, /// What: Minimum number of repetitions still required. /// Why: `min` stores minimum number of repetitions still required, so matcher code /// reads that precomputed state by name instead of recomputing or passing it /// separately. /// /// In TS you'd write (pseudocode): /// ```ts /// min: number; /// ``` min: usize, /// What: Maximum number of repetitions still allowed. /// Why: `max` stores maximum number of repetitions still allowed, so matcher code /// reads that precomputed state by name instead of recomputing or passing it /// separately. /// /// In TS you'd write (pseudocode): /// ```ts /// max: number; /// ``` max: usize, }, /// What: Zero-width `^`: nullable only at a line start. /// Why: The surrounding function uses this step to keep the matcher behavior correct /// at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` LineStart, /// What: Zero-width `$`: nullable only at a line end. /// Why: The surrounding function uses this step to keep the matcher behavior correct /// at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` LineEnd, /// What: Zero-width `\b`: nullable only where word-ness changes. /// Why: The surrounding function uses this step to keep the matcher behavior correct /// at this point. /// /// In TS you'd write (pseudocode): /// ```ts /// // Same step as the Rust statement below, written with ordinary TS objects/functions. /// ``` WordBoundary,}