From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- vendor/pest/src/parser_state.rs | 74 +++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 22 deletions(-) (limited to 'vendor/pest/src/parser_state.rs') diff --git a/vendor/pest/src/parser_state.rs b/vendor/pest/src/parser_state.rs index a4422e866..609de5557 100644 --- a/vendor/pest/src/parser_state.rs +++ b/vendor/pest/src/parser_state.rs @@ -28,8 +28,24 @@ use crate::RuleType; /// [`ParserState`]: struct.ParserState.html #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum Lookahead { + /// The positive predicate, written as an ampersand &, + /// attempts to match its inner expression. + /// If the inner expression succeeds, parsing continues, + /// but at the same position as the predicate — + /// &foo ~ bar is thus a kind of "AND" statement: + /// "the input string must match foo AND bar". + /// If the inner expression fails, + /// the whole expression fails too. Positive, + /// The negative predicate, written as an exclamation mark !, + /// attempts to match its inner expression. + /// If the inner expression fails, the predicate succeeds + /// and parsing continues at the same position as the predicate. + /// If the inner expression succeeds, the predicate fails — + /// !foo ~ bar is thus a kind of "NOT" statement: + /// "the input string must match bar but NOT foo". Negative, + /// No lookahead (i.e. it will consume input). None, } @@ -38,8 +54,16 @@ pub enum Lookahead { /// [`ParserState`]: struct.ParserState.html #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum Atomicity { + /// prevents implicit whitespace: inside an atomic rule, + /// the tilde ~ means "immediately followed by", + /// and repetition operators (asterisk * and plus sign +) + /// have no implicit separation. In addition, all other rules + /// called from an atomic rule are also treated as atomic. + /// (interior matching rules are silent) Atomic, + /// The same as atomic, but inner tokens are produced as normal. CompoundAtomic, + /// implicit whitespace is enabled NonAtomic, } @@ -49,7 +73,9 @@ pub type ParseResult = Result; /// Match direction for the stack. Used in `PEEK[a..b]`/`stack_match_peek_slice`. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum MatchDir { + /// from the bottom to the top of the stack BottomToTop, + /// from the top to the bottom of the stack TopToBottom, } @@ -121,6 +147,7 @@ pub struct ParserState<'i, R: RuleType> { /// let input = ""; /// pest::state::<(), _>(input, |s| Ok(s)).unwrap(); /// ``` +#[allow(clippy::perf)] pub fn state<'i, R: RuleType, F>(input: &'i str, f: F) -> Result, Error> where F: FnOnce(Box>) -> ParseResult>>, @@ -195,7 +222,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// } /// /// let input = "ab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let position = state.position(); /// assert_eq!(position.pos(), 0); /// ``` @@ -217,7 +244,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// } /// /// let input = "ab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let atomicity = state.atomicity(); /// assert_eq!(atomicity, Atomicity::NonAtomic); /// ``` @@ -464,7 +491,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// } /// /// let input = "aab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.repeat(|s| { /// s.match_string("a") /// }); @@ -508,7 +535,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// } /// /// let input = "ab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let result = state.optional(|s| { /// s.match_string("ab") /// }); @@ -544,13 +571,13 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "ab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let result = state.match_char_by(|c| c.is_ascii()); /// assert!(result.is_ok()); /// assert_eq!(result.unwrap().position().pos(), 1); /// /// let input = "❤"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let result = state.match_char_by(|c| c.is_ascii()); /// assert!(result.is_err()); /// assert_eq!(result.unwrap_err().position().pos(), 0); @@ -579,7 +606,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "ab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.match_string("ab"); /// assert!(result.is_ok()); /// assert_eq!(result.unwrap().position().pos(), 2); @@ -610,7 +637,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "ab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.match_insensitive("AB"); /// assert!(result.is_ok()); /// assert_eq!(result.unwrap().position().pos(), 2); @@ -632,6 +659,9 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// Attempts to match a single character from the given range. Returns `Ok` with the updated /// `Box` if successful, or `Err` with the updated `Box` otherwise. /// + /// # Caution + /// The provided `range` is intepreted as inclusive. + /// /// # Examples /// /// ``` @@ -641,7 +671,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "ab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.match_range('a'..'z'); /// assert!(result.is_ok()); /// assert_eq!(result.unwrap().position().pos(), 1); @@ -672,7 +702,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "ab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.skip(1); /// assert!(result.is_ok()); /// assert_eq!(result.unwrap().position().pos(), 1); @@ -703,7 +733,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "abcd"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.skip_until(&["c", "d"]); /// assert!(result.is_ok()); /// assert_eq!(result.unwrap().position().pos(), 2); @@ -726,7 +756,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "ab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.start_of_input(); /// assert!(result.is_ok()); /// @@ -756,7 +786,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "ab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.end_of_input(); /// assert!(result.is_err()); /// @@ -910,7 +940,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "ab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.stack_push(|state| state.match_string("a")); /// assert!(result.is_ok()); /// assert_eq!(result.unwrap().position().pos(), 1); @@ -947,7 +977,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "aa"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.stack_push(|state| state.match_string("a")).and_then( /// |state| state.stack_peek() /// ); @@ -976,7 +1006,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "aa"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.stack_push(|state| state.match_string("a")).and_then( /// |state| state.stack_pop() /// ); @@ -1004,7 +1034,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "abcd cd cb"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state /// .stack_push(|state| state.match_string("a")) /// .and_then(|state| state.stack_push(|state| state.match_string("b"))) @@ -1036,7 +1066,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { let mut position = self.position; let result = { let mut iter_b2t = self.stack[range].iter(); - let matcher = |span: &Span| position.match_string(span.as_str()); + let matcher = |span: &Span<'_>| position.match_string(span.as_str()); match match_dir { MatchDir::BottomToTop => iter_b2t.all(matcher), MatchDir::TopToBottom => iter_b2t.rev().all(matcher), @@ -1061,7 +1091,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "abba"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state /// .stack_push(|state| state.match_string("a")) /// .and_then(|state| { state.stack_push(|state| state.match_string("b")) }) @@ -1085,7 +1115,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "aaaa"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.stack_push(|state| state.match_string("a")).and_then(|state| { /// state.stack_push(|state| state.match_string("a")) /// }).and_then(|state| state.stack_match_peek()); @@ -1123,7 +1153,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "aa"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.stack_push(|state| state.match_string("a")).and_then( /// |state| state.stack_drop() /// ); @@ -1150,7 +1180,7 @@ impl<'i, R: RuleType> ParserState<'i, R> { /// enum Rule {} /// /// let input = "ab"; - /// let mut state: Box> = pest::ParserState::new(input); + /// let mut state: Box> = pest::ParserState::new(input); /// let mut result = state.restore_on_err(|state| state.stack_push(|state| /// state.match_string("a")).and_then(|state| state.match_string("a")) /// ); -- cgit v1.2.3