[−][src]Struct honeycomb::Parser
A Parser has a function that consumes input and returns an object of type Output.
Methods
impl<T> Parser<T> where
T: 'static + Clone,
[src]
T: 'static + Clone,
pub fn new(parser: impl Fn(&str) -> Output<T> + 'static) -> Self
[src]
Create a new parser from a function that returns an Output. This is mainly used to define the atomic combinators
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]
O: 'static + Clone,
This maps 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 prefixes<O>(self, operand: Parser<O>) -> Parser<O> where
O: 'static + Clone,
[src]
O: 'static + Clone,
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]
O: 'static + Clone,
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]
O: 'static + Clone,
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<O, T> Sub<fn(T) -> O> for Parser<T> where
O: 'static + Clone,
T: 'static + Clone,
[src]
O: 'static + Clone,
T: 'static + Clone,
The - operator is used as an alternative to the .map
method.
type Output = Parser<O>
The resulting type after applying the -
operator.
fn sub(self, rhs: fn(_: T) -> O) -> Self::Output
[src]
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.
fn mul(self, rhs: R) -> Self::Output
[src]
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.
fn not(self) -> Self::Output
[src]
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.
fn bitand(self, rhs: Parser<B>) -> Self::Output
[src]
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.
fn bitor(self, rhs: Self) -> Self::Output
[src]
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.
fn shl(self, rhs: Parser<B>) -> Self::Output
[src]
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.
fn shr(self, rhs: Parser<B>) -> Self::Output
[src]
impl<T: Clone> Clone for Parser<T>
[src]
Auto Trait Implementations
Blanket Implementations
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.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.