Struct Parser

Source
pub struct Parser { /* private fields */ }
Expand description

The main parser struct, which holds the main logic for the parser.

Implementations§

Source§

impl Parser

Source

pub fn new(stream: &str) -> Result<Self, ParseErr>

Creates a new parser from a given string.

In the instantiation process, this function will attempt to tokenize the string into tokens, raising an error if it fails.

Source

pub fn peek(&self) -> Option<&(Token, Span)>

Peeks at the next token to read.

Source

pub fn advance(&mut self)

Advances the parser ahead by one token.

Source

pub fn cursor(&self) -> Span

Gets the range of the next token to read (or an EOL range if there are no more tokens to read).

Source

pub fn parse<P: Parse>(&mut self) -> Result<P, ParseErr>

Parses the current token stream into a component, erroring if not possible.

If parsing fails, there are no guarantees about what happens to the input, and the parser likely should not be used after an error is raised during parsing.

Source

pub fn match_<P: TokenParse>(&mut self) -> Result<Option<P>, ParseErr>

Check if the next token matches the given component and consume it if so.

This function can error if the next token does match the given component, but an error occurs in trying to convert it to that component.

Source

pub fn advance_if<T>( &mut self, pred: impl FnOnce(Option<&Token>, Span) -> Result<T, ParseErr>, ) -> Result<T, ParseErr>

Applies the provided predicate to the next token in the input.

If an error is raised from the predicate, the parser does not advance its input.

Source

pub fn spanned<T, E>( &mut self, f: impl FnOnce(&mut Parser) -> Result<T, E>, ) -> Result<(T, Range<usize>), E>

Calculates the span of the component created inside this region block.

Source

pub fn is_empty(&self) -> bool

Checks whether the input for the parser is empty.

Auto Trait Implementations§

§

impl Freeze for Parser

§

impl RefUnwindSafe for Parser

§

impl Send for Parser

§

impl Sync for Parser

§

impl Unpin for Parser

§

impl UnwindSafe for Parser

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V