This is an automated email from the ASF dual-hosted git repository.

iffyio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new fe360208 Simplify `parse_keyword_apis` more (#1626)
fe360208 is described below

commit fe360208900a287872fc9875e9e6cb7d3a662302
Author: Andrew Lamb <[email protected]>
AuthorDate: Sun Dec 29 08:20:17 2024 -0500

    Simplify `parse_keyword_apis` more (#1626)
---
 src/parser/mod.rs | 34 ++++++++--------------------------
 1 file changed, 8 insertions(+), 26 deletions(-)

diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index ec91bf00..012314b4 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -3709,7 +3709,7 @@ impl<'a> Parser<'a> {
         )
     }
 
-    /// Report that the current token was found instead of `expected`.
+    /// Report that the token at `index` was found instead of `expected`.
     pub fn expected_at<T>(&self, expected: &str, index: usize) -> Result<T, 
ParserError> {
         let found = self.tokens.get(index).unwrap_or(&EOF_TOKEN);
         parser_err!(
@@ -3730,27 +3730,6 @@ impl<'a> Parser<'a> {
         }
     }
 
-    /// If the current token is the `expected` keyword, consume it and returns
-    ///
-    /// See [`Self::parse_keyword_token_ref`] to avoid the copy.
-    #[must_use]
-    pub fn parse_keyword_token(&mut self, expected: Keyword) -> 
Option<TokenWithSpan> {
-        self.parse_keyword_token_ref(expected).cloned()
-    }
-
-    /// If the current token is the `expected` keyword, consume it and returns 
a reference to the next token.
-    ///
-    #[must_use]
-    pub fn parse_keyword_token_ref(&mut self, expected: Keyword) -> 
Option<&TokenWithSpan> {
-        match &self.peek_token_ref().token {
-            Token::Word(w) if expected == w.keyword => {
-                self.advance_token();
-                Some(self.get_current_token())
-            }
-            _ => None,
-        }
-    }
-
     #[must_use]
     pub fn peek_keyword(&self, expected: Keyword) -> bool {
         matches!(&self.peek_token_ref().token, Token::Word(w) if expected == 
w.keyword)
@@ -3833,9 +3812,11 @@ impl<'a> Parser<'a> {
 
     /// If the current token is the `expected` keyword, consume the token.
     /// Otherwise, return an error.
+    ///
+    // todo deprecate infavor of expected_keyword_is
     pub fn expect_keyword(&mut self, expected: Keyword) -> 
Result<TokenWithSpan, ParserError> {
-        if let Some(token) = self.parse_keyword_token_ref(expected) {
-            Ok(token.clone())
+        if self.parse_keyword(expected) {
+            Ok(self.get_current_token().clone())
         } else {
             self.expected_ref(format!("{:?}", &expected).as_str(), 
self.peek_token_ref())
         }
@@ -3847,7 +3828,7 @@ impl<'a> Parser<'a> {
     /// This differs from expect_keyword only in that the matched keyword
     /// token is not returned.
     pub fn expect_keyword_is(&mut self, expected: Keyword) -> Result<(), 
ParserError> {
-        if self.parse_keyword_token_ref(expected).is_some() {
+        if self.parse_keyword(expected) {
             Ok(())
         } else {
             self.expected_ref(format!("{:?}", &expected).as_str(), 
self.peek_token_ref())
@@ -9488,7 +9469,8 @@ impl<'a> Parser<'a> {
     /// expect the initial keyword to be already consumed
     pub fn parse_query(&mut self) -> Result<Box<Query>, ParserError> {
         let _guard = self.recursion_counter.try_decrease()?;
-        let with = if let Some(with_token) = 
self.parse_keyword_token_ref(Keyword::WITH) {
+        let with = if self.parse_keyword(Keyword::WITH) {
+            let with_token = self.get_current_token();
             Some(With {
                 with_token: with_token.clone().into(),
                 recursive: self.parse_keyword(Keyword::RECURSIVE),


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to