Struct pex::ParseState
source · pub struct ParseState<'i> {
pub rest_text: &'i str,
pub start_offset: usize,
pub stop_reason: Option<StopBecause>,
}
Expand description
The state of parsing
Fields§
§rest_text: &'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(
self,
target: &'static str,
insensitive: bool
) -> ParseResult<'i, &'i str>
pub fn match_str( self, target: &'static str, insensitive: bool ) -> ParseResult<'i, &'i str>
Match a static string.
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.
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 match_comment_line(self, head: &'static str) -> ParseResult<'i, &'i str>
pub fn match_comment_line(self, head: &'static str) -> ParseResult<'i, &'i str>
Parse a comment line
# comment
// comment
sourcepub fn match_comment_block<F, T>(
self,
head: &'static str,
tail: &'static str
) -> ParseResult<'i, ()>where
F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,
pub fn match_comment_block<F, T>( self, head: &'static str, tail: &'static str ) -> ParseResult<'i, ()>where F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,
Parse the comment block
/* */
sourcepub fn match_surround<F, T>(
self,
delimiter: char,
min: usize
) -> ParseResult<'i, ()>where
F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,
pub fn match_surround<F, T>( self, delimiter: char, min: usize ) -> ParseResult<'i, ()>where F: FnMut(ParseState<'i>) -> ParseResult<'_, T>,
Parse the comment block
r#" "#
r##" "##
r###" "###
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 fn with_start_offset(self, offset: usize) -> Self
pub fn with_start_offset(self, offset: usize) -> Self
Reset the cursor offset
sourcepub fn finish<T>(self, value: T) -> ParseResult<'i, T>
pub fn finish<T>(self, value: T) -> ParseResult<'i, T>
Finish with given value
sourcepub fn get_error(self) -> StopBecause
pub fn get_error(self) -> StopBecause
Get inner error
sourcepub fn set_error(&mut self, error: StopBecause)
pub 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 fn away_from(&self, start: ParseState<'_>) -> Range<usize>
pub 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 ==
.