pub struct Match<'t> { /* private fields */ }
Expand description
This is a node in a parse tree. It is functionally similar to regex::Match
,
in fact providing much the same API, but unlike a regex::Match
a pidgin::Match
always corresponds to some rule, it knows what rule it corresponds to,
and it records any sub-matches involved in its parsing.
The lifetime parameter 't
represents the lifetime of the &str
matched
against.
Implementations§
source§impl<'t> Match<'t>
impl<'t> Match<'t>
sourcepub fn name(&self, name: &str) -> Option<&Match<'_>>
pub fn name(&self, name: &str) -> Option<&Match<'_>>
Returns the first Match
defined by the given rule under this parse
node searching recursively, depth-first, left-to-right.
sourcepub fn all_names(&self, name: &str) -> Vec<&Match<'_>> ⓘ
pub fn all_names(&self, name: &str) -> Vec<&Match<'_>> ⓘ
Returns all Match
es matching the given rule in the parse tree under
this node. Matches are ordered as found by a depth-first left-to-right
search of the parse tree.
sourcepub fn has(&self, name: &str) -> bool
pub fn has(&self, name: &str) -> bool
Returns whether the given rule matched for any node in the parse tree.
Examples
let mut p = Pidgin::new();
let g = p.grammar(&vec!["cat", "dog", "camel"]);
p.rule("animal", &g);
let g = p.grammar(&vec!["carpet", "crate", "cartoon"]);
p.rule("thing", &g);
let m = p.grammar(&vec!["animal", "thing"]).matcher()?;
assert!(m.parse("cat").unwrap().has("animal"));
Trait Implementations§
source§impl<'t> Ord for Match<'t>
impl<'t> Ord for Match<'t>
source§impl<'t> PartialOrd<Match<'t>> for Match<'t>
impl<'t> PartialOrd<Match<'t>> for Match<'t>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more