Skip to main content

Parser

Struct Parser 

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

Parser

Implementations§

Source§

impl Parser

Source

pub fn new(input: impl Into<ArcStr>) -> Self

Creates a new parser

Source

pub const fn input(&self) -> &ArcStr

Returns the whole input of the parser

Source

pub fn remaining(&self) -> &str

Returns the remaining string for the parser

Source

pub const fn cur_pos(&mut self) -> AstPos

Returns the current position of the parser

Source

pub const fn set_pos(&mut self, pos: AstPos)

Sets the position of this parser

Source

pub fn reverse_whitespace(&mut self)

Reverses all whitespace (except the last) in the current position

Source

pub fn reverse_line(&mut self)

Reverses to the start of the current line

Source

pub fn cur_line(&self) -> &str

Returns the current line of the parser, not including the end

Source

pub fn loc(&self, pos: AstPos) -> ParserLoc

Gets the position (0-indexed) of the parser at a position

Source

pub fn cur_loc(&self) -> ParserLoc

Gets the current position (0-indexed) of the parser

Source

pub fn is_finished(&self) -> bool

Returns if the parser is finished

Source

pub fn update_with<F, O>(&mut self, f: F) -> (AstStr, O)
where F: FnOnce(&mut &str) -> O,

Updates this parser from a string.

See Self::try_update_with for more details.

Source

pub fn try_update_with<F, T>( &mut self, f: F, ) -> <T::Residual as Residual<(AstStr, T::Output)>>::TryType
where F: FnOnce(&mut &str) -> T, T: Try<Residual: Residual<(AstStr, T::Output)>>,

Updates this parser from a string.

The function f receives a string to update. The value it is updated with must be a substring of the received function.

§Success

When f returns successfully, the parser is updated from the state of the string.

§Failure

If f returns unsuccessfully, an error will be returned with the latest change to the string as it’s position.

Source

pub fn parse<T: Parse>(&mut self) -> Result<T, ParserError<T>>

Parses T from this parser

Source

pub fn parse_with_peeked<T: ParsePeeked<U>, U>( &mut self, parsed: U, ) -> Result<T, ParserError<T>>

Parses T from this parser with a peeked value

Source

pub fn try_parse_with<T, E: ParseError>( &mut self, parser: impl FnOnce(&mut Self) -> Result<T, E>, ) -> Result<Result<T, E>, E>

Tries to parses T from this parser using parser for parsing.

On error, nothing is modified.

Source

pub fn try_parse<T: Parse>( &mut self, ) -> Result<Result<T, ParserError<T>>, ParserError<T>>

Tries to parses T from this parser.

On error, nothing is modified.

Source

pub fn peek_with<T, E: ParseError>( &mut self, parse: impl FnOnce(&mut Self) -> Result<T, E>, ) -> Result<Result<(T, PeekState), E>, E>

Peeks a T from this parser using parser for parsing.

Parser is only advanced is a fatal error occurs

Source

pub fn peek<T: Parse>( &mut self, ) -> Result<Result<(T, PeekState), ParserError<T>>, ParserError<T>>

Peeks a T from this parser.

Parser is only advanced is a fatal error occurs

Source

pub const fn set_peeked(&mut self, peek_state: PeekState)

Accepts a peeked state.

Source

pub fn tags(&self) -> impl Iterator<Item = ParserTag>

Returns all current tags

Source

pub fn has_tag(&self, tag: impl Into<ParserTag>) -> bool

Returns if this parser has a tag

Source

pub fn with_tags<O>( &mut self, tags: impl IntoIterator<Item = ParserTag>, f: impl FnOnce(&mut Self) -> O, ) -> O

Calls f with tags tags added to this parser

Source

pub fn with_tag<O>( &mut self, tag: impl Into<ParserTag>, f: impl FnOnce(&mut Self) -> O, ) -> O

Calls f with tag tag added to this parser

Source

pub fn without_tags<O>(&mut self, f: impl FnOnce(&mut Self) -> O) -> O

Calls f with all tags removed.

Trait Implementations§

Source§

impl Debug for Parser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<R, T> FromRecursiveRoot<R> for T
where T: From<R>,

Source§

fn from_recursive_root(root: R, _parser: &mut Parser) -> T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<R> IntoRecursiveRoot<R> for R

Source§

fn into_recursive_root(self, _parser: &mut Parser) -> R

Source§

impl<T, R> ParsableFrom<RecursiveWrapper<T, R>> for T

Source§

fn from_parsable(wrapper: RecursiveWrapper<T, R>) -> T

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<R> TryFromRecursiveRoot<R> for R

Source§

fn try_from_recursive_root(root: R, _parser: &mut Parser) -> Option<R>

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.