pub trait Pass {
type Ctx;
// Required method
fn parse(
&self,
source: &str,
span: Span,
ctx: &Self::Ctx,
) -> Outcome<Self::Ctx>;
// Provided method
fn name(&self) -> &'static str { ... }
}Expand description
One stage of a parse schedule.
A pass is a pure function from a source region plus its context to an
Outcome: the region either expands into smaller child regions, is
accepted as parsed, or fails (later passes may retry it).
increparse is deliberately combinator-agnostic: a pass can wrap any
parsing technique — nom, chumsky, a PEG, regexes, or hand-rolled
scanning — behind this trait. The engine only cares about the outcome.
§Contract
- Passes must be pure: they must not mutate shared state and must produce
the same output for the same
(source, span, ctx)input. - Every child span returned from
Outcome::Expandmust be contained in the input span and on the same source revision. By default a child may cover its parent exactly; withEngineConfig::enforce_shrinkit must be strictly smaller. The engine rejects outcomes that violate this, marking the nodeFailed. - Passes must be
Send + Syncso the engine can run batches on anyExecutor.
§Examples
use increparse::{Outcome, Pass, Span};
/// Accepts any region whose text starts with "ok".
struct AcceptOk;
impl Pass for AcceptOk {
type Ctx = ();
fn parse(&self, source: &str, span: Span, _ctx: &()) -> Outcome<()> {
let text = &source[span.to_range()];
if text.starts_with("ok") {
Outcome::Done
} else {
Outcome::Failed
}
}
}Required Associated Types§
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".