pub struct Parser<'a, T, E, F = ()> { /* private fields */ }Expand description
A parser is a function from a State to a ParseResult.
The T type is the type of the value produced by the parser, the E is the
type of the errors it can produce. F is the type of failure - this is like
an error, but made to be used for backtracking. It is optional.
The 'a lifetime is the lifetime of the parser.
Implementations§
Source§impl<'a, T, E, F> Parser<'a, T, E, F>
impl<'a, T, E, F> Parser<'a, T, E, F>
pub fn ret(value: T) -> Selfwhere
T: Clone + 'a,
pub fn ret_with(value: impl Fn() -> T + 'a) -> Self
pub fn fail(value: F) -> Selfwhere
F: Clone + 'a,
pub fn fail_with(value: impl Fn() -> F + 'a) -> Self
pub fn err(value: E) -> Selfwhere
E: Clone + 'a,
pub fn err_with(value: impl Fn() -> E + 'a) -> Self
pub fn from_fn<Func>(func: Func) -> Self
pub fn parse(&self, state: State<'a>) -> ParseResult<T, E, F>
pub fn map<U>(self, f: impl Fn(T) -> U + 'a) -> Parser<'a, U, E, F>where
F: 'a,
E: 'a,
T: 'a,
pub fn map_fail<G>(self, f: impl Fn(F) -> G + 'a) -> Parser<'a, T, E, G>where
F: 'a,
E: 'a,
T: 'a,
pub fn map_err<E2>(self, f: impl Fn(E) -> E2 + 'a) -> Parser<'a, T, E2, F>where
F: 'a,
E: 'a,
T: 'a,
pub fn and_then<U, Func>(self, func: Func) -> Parser<'a, U, E, F>
Sourcepub fn and_then_fail<G, Func>(self, func: Func) -> Parser<'a, T, E, G>
pub fn and_then_fail<G, Func>(self, func: Func) -> Parser<'a, T, E, G>
This is like and_then, but the next parser is called when the first
parser fails.
Unlike and_then, the next parser is started at the same position as
the first parser (not at the position that it stopped).
Sourcepub fn and_then_err<E2, Func>(self, func: Func) -> Parser<'a, T, E2, F>
pub fn and_then_err<E2, Func>(self, func: Func) -> Parser<'a, T, E2, F>
This is like and_then, but the next parser is called when the first
parser returns an error (Notice - this is different from failure).
Unlike and_then, the next parser is started at the same position as
the first parser (not at the position that it stopped).
pub fn or<G, H>(self, other: Parser<'a, T, E, G>) -> Parser<'a, T, E, H>where
T: 'a,
E: 'a,
F: 'a + CombineFail<'a, G, H>,
G: 'a,
pub fn or_ret<G>(self, x: T) -> Parser<'a, T, E, G>where
T: Clone + 'a,
E: 'a,
F: 'a,
G: 'a,
pub fn or_fail<G>(self, f: G) -> Parser<'a, T, E, G>where
T: 'a,
E: 'a,
F: 'a,
G: Clone + 'a,
pub fn or_err<G>(self, e: E) -> Parser<'a, T, E, G>where
T: 'a,
E: Clone + 'a,
F: 'a,
G: 'a,
pub fn one_of<G>(
parsers: impl IntoIterator<Item = Parser<'a, T, E, F>> + 'a,
) -> Parser<'a, T, E, G>where
T: 'a,
E: 'a,
F: 'a + CombineManyFail<'a, G>,
G: 'a,
pub fn filter(self, pred: impl Fn(&T) -> bool + 'a) -> Self
Source§impl<'a, E: 'a> Parser<'a, char, E, NotWhitespace>
impl<'a, E: 'a> Parser<'a, char, E, NotWhitespace>
pub fn whitespace() -> Parser<'a, char, E, NotWhitespace>
Source§impl<'a, F: 'a, E: 'a> Parser<'a, (), E, F>
impl<'a, F: 'a, E: 'a> Parser<'a, (), E, F>
pub fn skip_whitespace() -> Parser<'a, (), E, F>
Source§impl<'a, T, F, E> Parser<'a, T, E, F>
impl<'a, T, F, E> Parser<'a, T, E, F>
Trait Implementations§
Auto Trait Implementations§
impl<'a, T, E, F> Freeze for Parser<'a, T, E, F>
impl<'a, T, E, F = ()> !RefUnwindSafe for Parser<'a, T, E, F>
impl<'a, T, E, F = ()> !Send for Parser<'a, T, E, F>
impl<'a, T, E, F = ()> !Sync for Parser<'a, T, E, F>
impl<'a, T, E, F> Unpin for Parser<'a, T, E, F>
impl<'a, T, E, F = ()> !UnwindSafe for Parser<'a, T, E, F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<F1, F2> CombineFail<'_, F2, ()> for F1
impl<F1, F2> CombineFail<'_, F2, ()> for F1
fn combine_fail(self, _: State<'_>, _: F2, _: State<'_>)
Source§impl<F1, F2> CombineFail<'_, F2, (F1, F2)> for F1
impl<F1, F2> CombineFail<'_, F2, (F1, F2)> for F1
Source§impl<'a, F1, F2> CombineFail<'a, F2, (F1, State<'a>, F2, State<'a>)> for F1
impl<'a, F1, F2> CombineFail<'a, F2, (F1, State<'a>, F2, State<'a>)> for F1
Source§impl<F> CombineManyFail<'_, ()> for F
impl<F> CombineManyFail<'_, ()> for F
fn combine_many_fail(_: Vec<(F, State<'_>)>)
Source§impl<F> CombineManyFail<'_, Vec<F>> for F
impl<F> CombineManyFail<'_, Vec<F>> for F
Source§impl<'a, F> CombineManyFail<'a, Vec<(F, State<'a>)>> for F
impl<'a, F> CombineManyFail<'a, Vec<(F, State<'a>)>> for F
Source§impl<X> Pipe for X
impl<X> Pipe for X
Source§fn pipe_ref<'a, Return, Function>(&'a self, f: Function) -> Returnwhere
Function: FnOnce(&'a Self) -> Return,
fn pipe_ref<'a, Return, Function>(&'a self, f: Function) -> Returnwhere
Function: FnOnce(&'a Self) -> Return,
Source§fn pipe_mut<'a, Return, Function>(&'a mut self, f: Function) -> Returnwhere
Function: FnOnce(&'a mut Self) -> Return,
fn pipe_mut<'a, Return, Function>(&'a mut self, f: Function) -> Returnwhere
Function: FnOnce(&'a mut Self) -> Return,
Source§fn pipe_as_ref<'a, Param, Return, Function>(&'a self, f: Function) -> Return
fn pipe_as_ref<'a, Param, Return, Function>(&'a self, f: Function) -> Return
f to &self where f takes a single parameter of type Param
and Self implements trait AsRef<Param>. Read moreSource§fn pipe_as_mut<'a, Param, Return, Function>(&'a mut self, f: Function) -> Return
fn pipe_as_mut<'a, Param, Return, Function>(&'a mut self, f: Function) -> Return
f to &mut self where f takes a single parameter of type Param
and Self implements trait AsMut<Param>. Read moreSource§fn pipe_deref<'a, Param, Return, Function>(&'a self, f: Function) -> Return
fn pipe_deref<'a, Param, Return, Function>(&'a self, f: Function) -> Return
f to &self where f takes a single parameter of type Param
and Self implements trait Deref<Target = Param>. Read moreSource§fn pipe_deref_mut<'a, Param, Return, Function>(
&'a mut self,
f: Function,
) -> Returnwhere
Self: DerefMut<Target = Param>,
Param: 'a + ?Sized,
Function: FnOnce(&'a mut Param) -> Return,
fn pipe_deref_mut<'a, Param, Return, Function>(
&'a mut self,
f: Function,
) -> Returnwhere
Self: DerefMut<Target = Param>,
Param: 'a + ?Sized,
Function: FnOnce(&'a mut Param) -> Return,
f to &mut self where f takes a single parameter of type Param
and Self implements trait DerefMut<Target = Param>. Read moreSource§fn pipe_borrow<'a, Param, Return, Function>(&'a self, f: Function) -> Return
fn pipe_borrow<'a, Param, Return, Function>(&'a self, f: Function) -> Return
f to &self where f takes a single parameter of type Param
and Self implements trait Borrow<Param>. Read moreSource§fn pipe_borrow_mut<'a, Param, Return, Function>(
&'a mut self,
f: Function,
) -> Return
fn pipe_borrow_mut<'a, Param, Return, Function>( &'a mut self, f: Function, ) -> Return
f to &mut self where f takes a single parameter of type Param
and Self implements trait BorrowMut<Param>. Read more