Skip to main content

Module matcher

Module matcher 

Source
Expand description

Matchers: grammar fragments used inside crate::parser::capture::Capture (via crate::capture) and related runners.

§For users

Concept guides: crate::guide::core_concepts, crate::guide::errors_and_recovery, crate::guide::common_patterns.

§Parameters and sealing

Matcher is parameterized by MRes, the “match result” type that captures bound values and spans (typically a tuple bucket produced by crate::parser::capture::Capture). You compose matchers rather than implementing Matcher yourself: it extends a crate-private implementation trait (not public API).

§Associated constants

  • CAN_FAIL — may return Ok(false) on a normal path (no match).
  • HAS_PROPERTY — may write into MRes (captures).
  • CAN_MATCH_DIRECTLY — optimization hint for the runner.

CAN_FAIL does not indicate whether Err with crate::error::MatcherRunError is possible.

Re-exports§

pub use crate::error::MatcherRunError;
pub use any_token::AnyToken;
pub use commit_matcher::CommitMatcher;
pub use commit_matcher::commit_on;
pub use err_if::ErrIfMatchedMatcher;
pub use err_if::ErrIfNoMatchMatcher;
pub use err_if::err_if_matched;
pub use err_if::err_if_no_match;
pub use err_if::try_insert_if_missing;
pub use err_if::unwanted;
pub use error_contextualizer::ErrorContextualizer;
pub use multiple::Multiple;
pub use multiple::many;
pub use negative_lookahead::NegativeLookahead;
pub use negative_lookahead::negative_lookahead;
pub use one_or_more::OneOrMore;
pub use one_or_more::one_or_more;
pub use optional::Optional;
pub use optional::optional;
pub use parser_matcher::ParserMatcher;
pub use positive_lookahead::PositiveLookahead;
pub use positive_lookahead::positive_lookahead;
pub use string::StringMatcher;
pub use to_parser::ToParser;

Modules§

any_token
Unconditional single-token consumption (if any input remains).
commit_matcher
Committing sequence: after commit_on succeeds, failure in then_matcher becomes a hard error.
err_if
Matchers that emit crate::error::InlineError when an inner pattern matches / does not match.
error_contextualizer
Enrich crate::error::FurthestFailError from happy_matcher using a small crate::parser::Parser callback.
if_error
Matchers and parsers that only participate while real error handling is active.
ignore_result
Parser-as-matcher adapters that discard parser output.
multiple
Zero-or-more repetition matcher; stops when matcher fails or makes no progress.
negative_lookahead
!e — succeeds when checker does not match at the current position (no input consumed).
none_of
Helpers for “match any token except …” patterns.
one_or_more
One-or-more repetition (matcher+).
optional
Optional matcher: tries matcher once; always reports success (whether or not it matched).
parser_matcher
Treat a crate::parser::Parser as a crate::matcher::Matcher: succeed only when parse output equals expected_output.
positive_lookahead
&e — succeeds when checker would match, without consuming input (position restored).
sequence
Sequential composition: tuples (m1, m2, …) implement crate::matcher::Matcher by running each arm in order.
string
Literal string / &str / char matchers over a char token stream.
to_parser
Matcher-to-parser adapters that return a fixed output.

Traits§

Matcher
Facade for matchers over Token that read and write match state into MRes.
MatcherCombinator
Extension methods for matchers (labels, missing-token diagnostics, furthest-failure enrichment).