@@ -46,6 +46,9 @@ pub enum ParserError {
46
46
RecursionLimitExceeded ,
47
47
}
48
48
49
+ // avoid clippy type_complexity warnings
50
+ type ParsedAction = ( Keyword , Option < Vec < Ident > > ) ;
51
+
49
52
// Use `Parser::expected` instead, if possible
50
53
macro_rules! parser_err {
51
54
( $MSG: expr, $loc: expr) => {
@@ -3334,6 +3337,29 @@ impl<'a> Parser<'a> {
3334
3337
ret
3335
3338
}
3336
3339
3340
+ pub fn parse_actions_list ( & mut self ) -> Result < Vec < ParsedAction > , ParserError > {
3341
+ let mut values = vec ! [ ] ;
3342
+ loop {
3343
+ values. push ( self . parse_grant_permission ( ) ?) ;
3344
+ if !self . consume_token ( & Token :: Comma ) {
3345
+ break ;
3346
+ } else if self . options . trailing_commas {
3347
+ match self . peek_token ( ) . token {
3348
+ Token :: Word ( kw) if kw. keyword == Keyword :: ON => {
3349
+ break ;
3350
+ }
3351
+ Token :: RParen
3352
+ | Token :: SemiColon
3353
+ | Token :: EOF
3354
+ | Token :: RBracket
3355
+ | Token :: RBrace => break ,
3356
+ _ => continue ,
3357
+ }
3358
+ }
3359
+ }
3360
+ Ok ( values)
3361
+ }
3362
+
3337
3363
/// Parse a comma-separated list of 1+ items accepted by `F`
3338
3364
pub fn parse_comma_separated < T , F > ( & mut self , mut f : F ) -> Result < Vec < T > , ParserError >
3339
3365
where
@@ -3347,9 +3373,7 @@ impl<'a> Parser<'a> {
3347
3373
} else if self . options . trailing_commas {
3348
3374
match self . peek_token ( ) . token {
3349
3375
Token :: Word ( kw)
3350
- if keywords:: RESERVED_FOR_COLUMN_ALIAS
3351
- . iter ( )
3352
- . any ( |d| kw. keyword == * d) =>
3376
+ if keywords:: RESERVED_FOR_COLUMN_ALIAS . contains ( & kw. keyword ) =>
3353
3377
{
3354
3378
break ;
3355
3379
}
@@ -9680,11 +9704,8 @@ impl<'a> Parser<'a> {
9680
9704
with_privileges_keyword : self . parse_keyword ( Keyword :: PRIVILEGES ) ,
9681
9705
}
9682
9706
} else {
9683
- let old_value = self . options . trailing_commas ;
9684
- self . options . trailing_commas = false ;
9685
-
9686
9707
let ( actions, err) : ( Vec < _ > , Vec < _ > ) = self
9687
- . parse_comma_separated ( Parser :: parse_grant_permission ) ?
9708
+ . parse_actions_list ( ) ?
9688
9709
. into_iter ( )
9689
9710
. map ( |( kw, columns) | match kw {
9690
9711
Keyword :: DELETE => Ok ( Action :: Delete ) ,
@@ -9706,8 +9727,6 @@ impl<'a> Parser<'a> {
9706
9727
} )
9707
9728
. partition ( Result :: is_ok) ;
9708
9729
9709
- self . options . trailing_commas = old_value;
9710
-
9711
9730
if !err. is_empty ( ) {
9712
9731
let errors: Vec < Keyword > = err. into_iter ( ) . filter_map ( |x| x. err ( ) ) . collect ( ) ;
9713
9732
return Err ( ParserError :: ParserError ( format ! (
@@ -9753,7 +9772,7 @@ impl<'a> Parser<'a> {
9753
9772
Ok ( ( privileges, objects) )
9754
9773
}
9755
9774
9756
- pub fn parse_grant_permission ( & mut self ) -> Result < ( Keyword , Option < Vec < Ident > > ) , ParserError > {
9775
+ pub fn parse_grant_permission ( & mut self ) -> Result < ParsedAction , ParserError > {
9757
9776
if let Some ( kw) = self . parse_one_of_keywords ( & [
9758
9777
Keyword :: CONNECT ,
9759
9778
Keyword :: CREATE ,
0 commit comments