Struct pex::ParseState

source ·
pub struct ParseState<'i> {
    pub residual: &'i str,
    pub start_offset: usize,
    pub stop_reason: Option<StopBecause>,
}
Expand description

The state of parsing

Fields§

§residual: &'i str

Rest part of string

§start_offset: usize

Start offset of the string

§stop_reason: Option<StopBecause>

Stop reason

Implementations§

source§

impl<'i> ParseState<'i>

source

pub fn advance<T>(self, term: T) -> ParseState<'i>where T: Into<ParseAdvance>,

Advance the parser to a new state.

source

pub fn advance_view(self, offset: usize) -> ParseResult<'i, &'i str>

Advance the parser state and return the view of these string.

source§

impl<'i> ParseState<'i>

Character parsing methods.

source

pub fn match_char(self, target: char) -> ParseResult<'i, char>

Match a single character.

'c'
source

pub fn match_char_range(self, start: char, end: char) -> ParseResult<'i, char>

Match a character in given range.

[a-z]
source

pub fn match_eof(self) -> ParseResult<'i, ()>

Assert end of file

p $
source

pub fn match_char_any(self) -> ParseResult<'i, char>

Match any character, except EOF.

source

pub fn match_char_if<F>( self, predicate: F, message: &'static str ) -> ParseResult<'i, char>where F: FnMut(char) -> bool,

Parsing a character with given rule.

source§

impl<'i> ParseState<'i>

source

pub fn match_str_pattern<'a, 'p, P>( self, target: P, message: &'static str ) -> ParseResult<'i, &'i str>where P: Pattern<'p>, 'i: 'p,

Match a static string pattern.

source

pub fn match_str<'a>(self, target: &'static str) -> ParseResult<'i, &'i str>

Match a static string.

source

pub fn match_str_insensitive( self, target: &'static str ) -> ParseResult<'i, &'i str>

Match a static string.

source

pub fn match_regex( &self, re: &Regex, message: &'static str ) -> ParseResult<'i, Match<'_>>

Match a string with given regex.

source

pub fn match_str_if<F>( self, predicate: F, message: &'static str ) -> ParseResult<'i, &'i str>where F: FnMut(char) -> bool,

Match a string with given conditional.

source

pub fn match_str_until<F>( self, predicate: F, message: &'static str ) -> ParseResult<'i, &'i str>where F: FnMut(char) -> bool,

Match a string with given conditional.

source§

impl<'i> ParseState<'i>

source

pub fn match_fn<T, F>(self, parse: F) -> ParseResult<'i, T>where F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,

Simple suffix call form

source

pub fn match_repeats<T, F>(self, parse: F) -> ParseResult<'i, Vec<T>>where F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,

Parses a sequence of 0 or more repetitions of the given parser.

p*
p+ <=> p p*
source

pub fn match_repeat_m_n<T, F>( self, min: usize, max: usize, parse: F ) -> ParseResult<'i, Vec<T>>where F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,

Parses a sequence of 0 or more repetitions of the given parser.

p* <=> p{0, \inf}
p+ <=> p{1, \inf}
p{min, max}
source

pub fn match_optional<T, F>(self, parse: F) -> ParseResult<'i, Option<T>>where F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,

Parse an optional element

p?
source

pub fn skip<F, T>(self, parse: F) -> ParseState<'i>where F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,

Match but does not return the result

source

pub fn match_positive<F, T>( self, parse: F, message: &'static str ) -> ParseResult<'i, ()>where F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,

Zero-width positive match, does not consume input

Used to be a external rule, which used as assert

&ahead p
p &after
source

pub fn match_negative<F, T>( self, parse: F, message: &'static str ) -> ParseResult<'i, ()>where F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,

Zero-width negative match, does not consume input

!ahead p
p !after
source§

impl<'i> ParseState<'i>

source

pub fn begin_choice<T>(self) -> ChoiceHelper<'i, T>

Begin a choice progress

source§

impl<'i> ParseState<'i>

source

pub const fn new(input: &'i str) -> Self

Create a new state

source

pub const fn with_start_offset(self, offset: usize) -> Self

Reset the cursor offset

source

pub const fn end_offset(&self) -> usize

Reset the cursor offset

source

pub const fn finish<T>(self, value: T) -> ParseResult<'i, T>

Finish with given value

source

pub const fn is_empty(&self) -> bool

Check if the string is depleted

source

pub const fn get_error(self) -> StopBecause

Get inner error

source

pub const fn set_error(&mut self, error: StopBecause)

Set inner error

source

pub fn get_string<R>(&self, range: R) -> Option<&R::Output>where R: SliceIndex<str>,

Get a string view

source

pub fn get_character(&self, nth: usize) -> Option<char>

Get nth character

source

pub const fn away_from(&self, start: ParseState<'_>) -> Range<usize>

Get range away from start state

Trait Implementations§

source§

impl<'i> Clone for ParseState<'i>

source§

fn clone(&self) -> ParseState<'i>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'i> Debug for ParseState<'i>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'i> PartialEq<ParseState<'i>> for ParseState<'i>

source§

fn eq(&self, other: &ParseState<'i>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'i> Copy for ParseState<'i>

source§

impl<'i> Eq for ParseState<'i>

source§

impl<'i> StructuralEq for ParseState<'i>

source§

impl<'i> StructuralPartialEq for ParseState<'i>

Auto Trait Implementations§

§

impl<'i> RefUnwindSafe for ParseState<'i>

§

impl<'i> Send for ParseState<'i>

§

impl<'i> Sync for ParseState<'i>

§

impl<'i> Unpin for ParseState<'i>

§

impl<'i> UnwindSafe for ParseState<'i>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.