@@ -34,6 +34,15 @@ macro_rules! parser_err {
34
34
} ;
35
35
}
36
36
37
+ // Returns a successful result if the optional expression is some
38
+ macro_rules! return_ok_if_some {
39
+ ( $e: expr) => { {
40
+ if let Some ( v) = $e {
41
+ return Ok ( v) ;
42
+ }
43
+ } } ;
44
+ }
45
+
37
46
#[ derive( PartialEq ) ]
38
47
pub enum IsOptional {
39
48
Optional ,
@@ -192,7 +201,7 @@ impl Parser {
192
201
// Note also that naively `SELECT date` looks like a syntax error because the `date` type
193
202
// name is not followed by a string literal, but in fact in PostgreSQL it is a valid
194
203
// expression that should parse as the column name "date".
195
- if let Some ( parsed ) = self . maybe_parse ( |parser| match parser. parse_data_type ( ) ? {
204
+ return_ok_if_some ! ( self . maybe_parse( |parser| match parser. parse_data_type( ) ? {
196
205
DataType :: Interval => parser. parse_literal_interval( ) ,
197
206
// Single-quoted strings are parsed as custom data types, however this not desirable
198
207
// when we are handling input like `"NOT 'a' NOT LIKE 'b'"` because this will produce a
@@ -204,9 +213,7 @@ impl Parser {
204
213
data_type,
205
214
value: parser. parse_literal_string( ) ?,
206
215
} ) ,
207
- } ) {
208
- return Ok ( parsed) ;
209
- }
216
+ } ) ) ;
210
217
211
218
let tok = self
212
219
. next_token ( )
@@ -1975,11 +1982,9 @@ impl Parser {
1975
1982
// A parsing error from `parse_derived_table_factor` indicates that the '(' we've
1976
1983
// recently consumed does not start a derived table (cases 1, 2, or 4). Ignore the
1977
1984
// error and back up to where we after the opening '('.
1978
- if let Some ( parsed ) =
1985
+ return_ok_if_some ! (
1979
1986
self . maybe_parse( |parser| parser. parse_derived_table_factor( NotLateral ) )
1980
- {
1981
- return Ok ( parsed) ;
1982
- }
1987
+ ) ;
1983
1988
1984
1989
// Inside the parentheses we expect to find a table factor
1985
1990
// followed by some joins or another level of nesting.
0 commit comments