@@ -2791,6 +2791,31 @@ impl<'a> Parser<'a> {
2791
2791
}
2792
2792
}
2793
2793
2794
+ /// If the current token is the `expected` keyword followed by
2795
+ /// specified tokens, consume them and returns true.
2796
+ /// Otherwise, no tokens are consumed and returns false.
2797
+ ///
2798
+ /// Note that if the length of `tokens` is too long, this function will
2799
+ /// not be efficient as it does a loop on the tokens with `peek_nth_token`
2800
+ /// each time.
2801
+ pub fn parse_keyword_with_tokens ( & mut self , expected : Keyword , tokens : & [ Token ] ) -> bool {
2802
+ match self . peek_token ( ) . token {
2803
+ Token :: Word ( w) if expected == w. keyword => {
2804
+ for ( idx, token) in tokens. iter ( ) . enumerate ( ) {
2805
+ if self . peek_nth_token ( idx + 1 ) . token != * token {
2806
+ return false ;
2807
+ }
2808
+ }
2809
+ // consume all tokens
2810
+ for _ in 0 ..( tokens. len ( ) + 1 ) {
2811
+ self . next_token ( ) ;
2812
+ }
2813
+ true
2814
+ }
2815
+ _ => false ,
2816
+ }
2817
+ }
2818
+
2794
2819
/// If the current and subsequent tokens exactly match the `keywords`
2795
2820
/// sequence, consume them and returns true. Otherwise, no tokens are
2796
2821
/// consumed and returns false
@@ -7555,12 +7580,7 @@ impl<'a> Parser<'a> {
7555
7580
with_offset,
7556
7581
with_offset_alias,
7557
7582
} )
7558
- } else if matches ! (
7559
- self . peek_token( ) . token, Token :: Word ( w)
7560
- if w. keyword == Keyword :: JSON_TABLE && self . peek_nth_token( 1 ) . token == Token :: LParen
7561
- ) {
7562
- self . expect_keyword ( Keyword :: JSON_TABLE ) ?;
7563
- self . expect_token ( & Token :: LParen ) ?;
7583
+ } else if self . parse_keyword_with_tokens ( Keyword :: JSON_TABLE , & [ Token :: LParen ] ) {
7564
7584
let json_expr = self . parse_expr ( ) ?;
7565
7585
self . expect_token ( & Token :: Comma ) ?;
7566
7586
let json_path = self . parse_value ( ) ?;
0 commit comments