@@ -1849,17 +1849,9 @@ impl<'a> Parser<'a> {
1849
1849
/// Parses an array expression `[ex1, ex2, ..]`
1850
1850
/// if `named` is `true`, came from an expression like `ARRAY[ex1, ex2]`
1851
1851
pub fn parse_array_expr ( & mut self , named : bool ) -> Result < Expr , ParserError > {
1852
- if self . peek_token ( ) . token == Token :: RBracket {
1853
- let _ = self . next_token ( ) ; // consume ]
1854
- Ok ( Expr :: Array ( Array {
1855
- elem : vec ! [ ] ,
1856
- named,
1857
- } ) )
1858
- } else {
1859
- let exprs = self . parse_comma_separated ( Parser :: parse_expr) ?;
1860
- self . expect_token ( & Token :: RBracket ) ?;
1861
- Ok ( Expr :: Array ( Array { elem : exprs, named } ) )
1862
- }
1852
+ let exprs = self . parse_comma_separated0 ( Parser :: parse_expr, Token :: RBracket ) ?;
1853
+ self . expect_token ( & Token :: RBracket ) ?;
1854
+ Ok ( Expr :: Array ( Array { elem : exprs, named } ) )
1863
1855
}
1864
1856
1865
1857
pub fn parse_listagg_on_overflow ( & mut self ) -> Result < Option < ListAggOnOverflow > , ParserError > {
@@ -2352,11 +2344,8 @@ impl<'a> Parser<'a> {
2352
2344
/// [map]: https://duckdb.org/docs/sql/data_types/map.html#creating-maps
2353
2345
fn parse_duckdb_map_literal ( & mut self ) -> Result < Expr , ParserError > {
2354
2346
self . expect_token ( & Token :: LBrace ) ?;
2355
-
2356
- let fields = self . parse_comma_separated ( Self :: parse_duckdb_map_field) ?;
2357
-
2347
+ let fields = self . parse_comma_separated0 ( Self :: parse_duckdb_map_field, Token :: RBrace ) ?;
2358
2348
self . expect_token ( & Token :: RBrace ) ?;
2359
-
2360
2349
Ok ( Expr :: Map ( Map { entries : fields } ) )
2361
2350
}
2362
2351
@@ -2937,7 +2926,7 @@ impl<'a> Parser<'a> {
2937
2926
Expr :: InList {
2938
2927
expr : Box :: new ( expr) ,
2939
2928
list : if self . dialect . supports_in_empty_list ( ) {
2940
- self . parse_comma_separated0 ( Parser :: parse_expr) ?
2929
+ self . parse_comma_separated0 ( Parser :: parse_expr, Token :: RParen ) ?
2941
2930
} else {
2942
2931
self . parse_comma_separated ( Parser :: parse_expr) ?
2943
2932
} ,
@@ -3479,18 +3468,20 @@ impl<'a> Parser<'a> {
3479
3468
}
3480
3469
3481
3470
/// Parse a comma-separated list of 0+ items accepted by `F`
3482
- pub fn parse_comma_separated0 < T , F > ( & mut self , f : F ) -> Result < Vec < T > , ParserError >
3471
+ /// * `end_token` - expected end token for the closure (e.g. [Token::RParen], [Token::RBrace] ...)
3472
+ pub fn parse_comma_separated0 < T , F > (
3473
+ & mut self ,
3474
+ f : F ,
3475
+ end_token : Token ,
3476
+ ) -> Result < Vec < T > , ParserError >
3483
3477
where
3484
3478
F : FnMut ( & mut Parser < ' a > ) -> Result < T , ParserError > ,
3485
3479
{
3486
- // ()
3487
- if matches ! ( self . peek_token( ) . token, Token :: RParen ) {
3480
+ if self . peek_token ( ) . token == end_token {
3488
3481
return Ok ( vec ! [ ] ) ;
3489
3482
}
3490
- // (,)
3491
- if self . options . trailing_commas
3492
- && matches ! ( self . peek_tokens( ) , [ Token :: Comma , Token :: RParen ] )
3493
- {
3483
+
3484
+ if self . options . trailing_commas && self . peek_tokens ( ) == [ Token :: Comma , end_token] {
3494
3485
let _ = self . consume_token ( & Token :: Comma ) ;
3495
3486
return Ok ( vec ! [ ] ) ;
3496
3487
}
@@ -4059,7 +4050,7 @@ impl<'a> Parser<'a> {
4059
4050
} )
4060
4051
} ;
4061
4052
self . expect_token ( & Token :: LParen ) ?;
4062
- let args = self . parse_comma_separated0 ( parse_function_param) ?;
4053
+ let args = self . parse_comma_separated0 ( parse_function_param, Token :: RParen ) ?;
4063
4054
self . expect_token ( & Token :: RParen ) ?;
4064
4055
4065
4056
let return_type = if self . parse_keyword ( Keyword :: RETURNS ) {
@@ -10713,7 +10704,8 @@ impl<'a> Parser<'a> {
10713
10704
}
10714
10705
10715
10706
if self . consume_token ( & Token :: LParen ) {
10716
- let interpolations = self . parse_comma_separated0 ( |p| p. parse_interpolation ( ) ) ?;
10707
+ let interpolations =
10708
+ self . parse_comma_separated0 ( |p| p. parse_interpolation ( ) , Token :: RParen ) ?;
10717
10709
self . expect_token ( & Token :: RParen ) ?;
10718
10710
// INTERPOLATE () and INTERPOLATE ( ... ) variants
10719
10711
return Ok ( Some ( Interpolate {
0 commit comments