Skip to content

Commit 912019b

Browse files
committed
reintroduce maybe macro with a new name
1 parent a848935 commit 912019b

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/parser.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ macro_rules! parser_err {
3434
};
3535
}
3636

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+
3746
#[derive(PartialEq)]
3847
pub enum IsOptional {
3948
Optional,
@@ -192,7 +201,7 @@ impl Parser {
192201
// Note also that naively `SELECT date` looks like a syntax error because the `date` type
193202
// name is not followed by a string literal, but in fact in PostgreSQL it is a valid
194203
// 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()? {
196205
DataType::Interval => parser.parse_literal_interval(),
197206
// Single-quoted strings are parsed as custom data types, however this not desirable
198207
// when we are handling input like `"NOT 'a' NOT LIKE 'b'"` because this will produce a
@@ -204,9 +213,7 @@ impl Parser {
204213
data_type,
205214
value: parser.parse_literal_string()?,
206215
}),
207-
}) {
208-
return Ok(parsed);
209-
}
216+
}));
210217

211218
let tok = self
212219
.next_token()
@@ -1975,11 +1982,9 @@ impl Parser {
19751982
// A parsing error from `parse_derived_table_factor` indicates that the '(' we've
19761983
// recently consumed does not start a derived table (cases 1, 2, or 4). Ignore the
19771984
// error and back up to where we after the opening '('.
1978-
if let Some(parsed) =
1985+
return_ok_if_some!(
19791986
self.maybe_parse(|parser| parser.parse_derived_table_factor(NotLateral))
1980-
{
1981-
return Ok(parsed);
1982-
}
1987+
);
19831988

19841989
// Inside the parentheses we expect to find a table factor
19851990
// followed by some joins or another level of nesting.

0 commit comments

Comments
 (0)