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>
impl<'i> ParseState<'i>
sourcepub fn advance<T>(self, term: T) -> ParseState<'i>where
T: Into<ParseAdvance>,
pub fn advance<T>(self, term: T) -> ParseState<'i>where T: Into<ParseAdvance>,
Advance the parser to a new state.
sourcepub fn advance_view(self, offset: usize) -> ParseResult<'i, &'i str>
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>
impl<'i> ParseState<'i>
Character parsing methods.
sourcepub fn match_char(self, target: char) -> ParseResult<'i, char>
pub fn match_char(self, target: char) -> ParseResult<'i, char>
Match a single character.
'c'
sourcepub fn match_char_range(self, start: char, end: char) -> ParseResult<'i, char>
pub fn match_char_range(self, start: char, end: char) -> ParseResult<'i, char>
Match a character in given range.
[a-z]
sourcepub fn match_eof(self) -> ParseResult<'i, ()>
pub fn match_eof(self) -> ParseResult<'i, ()>
Assert end of file
p $
sourcepub fn match_char_any(self) -> ParseResult<'i, char>
pub fn match_char_any(self) -> ParseResult<'i, char>
Match any character, except EOF
.
sourcepub fn match_char_if<F>(
self,
predicate: F,
message: &'static str
) -> ParseResult<'i, char>where
F: FnMut(char) -> bool,
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>
impl<'i> ParseState<'i>
sourcepub fn match_str_pattern<'a, 'p, P>(
self,
target: P,
message: &'static str
) -> ParseResult<'i, &'i str>where
P: Pattern<'p>,
'i: 'p,
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.
sourcepub fn match_str<'a>(self, target: &'static str) -> ParseResult<'i, &'i str>
pub fn match_str<'a>(self, target: &'static str) -> ParseResult<'i, &'i str>
Match a static string.
sourcepub fn match_str_insensitive(
self,
target: &'static str
) -> ParseResult<'i, &'i str>
pub fn match_str_insensitive( self, target: &'static str ) -> ParseResult<'i, &'i str>
Match a static string.
sourcepub fn match_regex(
&self,
re: &Regex,
message: &'static str
) -> ParseResult<'i, Match<'_>>
pub fn match_regex( &self, re: &Regex, message: &'static str ) -> ParseResult<'i, Match<'_>>
Match a string with given regex.
sourcepub fn match_str_if<F>(
self,
predicate: F,
message: &'static str
) -> ParseResult<'i, &'i str>where
F: FnMut(char) -> bool,
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.
sourcepub fn match_str_until<F>(
self,
predicate: F,
message: &'static str
) -> ParseResult<'i, &'i str>where
F: FnMut(char) -> bool,
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>
impl<'i> ParseState<'i>
sourcepub fn match_fn<T, F>(self, parse: F) -> ParseResult<'i, T>where
F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,
pub fn match_fn<T, F>(self, parse: F) -> ParseResult<'i, T>where F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,
Simple suffix call form
sourcepub fn match_repeats<T, F>(self, parse: F) -> ParseResult<'i, Vec<T>>where
F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,
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*
sourcepub 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>,
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}
sourcepub fn match_optional<T, F>(self, parse: F) -> ParseResult<'i, Option<T>>where
F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,
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?
sourcepub fn skip<F, T>(self, parse: F) -> ParseState<'i>where
F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,
pub fn skip<F, T>(self, parse: F) -> ParseState<'i>where F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,
Match but does not return the result
sourcepub fn match_positive<F, T>(
self,
parse: F,
message: &'static str
) -> ParseResult<'i, ()>where
F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,
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
sourcepub fn match_negative<F, T>(
self,
parse: F,
message: &'static str
) -> ParseResult<'i, ()>where
F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,
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>
impl<'i> ParseState<'i>
sourcepub fn begin_choice<T>(self) -> ChoiceHelper<'i, T>
pub fn begin_choice<T>(self) -> ChoiceHelper<'i, T>
Begin a choice progress
source§impl<'i> ParseState<'i>
impl<'i> ParseState<'i>
sourcepub const fn with_start_offset(self, offset: usize) -> Self
pub const fn with_start_offset(self, offset: usize) -> Self
Reset the cursor offset
sourcepub const fn end_offset(&self) -> usize
pub const fn end_offset(&self) -> usize
Reset the cursor offset
sourcepub const fn finish<T>(self, value: T) -> ParseResult<'i, T>
pub const fn finish<T>(self, value: T) -> ParseResult<'i, T>
Finish with given value
sourcepub const fn get_error(self) -> StopBecause
pub const fn get_error(self) -> StopBecause
Get inner error
sourcepub const fn set_error(&mut self, error: StopBecause)
pub const fn set_error(&mut self, error: StopBecause)
Set inner error
sourcepub fn get_string<R>(&self, range: R) -> Option<&R::Output>where
R: SliceIndex<str>,
pub fn get_string<R>(&self, range: R) -> Option<&R::Output>where R: SliceIndex<str>,
Get a string view
sourcepub fn get_character(&self, nth: usize) -> Option<char>
pub fn get_character(&self, nth: usize) -> Option<char>
Get nth character
sourcepub const fn away_from(&self, start: ParseState<'_>) -> Range<usize>
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>
impl<'i> Clone for ParseState<'i>
source§fn clone(&self) -> ParseState<'i>
fn clone(&self) -> ParseState<'i>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'i> Debug for ParseState<'i>
impl<'i> Debug for ParseState<'i>
source§impl<'i> PartialEq<ParseState<'i>> for ParseState<'i>
impl<'i> PartialEq<ParseState<'i>> for ParseState<'i>
source§fn eq(&self, other: &ParseState<'i>) -> bool
fn eq(&self, other: &ParseState<'i>) -> bool
self
and other
values to be equal, and is used
by ==
.