Struct ParserState
struct ParserState<'i, R: RuleType> { ... }
The complete state of a Parser.
Implementations
impl<'i, R: RuleType> ParserState<'i, R>
fn new(input: &'i str) -> Box<Self>Allocates a fresh
ParserStateobject to the heap and returns the ownedBox. ThisBoxwill be passed from closure to closure based on the needs of the specifiedParser.Examples
# use pest; let input = ""; let state: = new;fn get_parse_attempts(self: &Self) -> &ParseAttempts<R>Get all parse attempts after process of parsing is finished.
fn position(self: &Self) -> &Position<'i>Returns a reference to the current
Positionof theParserState.Examples
# use pest; # # let input = "ab"; let mut state: = new; let position = state.position; assert_eq!;fn atomicity(self: &Self) -> AtomicityReturns the current atomicity of the
ParserState.Examples
# use pest; # use Atomicity; # # let input = "ab"; let mut state: = new; let atomicity = state.atomicity; assert_eq!;fn rule<F>(self: Box<Self>, rule: R, f: F) -> ParseResult<Box<Self>> where F: FnOnce(Box<Self>) -> ParseResult<Box<Self>>Wrapper needed to generate tokens. This will associate the
Rtype rule to the closure meant to match the rule.Examples
# use pest; # # let input = "a"; let pairs: = state.unwrap.collect; assert_eq!;fn tag_node(self: Box<Self>, tag: &'i str) -> ParseResult<Box<Self>>Tag current node
Examples
Try to recognize the one specified in a set of characters
use ; let input = "abcd"; let pairs = state.unwrap; // find all node tag as `c` let find: = pairs.filter.collect; assert_eq!fn sequence<F>(self: Box<Self>, f: F) -> ParseResult<Box<Self>> where F: FnOnce(Box<Self>) -> ParseResult<Box<Self>>Starts a sequence of transformations provided by
ffrom theBox<ParserState>. Returns the sameResultreturned byfin the case of anOk, orErrwith the currentBox<ParserState>otherwise.This method is useful to parse sequences that only match together which usually come in the form of chained
Results withResult::and_then.Examples
# use pest; # # let input = "a"; let pairs: = state.unwrap.collect; assert_eq!;fn repeat<F>(self: Box<Self>, f: F) -> ParseResult<Box<Self>> where F: FnMut(Box<Self>) -> ParseResult<Box<Self>>Repeatedly applies the transformation provided by
ffrom theBox<ParserState>. ReturnsOkwith the updatedBox<ParserState>returned byfwrapped up in anErr.Examples
# use pest; # # let input = "aab"; let mut state: = new; let mut result = state.repeat; assert!; assert_eq!; state = new; result = state.repeat; assert!; assert_eq!;fn optional<F>(self: Box<Self>, f: F) -> ParseResult<Box<Self>> where F: FnOnce(Box<Self>) -> ParseResult<Box<Self>>Optionally applies the transformation provided by
ffrom theBox<ParserState>. ReturnsOkwith the updatedBox<ParserState>returned byfregardless of theResult.Examples
# use pest; # # let input = "ab"; let mut state: = new; let result = state.optional; assert!; state = new; let result = state.optional; assert!;fn match_char_by<F>(self: Box<Self>, f: F) -> ParseResult<Box<Self>> where F: FnOnce(char) -> boolAttempts to match a single character based on a filter function. Returns
Okwith the updatedBox<ParserState>if successful, orErrwith the updatedBox<ParserState>otherwise.Examples
# use pest; # # let input = "ab"; let mut state: = new; let result = state.match_char_by; assert!; assert_eq!; let input = "❤"; let mut state: = new; let result = state.match_char_by; assert!; assert_eq!;fn match_string(self: Box<Self>, string: &str) -> ParseResult<Box<Self>>Attempts to match the given string. Returns
Okwith the updatedBox<ParserState>if successful, orErrwith the updatedBox<ParserState>otherwise.Examples
# use pest; # # let input = "ab"; let mut state: = new; let mut result = state.match_string; assert!; assert_eq!; state = new; result = state.match_string; assert!; assert_eq!;fn stack_push_literal<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: Box<Self>, string: impl Into<Cow<'static, str>>) -> ParseResult<Box<Self>>Pushes the given literal to the stack, and always returns
Ok(Box<ParserState>).Examples
# use pest; # # let input = "ab"; let mut state: = new; let mut result = state.stack_push_literal; assert!; assert_eq!; let mut result = result.unwrap.stack_pop; assert!; assert_eq!;fn match_insensitive(self: Box<Self>, string: &str) -> ParseResult<Box<Self>>Attempts to case-insensitively match the given string. Returns
Okwith the updatedBox<ParserState>if successful, orErrwith the updatedBox<ParserState>otherwise.Examples
# use pest; # # let input = "ab"; let mut state: = new; let mut result = state.match_insensitive; assert!; assert_eq!; state = new; result = state.match_insensitive; assert!; assert_eq!;fn match_range(self: Box<Self>, range: Range<char>) -> ParseResult<Box<Self>>Attempts to match a single character from the given range. Returns
Okwith the updatedBox<ParserState>if successful, orErrwith the updatedBox<ParserState>otherwise.Caution
The provided
rangeis interpreted as inclusive.Examples
# use pest; # # let input = "ab"; let mut state: = new; let mut result = state.match_range; assert!; assert_eq!; state = new; result = state.match_range; assert!; assert_eq!;fn skip(self: Box<Self>, n: usize) -> ParseResult<Box<Self>>Attempts to skip
ncharacters forward. ReturnsOkwith the updatedBox<ParserState>if successful, orErrwith the updatedBox<ParserState>otherwise.Examples
# use pest; # # let input = "ab"; let mut state: = new; let mut result = state.skip; assert!; assert_eq!; state = new; result = state.skip; assert!; assert_eq!;fn skip_until(self: Box<Self>, strings: &[&str]) -> ParseResult<Box<Self>>Attempts to skip forward until one of the given strings is found. Returns
Okwith the updatedBox<ParserState>whether or not one of the strings is found.Examples
# use pest; # # let input = "abcd"; let mut state: = new; let mut result = state.skip_until; assert!; assert_eq!;fn start_of_input(self: Box<Self>) -> ParseResult<Box<Self>>Attempts to match the start of the input. Returns
Okwith the currentBox<ParserState>if the parser has not yet advanced, orErrwith the currentBox<ParserState>otherwise.Examples
# use pest; # # let input = "ab"; let mut state: = new; let mut result = state.start_of_input; assert!; state = new; state = state.match_string.unwrap; result = state.start_of_input; assert!;fn end_of_input(self: Box<Self>) -> ParseResult<Box<Self>>Attempts to match the end of the input. Returns
Okwith the currentBox<ParserState>if there is no input remaining, orErrwith the currentBox<ParserState>otherwise.Examples
# use pest; # # let input = "ab"; let mut state: = new; let mut result = state.end_of_input; assert!; state = new; state = state.match_string.unwrap; result = state.end_of_input; assert!;fn lookahead<F>(self: Box<Self>, is_positive: bool, f: F) -> ParseResult<Box<Self>> where F: FnOnce(Box<Self>) -> ParseResult<Box<Self>>Starts a lookahead transformation provided by
ffrom theBox<ParserState>. It returnsOkwith the currentBox<ParserState>iffalso returns anOk, orErrwith the currentBox<ParserState>otherwise. Ifis_positiveisfalse, it swaps theOkandErrtogether, negating theResult.Examples
# use pest; # # let input = "a"; let pairs: = state.unwrap.collect; assert_eq!;fn atomic<F>(self: Box<Self>, atomicity: Atomicity, f: F) -> ParseResult<Box<Self>> where F: FnOnce(Box<Self>) -> ParseResult<Box<Self>>Transformation which stops
Tokens from being generated according tois_atomic. Used as wrapper overrule(or even anotheratomic) call.Examples
# use ; # # let input = "a"; let pairs: = state.unwrap.collect; assert_eq!;fn stack_push<F>(self: Box<Self>, f: F) -> ParseResult<Box<Self>> where F: FnOnce(Box<Self>) -> ParseResult<Box<Self>>Evaluates the result of closure
fand pushes the span of the input consumed from beforefis called to afterfis called to the stack. ReturnsOk(Box<ParserState>)iffis called successfully, orErr(Box<ParserState>)otherwise.Examples
# use pest; # # let input = "ab"; let mut state: = new; let mut result = state.stack_push; assert!; assert_eq!;fn stack_peek(self: Box<Self>) -> ParseResult<Box<Self>>Peeks the top of the stack and attempts to match the string. Returns
Ok(Box<ParserState>)if the string is matched successfully, orErr(Box<ParserState>)otherwise.Examples
# use pest; # # let input = "aa"; let mut state: = new; let mut result = state.stack_push.and_then; assert!; assert_eq!;fn stack_pop(self: Box<Self>) -> ParseResult<Box<Self>>Pops the top of the stack and attempts to match the string. Returns
Ok(Box<ParserState>)if the string is matched successfully, orErr(Box<ParserState>)otherwise.Examples
# use pest; # # let input = "aa"; let mut state: = new; let mut result = state.stack_push.and_then; assert!; assert_eq!;fn stack_match_peek_slice(self: Box<Self>, start: i32, end: Option<i32>, match_dir: MatchDir) -> ParseResult<Box<Self>>Matches part of the state of the stack.
Examples
# use ; # # let input = "abcd cd cb"; let mut state: = new; let mut result = state .stack_push .and_then .and_then .and_then .and_then .and_then .and_then .and_then; assert!; assert_eq!;fn stack_match_peek(self: Box<Self>) -> ParseResult<Box<Self>>Matches the full state of the stack.
Examples
# use pest; # # let input = "abba"; let mut state: = new; let mut result = state .stack_push .and_then .and_then; assert!; assert_eq!;fn stack_match_pop(self: Box<Self>) -> ParseResult<Box<Self>>Matches the full state of the stack. This method will clear the stack as it evaluates.
Examples
/// # use pest; # # let input = "aaaa"; let mut state: = new; let mut result = state.stack_push.and_then.and_then; assert!; assert_eq!;fn stack_drop(self: Box<Self>) -> ParseResult<Box<Self>>Drops the top of the stack. Returns
Ok(Box<ParserState>)if there was a value to drop, orErr(Box<ParserState>)otherwise.Examples
# use pest; # # let input = "aa"; let mut state: = new; let mut result = state.stack_push.and_then; assert!; assert_eq!;fn restore_on_err<F>(self: Box<Self>, f: F) -> ParseResult<Box<Self>> where F: FnOnce(Box<Self>) -> ParseResult<Box<Self>>Restores the original state of the
ParserStatewhenfreturns anErr. Currently, this method only restores the stack.Examples
# use pest; # # let input = "ab"; let mut state: = new; let mut result = state.restore_on_err; assert!; // Since the the rule doesn't match, the "a" pushed to the stack will be removed. let catch_panic = catch_unwind; assert!;
impl<'i, R> Freeze for ParserState<'i, R>
impl<'i, R> RefUnwindSafe for ParserState<'i, R>
impl<'i, R> Send for ParserState<'i, R>
impl<'i, R> Sync for ParserState<'i, R>
impl<'i, R> Unpin for ParserState<'i, R>
impl<'i, R> UnsafeUnpin for ParserState<'i, R>
impl<'i, R> UnwindSafe for ParserState<'i, R>
impl<'i, R: $crate::fmt::Debug + RuleType> Debug for ParserState<'i, R>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<T> Any for ParserState<'i, R>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for ParserState<'i, R>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for ParserState<'i, R>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for ParserState<'i, R>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for ParserState<'i, R>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for ParserState<'i, R>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for ParserState<'i, R>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>