@@ -3709,7 +3709,7 @@ impl<'a> Parser<'a> {
3709
3709
)
3710
3710
}
3711
3711
3712
- /// Report that the current token was found instead of `expected`.
3712
+ /// Report that the token at `index` was found instead of `expected`.
3713
3713
pub fn expected_at<T>(&self, expected: &str, index: usize) -> Result<T, ParserError> {
3714
3714
let found = self.tokens.get(index).unwrap_or(&EOF_TOKEN);
3715
3715
parser_err!(
@@ -3730,27 +3730,6 @@ impl<'a> Parser<'a> {
3730
3730
}
3731
3731
}
3732
3732
3733
- /// If the current token is the `expected` keyword, consume it and returns
3734
- ///
3735
- /// See [`Self::parse_keyword_token_ref`] to avoid the copy.
3736
- #[must_use]
3737
- pub fn parse_keyword_token(&mut self, expected: Keyword) -> Option<TokenWithSpan> {
3738
- self.parse_keyword_token_ref(expected).cloned()
3739
- }
3740
-
3741
- /// If the current token is the `expected` keyword, consume it and returns a reference to the next token.
3742
- ///
3743
- #[must_use]
3744
- pub fn parse_keyword_token_ref(&mut self, expected: Keyword) -> Option<&TokenWithSpan> {
3745
- match &self.peek_token_ref().token {
3746
- Token::Word(w) if expected == w.keyword => {
3747
- self.advance_token();
3748
- Some(self.get_current_token())
3749
- }
3750
- _ => None,
3751
- }
3752
- }
3753
-
3754
3733
#[must_use]
3755
3734
pub fn peek_keyword(&self, expected: Keyword) -> bool {
3756
3735
matches!(&self.peek_token_ref().token, Token::Word(w) if expected == w.keyword)
@@ -3833,9 +3812,11 @@ impl<'a> Parser<'a> {
3833
3812
3834
3813
/// If the current token is the `expected` keyword, consume the token.
3835
3814
/// Otherwise, return an error.
3815
+ ///
3816
+ // todo deprecate infavor of expected_keyword_is
3836
3817
pub fn expect_keyword(&mut self, expected: Keyword) -> Result<TokenWithSpan, ParserError> {
3837
- if let Some(token) = self.parse_keyword_token_ref (expected) {
3838
- Ok(token .clone())
3818
+ if self.parse_keyword (expected) {
3819
+ Ok(self.get_current_token() .clone())
3839
3820
} else {
3840
3821
self.expected_ref(format!("{:?}", &expected).as_str(), self.peek_token_ref())
3841
3822
}
@@ -3847,7 +3828,7 @@ impl<'a> Parser<'a> {
3847
3828
/// This differs from expect_keyword only in that the matched keyword
3848
3829
/// token is not returned.
3849
3830
pub fn expect_keyword_is(&mut self, expected: Keyword) -> Result<(), ParserError> {
3850
- if self.parse_keyword_token_ref (expected).is_some( ) {
3831
+ if self.parse_keyword (expected) {
3851
3832
Ok(())
3852
3833
} else {
3853
3834
self.expected_ref(format!("{:?}", &expected).as_str(), self.peek_token_ref())
@@ -9488,7 +9469,8 @@ impl<'a> Parser<'a> {
9488
9469
/// expect the initial keyword to be already consumed
9489
9470
pub fn parse_query(&mut self) -> Result<Box<Query>, ParserError> {
9490
9471
let _guard = self.recursion_counter.try_decrease()?;
9491
- let with = if let Some(with_token) = self.parse_keyword_token_ref(Keyword::WITH) {
9472
+ let with = if self.parse_keyword(Keyword::WITH) {
9473
+ let with_token = self.get_current_token();
9492
9474
Some(With {
9493
9475
with_token: with_token.clone().into(),
9494
9476
recursive: self.parse_keyword(Keyword::RECURSIVE),
0 commit comments