Skip to content

Commit 266d8a2

Browse files
committed
eliminate maybe macro
1 parent a34b912 commit 266d8a2

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

src/parser.rs

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

37-
macro_rules! maybe {
38-
($e:expr) => {{
39-
if let Some(v) = $e {
40-
return Ok(v);
41-
}
42-
}};
43-
}
44-
4537
#[derive(PartialEq)]
4638
pub enum IsOptional {
4739
Optional,
@@ -198,19 +190,19 @@ impl Parser {
198190
// INTERVAL '7' DAY
199191
//
200192
// Note also that naively `SELECT date` looks like a syntax error because the `date` type
201-
// name is not followed by a string literal, but in fact in PostgreSQL it is a valid
193+
// name is not followed by a string literal, but in fact in PostgreSQL it is a valid
202194
// expression that should parse as the column name "date".
203-
maybe!(self.maybe_parse(|parser| {
204-
match parser.parse_data_type()? {
205-
DataType::Interval => parser.parse_literal_interval(),
206-
data_type => Ok(Expr::Cast {
207-
expr: Box::new(Expr::Value(Value::SingleQuotedString(
208-
parser.parse_literal_string()?,
209-
))),
210-
data_type,
211-
}),
212-
}
213-
}));
195+
if let Some(parsed) = self.maybe_parse(|parser| match parser.parse_data_type()? {
196+
DataType::Interval => parser.parse_literal_interval(),
197+
data_type => Ok(Expr::Cast {
198+
expr: Box::new(Expr::Value(Value::SingleQuotedString(
199+
parser.parse_literal_string()?,
200+
))),
201+
data_type,
202+
}),
203+
}) {
204+
return Ok(parsed);
205+
}
214206

215207
let tok = self
216208
.next_token()
@@ -1975,7 +1967,11 @@ impl Parser {
19751967
// Check if the recently consumed '(' started a derived table, in which case we've
19761968
// parsed the subquery, followed by the closing ')', and the alias of the derived
19771969
// table. In the example above this is case (3), or another nested join (2).
1978-
maybe!(self.maybe_parse(|parser| parser.parse_derived_table_factor(NotLateral)));
1970+
if let Some(parsed) =
1971+
self.maybe_parse(|parser| parser.parse_derived_table_factor(NotLateral))
1972+
{
1973+
return Ok(parsed);
1974+
}
19791975

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

0 commit comments

Comments
 (0)