Expand description
Matchers: grammar fragments used inside crate::parser::capture::Capture (via crate::capture)
and related runners.
§For users
- Matchers describe structure: sequences (
(a, b)),crate::one_of::one_of, repetition (multiple::many,one_or_more(),optional()), lookahead (positive_lookahead(),negative_lookahead()), andcommit_on()for committed sub-rules. - They are composed with parsers through
crate::capture; seecrate::guide::capture_and_binds. - Extend matchers with
MatcherCombinator(with_label,try_insert_if_missing,unwanted, …).
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 returnOk(false)on a normal path (no match).HAS_PROPERTY— may write intoMRes(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_onsucceeds, failure inthen_matcherbecomes a hard error. - err_if
- Matchers that emit
crate::error::InlineErrorwhen an inner pattern matches / does not match. - error_
contextualizer - Enrich
crate::error::FurthestFailErrorfromhappy_matcherusing a smallcrate::parser::Parsercallback. - 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
matcherfails or makes no progress. - negative_
lookahead !e— succeeds whencheckerdoes 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
matcheronce; always reports success (whether or not it matched). - parser_
matcher - Treat a
crate::parser::Parseras acrate::matcher::Matcher: succeed only when parse output equalsexpected_output. - positive_
lookahead &e— succeeds whencheckerwould match, without consuming input (position restored).- sequence
- Sequential composition: tuples
(m1, m2, …)implementcrate::matcher::Matcherby running each arm in order. - string
- Literal string /
&str/charmatchers over achartoken stream. - to_
parser - Matcher-to-parser adapters that return a fixed output.
Traits§
- Matcher
- Facade for matchers over
Tokenthat read and write match state intoMRes. - Matcher
Combinator - Extension methods for matchers (labels, missing-token diagnostics, furthest-failure enrichment).