Skip to main content

Parser

Enum Parser 

Source
pub enum Parser<'lex, T, E> {
    Success(RefLexer<'lex>, T),
    Fail(RefLexer<'lex>, E),
}
Expand description

Represents the result of a parsing operation.

A parser either succeeds with an advanced lexer and a parsed value T, or fails and returns the unchanged lexer state along with an error E.

Variants§

§

Success(RefLexer<'lex>, T)

§

Fail(RefLexer<'lex>, E)

Implementations§

Source§

impl<'lex, T, E> Parser<'lex, T, E>

Source

pub fn or_else<F>(self, f: F) -> Self
where F: FnOnce(RefLexer<'_>) -> Parser<'_, T, E>,

Chains another parsing attempt if the current parser failed.

Source

pub fn and_then<U, F>(self, f: F) -> Parser<'lex, U, E>
where F: FnOnce(RefLexer<'lex>, T) -> Parser<'lex, U, E>,

Chains a subsequent parser if the current parser succeeds.

Source

pub fn success(self) -> Result<T, (RefLexer<'lex>, E)>

Converts this parser result into a standard Result, returning the parsed item or the lexer and error pair upon failure.

Auto Trait Implementations§

§

impl<'lex, T, E> !UnwindSafe for Parser<'lex, T, E>

§

impl<'lex, T, E> Freeze for Parser<'lex, T, E>
where T: Freeze, E: Freeze,

§

impl<'lex, T, E> RefUnwindSafe for Parser<'lex, T, E>

§

impl<'lex, T, E> Send for Parser<'lex, T, E>
where T: Send, E: Send,

§

impl<'lex, T, E> Sync for Parser<'lex, T, E>
where T: Sync, E: Sync,

§

impl<'lex, T, E> Unpin for Parser<'lex, T, E>
where T: Unpin, E: Unpin,

§

impl<'lex, T, E> UnsafeUnpin for Parser<'lex, T, E>
where T: UnsafeUnpin, E: UnsafeUnpin,

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.