Struct pidgin::Match [−][src]
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
impl<'t> Match<'t>
[src]
pub fn as_str(&self) -> &'t str
[src]
Returns the matched text.
Examples
let m = grammar!{ foo => ("bar") }.matcher()?.parse(" bar ").unwrap(); assert_eq!("bar", m.as_str());
pub fn start(&self) -> usize
[src]
Returns the starting offset of the match.
Examples
let m = grammar!{ foo => ("bar") }.matcher()?.parse(" bar ").unwrap(); assert_eq!(3, m.start());
pub fn end(&self) -> usize
[src]
Returns the ending offset of the match.
Examples
let m = grammar!{ foo => ("bar") }.matcher()?.parse(" bar ").unwrap(); assert_eq!(6, m.end());
pub fn rule(&self) -> &str
[src]
Returns the grammar rule matched.
Examples
let m = grammar!{ foo => ("bar") }.matcher()?.parse(" bar ").unwrap(); assert_eq!("foo", m.rule());
pub fn children(&self) -> Option<&[Match<'t>]>
[src]
Returns the sub-matches of this match, if any.
Examples
let m = grammar!{ TOP -> <foo> <bar> <baz> foo => (1) bar => (2) baz => (3) }.matcher()?.parse(" 1 2 3 ").unwrap(); let children = m.children().unwrap(); assert_eq!(3, children.len()); assert_eq!("1", children[0].as_str()); assert_eq!("foo", children[0].rule()); assert_eq!("2", children[1].as_str()); assert_eq!("bar", children[1].rule()); assert_eq!("3", children[2].as_str()); assert_eq!("baz", children[2].rule());
pub fn name(&self, name: &str) -> Option<&Match<'_>>
[src]
Returns the first Match
defined by the given rule under this parse
node searching recursively, depth-first, left-to-right.
Examples
let matcher = grammar!{ TOP -> <foo> <bar> foo -> (1) <baz> bar -> (2) <baz> baz -> [["prawn", "shrimp", "crevette"]] }.matcher()?; let p = matcher.parse("1 crevette 2 shrimp").unwrap(); let baz = p.name("baz").unwrap(); assert_eq!("crevette", baz.as_str());
pub fn all_names(&self, name: &str) -> Vec<&Match<'_>>
[src]
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.
Examples
let matcher = grammar!{ TOP -> <foo> <bar> foo -> (1) <baz> bar -> (2) <baz> baz -> [["prawn", "shrimp", "crevette"]] }.matcher()?; let p = matcher.parse("1 crevette 2 shrimp").unwrap(); let names = p.all_names("baz"); assert_eq!("crevette", names[0].as_str()); assert_eq!("shrimp", names[1].as_str());
pub fn has(&self, name: &str) -> bool
[src]
Returns whether the given rule matched for any node in the parse tree.
Examples
let g = grammar!{ TOP => <animal> | <thing> animal => [["cat", "dog", "camel"]] thing => [["carpet", "crate", "cartoon"]] }; let m = g.matcher()?; assert!(m.parse("cat").unwrap().has("animal"));
Trait Implementations
impl<'t> Clone for Match<'t>
[src]
impl<'t> Debug for Match<'t>
[src]
impl<'t> Display for Match<'t>
[src]
impl<'t> Eq for Match<'t>
[src]
impl<'t> Ord for Match<'t>
[src]
fn cmp(&self, other: &Match<'t>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<'t> PartialEq<Match<'t>> for Match<'t>
[src]
fn eq(&self, other: &Match<'t>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'t> PartialOrd<Match<'t>> for Match<'t>
[src]
Auto Trait Implementations
impl<'t> RefUnwindSafe for Match<'t>
impl<'t> Send for Match<'t>
impl<'t> Sync for Match<'t>
impl<'t> Unpin for Match<'t>
impl<'t> UnwindSafe for Match<'t>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,