[][src]Struct honeycomb::Parser

pub struct Parser<T> {
    pub expectation: String,
    // some fields omitted
}

A Parser has a function that consumes input and returns an object of type Output.

Fields

expectation: String

Methods

impl<T> Parser<T> where
    T: 'static + Clone
[src]

pub fn new(
    parser: impl Fn(&str) -> Output<T> + 'static,
    expectation: impl ToString
) -> Self
[src]

Create a new parser from a function that returns an Output. This is mainly used to define the atomic combinators

pub fn expects(self, expectation: impl ToString) -> Self[src]

pub fn parse(&self, input: &str) -> Result<T, Error>[src]

This parses a string using this combinator, and returns a result containing either the successfully lexed and parsed data, or an error containing info about the failure.

pub fn parse_internal(&self, input: &str) -> Output<T>[src]

This is used by the atomic combinators for things like control flow and passing the output of one parser into another.

pub fn map<O>(self, map_fn: fn(_: T) -> O) -> Parser<O> where
    O: 'static + Clone
[src]

This method takes a function that takes the output of this Parser, and converts it to the output of another data type. This allows us to lex our input as we parse it.

pub fn convert<O, E>(self, convert_fn: fn(_: T) -> Result<O, E>) -> Parser<O> where
    O: 'static + Clone,
    E: 'static, 
[src]

This method takes a function that takes the output of this Parser, and TRIES to convert it to the output of another data type. If the given function returns an Err, this parser fails.

pub fn prefixes<O>(self, operand: Parser<O>) -> Parser<O> where
    O: 'static + Clone
[src]

This parser "prefixes" another. When the returned parser is used, it will require this parser and the operand parser to succeed, and return the result of the second.

pub fn suffix<O>(self, operand: Parser<O>) -> Parser<T> where
    O: 'static + Clone
[src]

This parser will use the operand as a "suffix". The parser will only succeed if the "suffix" parser succeeds afterwards, but the input of the "suffix" parser will be discarded.

pub fn is(self) -> Parser<()>[src]

This method returns a parser that does not consume input, but succeeds if this parser succeeds. This can be used to make assertions for our input.

pub fn isnt(self) -> Parser<()>[src]

This method returns a parser that does not consume input, but succeeds if this parser does not succeed. This can be used to make assertions for our input.

pub fn and<O>(self, operand: Parser<O>) -> Parser<(T, O)> where
    O: 'static + Clone
[src]

Combine two parsers into one, and combine their consumed inputs into a tuple. Parser & Parser -> Parser<A, B>. The resulting parser will only succeed if BOTH sub-parsers succeed.

pub fn or(self, operand: Self) -> Self[src]

If this parser does not succeed, try this other parser

pub fn repeat(self, range: impl RangeBounds<usize>) -> Parser<Vec<T>>[src]

Repeat this parser N..M times This can also be repeated ..N times, N.. times, or even .. times

Trait Implementations

impl<T: 'static + Clone, S: ToString> Rem<S> for Parser<T>[src]

The | operator can be used as an alternative to the .or method

type Output = Self

The resulting type after applying the % operator.

impl<O, T> Sub<fn(T) -> O> for Parser<T> where
    O: 'static + Clone,
    T: 'static + Clone
[src]

The - operator is used as an alternative to the .map method.

type Output = Parser<O>

The resulting type after applying the - operator.

impl<T: 'static + Clone, R: RangeBounds<usize>> Mul<R> for Parser<T>[src]

A parser can be multiplied by a range as an alternative to .repeat. Here's an example: sym('a') * (..7)

type Output = Parser<Vec<T>>

The resulting type after applying the * operator.

impl<T: 'static + Clone> Not for Parser<T>[src]

The ! operator can be used as an alternative to the .not method

type Output = Parser<()>

The resulting type after applying the ! operator.

impl<A: 'static + Clone, B: 'static + Clone> BitAnd<Parser<B>> for Parser<A>[src]

The & operator can be used as an alternative to the .and method

type Output = Parser<(A, B)>

The resulting type after applying the & operator.

impl<T: 'static + Clone> BitOr<Parser<T>> for Parser<T>[src]

The | operator can be used as an alternative to the .or method

type Output = Parser<T>

The resulting type after applying the | operator.

impl<O, T, E> BitXor<fn(T) -> Result<O, E>> for Parser<T> where
    O: 'static + Clone,
    T: 'static + Clone,
    E: 'static, 
[src]

The ^ operator is used as an alternative to the .convert method.

type Output = Parser<O>

The resulting type after applying the ^ operator.

impl<A: 'static + Clone, B: 'static + Clone> Shl<Parser<B>> for Parser<A>[src]

Discard the consumed data of the RHS

type Output = Parser<A>

The resulting type after applying the << operator.

impl<A: 'static + Clone, B: 'static + Clone> Shr<Parser<B>> for Parser<A>[src]

Discard the consumed data of the LHS

type Output = Parser<B>

The resulting type after applying the >> operator.

impl<T: Clone> Clone for Parser<T>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl<T> Unpin for Parser<T>

impl<T> !Sync for Parser<T>

impl<T> !Send for Parser<T>

Blanket Implementations

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.