@@ -3719,7 +3719,7 @@ impl<'a> Parser<'a> {
3719
3719
)
3720
3720
}
3721
3721
3722
- /// Report that the current token was found instead of `expected`.
3722
+ /// Report that the token at `index` was found instead of `expected`.
3723
3723
pub fn expected_at<T>(&self, expected: &str, index: usize) -> Result<T, ParserError> {
3724
3724
let found = self.tokens.get(index).unwrap_or(&EOF_TOKEN);
3725
3725
parser_err!(
@@ -3740,27 +3740,6 @@ impl<'a> Parser<'a> {
3740
3740
}
3741
3741
}
3742
3742
3743
- /// If the current token is the `expected` keyword, consume it and returns
3744
- ///
3745
- /// See [`Self::parse_keyword_token_ref`] to avoid the copy.
3746
- #[must_use]
3747
- pub fn parse_keyword_token(&mut self, expected: Keyword) -> Option<TokenWithSpan> {
3748
- self.parse_keyword_token_ref(expected).cloned()
3749
- }
3750
-
3751
- /// If the current token is the `expected` keyword, consume it and returns a reference to the next token.
3752
- ///
3753
- #[must_use]
3754
- pub fn parse_keyword_token_ref(&mut self, expected: Keyword) -> Option<&TokenWithSpan> {
3755
- match &self.peek_token_ref().token {
3756
- Token::Word(w) if expected == w.keyword => {
3757
- self.advance_token();
3758
- Some(self.get_current_token())
3759
- }
3760
- _ => None,
3761
- }
3762
- }
3763
-
3764
3743
#[must_use]
3765
3744
pub fn peek_keyword(&self, expected: Keyword) -> bool {
3766
3745
matches!(&self.peek_token_ref().token, Token::Word(w) if expected == w.keyword)
@@ -3843,9 +3822,11 @@ impl<'a> Parser<'a> {
3843
3822
3844
3823
/// If the current token is the `expected` keyword, consume the token.
3845
3824
/// Otherwise, return an error.
3825
+ ///
3826
+ // todo deprecate infavor of expected_keyword_is
3846
3827
pub fn expect_keyword(&mut self, expected: Keyword) -> Result<TokenWithSpan, ParserError> {
3847
- if let Some(token) = self.parse_keyword_token_ref (expected) {
3848
- Ok(token .clone())
3828
+ if self.parse_keyword (expected) {
3829
+ Ok(self.get_current_token() .clone())
3849
3830
} else {
3850
3831
self.expected_ref(format!("{:?}", &expected).as_str(), self.peek_token_ref())
3851
3832
}
@@ -3857,7 +3838,7 @@ impl<'a> Parser<'a> {
3857
3838
/// This differs from expect_keyword only in that the matched keyword
3858
3839
/// token is not returned.
3859
3840
pub fn expect_keyword_is(&mut self, expected: Keyword) -> Result<(), ParserError> {
3860
- if self.parse_keyword_token_ref (expected).is_some( ) {
3841
+ if self.parse_keyword (expected) {
3861
3842
Ok(())
3862
3843
} else {
3863
3844
self.expected_ref(format!("{:?}", &expected).as_str(), self.peek_token_ref())
@@ -9498,7 +9479,8 @@ impl<'a> Parser<'a> {
9498
9479
/// expect the initial keyword to be already consumed
9499
9480
pub fn parse_query(&mut self) -> Result<Box<Query>, ParserError> {
9500
9481
let _guard = self.recursion_counter.try_decrease()?;
9501
- let with = if let Some(with_token) = self.parse_keyword_token_ref(Keyword::WITH) {
9482
+ let with = if self.parse_keyword(Keyword::WITH) {
9483
+ let with_token = self.get_current_token();
9502
9484
Some(With {
9503
9485
with_token: with_token.clone().into(),
9504
9486
recursive: self.parse_keyword(Keyword::RECURSIVE),
0 commit comments