Parser

Struct Parser 

Source
pub struct Parser<'a, I, O> { /* private fields */ }
Expand description

Parser combinator.

Implementations§

Source§

impl<'a, I, O> Parser<'a, I, O>

Source

pub fn new<P>(parse: P) -> Parser<'a, I, O>
where P: Fn(&'a [I], usize) -> Result<(O, usize, Option<Error>)> + 'a,

Create new parser.

Source

pub fn parse(&self, input: &'a [I]) -> Result<O>

Apply the parser to parse input.

Source

pub fn parse_at( &self, input: &'a [I], start: usize, ) -> Result<(O, usize, Option<Error>)>

Parse input at specified position.

Source

pub fn map<U, F>(self, f: F) -> Parser<'a, I, U>
where F: Fn(O) -> U + 'a, I: 'a, O: 'a, U: 'a,

Convert parser result to desired value.

Source

pub fn convert<U, E, F>(self, f: F) -> Parser<'a, I, U>
where F: Fn(O, &Option<Error>) -> Result<U, E> + 'a, E: Debug, O: 'a, U: 'a,

Convert parser result to desired value, fail in case of conversion error.

Source

pub fn cache(self) -> Parser<'a, I, O>
where O: Clone + 'a,

Cache parser output result to speed up backtracking.

Source

pub fn debug_ok<S>(self, id: S) -> Parser<'a, I, O>
where O: Debug + 'a, S: AsRef<str> + 'a,

Source

pub fn pos(self) -> Parser<'a, I, usize>
where O: 'a,

Get input position after matching parser.

Source

pub fn collect(self) -> Parser<'a, I, &'a [I]>
where O: 'a,

Collect all matched input symbols.

Source

pub fn discard(self) -> Parser<'a, I, ()>
where O: 'a,

Discard parser output.

Source

pub fn opt(self) -> Parser<'a, I, Option<O>>
where O: 'a,

Make parser optional.

Source

pub fn repeat<R>(self, range: R) -> Parser<'a, I, Vec<O>>
where R: RangeArgument<usize> + Debug + 'a, O: 'a,

p.repeat(5) repeat p exactly 5 times p.repeat(0..) repeat p zero or more times p.repeat(1..) repeat p one or more times p.repeat(1..4) match p at least 1 and at most 3 times

Source

pub fn name(self, name: &'a str) -> Parser<'a, I, O>
where O: 'a,

Give parser a name to identify parsing errors, and stops rollback tracing propagation.

Source

pub fn trace<S>(self, id: S) -> Parser<'a, I, O>
where O: 'a, S: AsRef<str> + 'a,

Trace parser with an identifier for rollback tracing.

Source

pub fn expect(self, name: &'a str) -> Parser<'a, I, O>
where O: 'a,

Mark parser as expected, abort early when failed in ordered choice.

Trait Implementations§

Source§

impl<'a, I, O: 'a, U: 'a> Add<Parser<'a, I, U>> for Parser<'a, I, O>

Sequence reserve value

Source§

type Output = Parser<'a, I, (O, U)>

The resulting type after applying the + operator.
Source§

fn add(self, other: Parser<'a, I, U>) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, I, O: 'a> BitOr for Parser<'a, I, O>

Ordered choice

Source§

type Output = Parser<'a, I, O>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: Parser<'a, I, O>) -> Self::Output

Performs the | operation. Read more
Source§

impl<'a, I: 'a, O: 'a, U: 'a> Mul<Parser<'a, I, U>> for Parser<'a, I, O>

Sequence discard first value

Source§

type Output = Parser<'a, I, U>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Parser<'a, I, U>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, I, O: 'a> Neg for Parser<'a, I, O>

And predicate

Source§

type Output = Parser<'a, I, bool>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<'a, I, O: 'a> Not for Parser<'a, I, O>

Not predicate

Source§

type Output = Parser<'a, I, bool>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<'a, I, O: 'a, U: 'a, F: Fn(O) -> Parser<'a, I, U> + 'a> Shr<F> for Parser<'a, I, O>

Chain two parsers where the second parser depends on the first’s result.

Source§

type Output = Parser<'a, I, U>

The resulting type after applying the >> operator.
Source§

fn shr(self, other: F) -> Self::Output

Performs the >> operation. Read more
Source§

impl<'a, I, O: 'a, U: 'a> Sub<Parser<'a, I, U>> for Parser<'a, I, O>

Sequence discard second value

Source§

type Output = Parser<'a, I, O>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Parser<'a, I, U>) -> Self::Output

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<'a, I, O> Freeze for Parser<'a, I, O>

§

impl<'a, I, O> !RefUnwindSafe for Parser<'a, I, O>

§

impl<'a, I, O> !Send for Parser<'a, I, O>

§

impl<'a, I, O> !Sync for Parser<'a, I, O>

§

impl<'a, I, O> Unpin for Parser<'a, I, O>

§

impl<'a, I, O> !UnwindSafe for Parser<'a, I, O>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.