Trait som_parser_core::Parser
source · pub trait Parser<T, I>: Sized {
// Required method
fn parse(&mut self, input: I) -> Option<(T, I)>;
// Provided methods
fn and<U, P: Parser<U, I>>(self, parser: P) -> And<Self, P> { ... }
fn or<P: Parser<T, I>>(self, parser: P) -> Or<Self, P> { ... }
fn map<F: Fn(T) -> U, U>(self, func: F) -> Map<Self, F, T> { ... }
fn and_left<P: Parser<U, I>, U>(self, parser: P) -> AndLeft<Self, P, U> { ... }
fn and_right<P: Parser<U, I>, U>(self, parser: P) -> AndRight<Self, P, T> { ... }
}
Expand description
Defines a parser.
It is basically a function that takes an input and returns a parsed result along with the rest of input (which can be parsed further).
Required Methods§
Provided Methods§
sourcefn and<U, P: Parser<U, I>>(self, parser: P) -> And<Self, P>
fn and<U, P: Parser<U, I>>(self, parser: P) -> And<Self, P>
Sequences two parsers, one after the other, collecting both results.
sourcefn or<P: Parser<T, I>>(self, parser: P) -> Or<Self, P>
fn or<P: Parser<T, I>>(self, parser: P) -> Or<Self, P>
Tries to apply the first parser, if it fails, it tries to apply the second parser.
sourcefn map<F: Fn(T) -> U, U>(self, func: F) -> Map<Self, F, T>
fn map<F: Fn(T) -> U, U>(self, func: F) -> Map<Self, F, T>
Maps a function over the output value of the parser.
Object Safety§
This trait is not object safe.
Implementors§
impl<A, B, T, U, I> Parser<T, I> for AndLeft<A, B, U>
impl<A, B, T, U, I> Parser<U, I> for AndRight<A, B, T>
impl<P, T, F, U, I> Parser<U, I> for Map<P, F, T>
impl<T1, T2, A, B, I> Parser<(T1, T2), I> for And<A, B>
impl<T, A, B, I> Parser<T, I> for Or<A, B>
impl<T, F, I> Parser<T, I> for F
Because a Parser
is basically a function of the following signature.
(I) -> (T, I)
We can implement it for any bare Fn(I) -> (T, I)
.