pub enum CompileError {
Syntax {
pos: usize,
message: String,
},
EmptyMatchable,
StateCap {
limit: usize,
},
Serialize {
message: String,
},
Invalid {
message: String,
},
}Expand description
What: Re-exports the compile-time error type. Why: The surrounding function uses this step to keep the matcher behavior correct at this point.
In TS you’d write (pseudocode):
// Same step as the Rust statement below, written with ordinary TS objects/functions.Reasons a pattern (or a serialized DFA) is rejected before it can match.
What: every failure path in parsing, the empty-match guard, the DFA state
cap, and (de)serialization funnels into one of these variants.
Why: callers (the scanner, tests) get a single typed error to match on, and
compile/new never panic on bad input; they return one of these instead.
In TS you’d write (pseudocode):
type CompileError =
| { kind: "variant" };Variants§
Syntax
A syntax or unsupported-construct rejection at a byte offset.
What: holds the offset into the pattern and a message naming what was wrong (unsupported operator, bad escape, unbalanced bracket, operand not a single atom, mixed operators, stacked quantifier, bad repetition). Why: one variant covers every parse rejection so the surface stays small while still pointing the rule author at the exact spot.
In TS you’d write (pseudocode):
// Same step as the Rust statement below, written with ordinary TS objects/functions.Fields
pos: usizeWhat: Byte offset into the pattern where the problem was detected.
Why: pos stores byte offset into the pattern where the problem was detected, so
matcher code reads that precomputed state by name instead of recomputing or
passing it separately.
In TS you’d write (pseudocode):
pos: number;EmptyMatchable
The pattern can match the empty string, so under unanchored search it would match every input.
What: raised when the parsed root is nullable in some realizable anchor context. Why: such a rule is a footgun (flags every line); rejecting it at compile time is safer than silently matching everything.
In TS you’d write (pseudocode):
// Same step as the Rust statement below, written with ordinary TS objects/functions.StateCap
Determinization produced more states than the configured cap.
What: complement and intersection can blow up the state count on pathological patterns. Why: a hard cap turns that into a clean error instead of unbounded memory use.
In TS you’d write (pseudocode):
// Same step as the Rust statement below, written with ordinary TS objects/functions.Fields
Serialize
Encoding a compiled automaton to bytes failed.
What: wraps a bincode serialization failure as a string. Why: keeps the public error free of a bincode type in its signature.
In TS you’d write (pseudocode):
// Same step as the Rust statement below, written with ordinary TS objects/functions.Fields
Invalid
A deserialized automaton failed structural validation.
What: raised by from_bytes when decoded indices are out of bounds or
lengths are inconsistent. Why: a hostile or corrupt blob must be rejected
before it is ever executed, so the match loop can never read out of
bounds.
In TS you’d write (pseudocode):
// Same step as the Rust statement below, written with ordinary TS objects/functions.Fields
message: StringWhat: Description of which invariant the decoded automaton violated.
Why: message stores description of which invariant the decoded automaton
violated, so matcher code reads that precomputed state by name instead of
recomputing or passing it separately.
In TS you’d write (pseudocode):
message: string;Trait Implementations§
Source§impl Clone for CompileError
impl Clone for CompileError
Source§fn clone(&self) -> CompileError
fn clone(&self) -> CompileError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompileError
impl Debug for CompileError
Source§impl Display for CompileError
What: Renders a CompileError for end users and logs.
Why: The program attaches these functions to the named Rust type so callers can use
method syntax.
impl Display for CompileError
What: Renders a CompileError for end users and logs.
Why: The program attaches these functions to the named Rust type so callers can use
method syntax.
In TS you’d write (pseudocode):
// Methods are written inside a class or as functions that take the value.Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Writes a one-line description of the error.
What: matches each variant to a sentence. Why: Display is what the
scanner surfaces and what Error builds on.
In TS you’d write (pseudocode):
function fmt(f: fmt.Formatter<'_>): fmt.Result {
// Rust body below is the implementation.
}impl Eq for CompileError
Source§impl Error for CompileError
What: Lets CompileError participate in the standard error ecosystem.
Why: The program attaches these functions to the named Rust type so callers can use
method syntax.
impl Error for CompileError
What: Lets CompileError participate in the standard error ecosystem.
Why: The program attaches these functions to the named Rust type so callers can use
method syntax.
In TS you’d write (pseudocode):
// Methods are written inside a class or as functions that take the value.1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()