Skip to content

Commit 8206523

Browse files
committed
Minor consume_token()-related simplifications
- use `if !self.consume_token(&Token::Comma) { break; }` to consume the comma and exit the loop if no comma found. - coalesce two `{ false }` blocks in `consume_token` by using a match guard
1 parent 2308c1c commit 8206523

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

src/sqlparser.rs

+11-20
Original file line numberDiff line numberDiff line change
@@ -702,14 +702,10 @@ impl Parser {
702702
/// Consume the next token if it matches the expected token, otherwise return false
703703
#[must_use]
704704
pub fn consume_token(&mut self, expected: &Token) -> bool {
705-
match self.peek_token() {
706-
Some(ref t) => {
707-
if *t == *expected {
708-
self.next_token();
709-
true
710-
} else {
711-
false
712-
}
705+
match &self.peek_token() {
706+
Some(t) if *t == *expected => {
707+
self.next_token();
708+
true
713709
}
714710
_ => false,
715711
}
@@ -1611,10 +1607,9 @@ impl Parser {
16111607
let mut expr_list: Vec<ASTNode> = vec![];
16121608
loop {
16131609
expr_list.push(self.parse_expr()?);
1614-
match self.peek_token() {
1615-
Some(Token::Comma) => self.next_token(),
1616-
_ => break,
1617-
};
1610+
if !self.consume_token(&Token::Comma) {
1611+
break;
1612+
}
16181613
}
16191614
Ok(expr_list)
16201615
}
@@ -1649,10 +1644,9 @@ impl Parser {
16491644
}
16501645
}
16511646

1652-
match self.peek_token() {
1653-
Some(Token::Comma) => self.next_token(),
1654-
_ => break,
1655-
};
1647+
if !self.consume_token(&Token::Comma) {
1648+
break;
1649+
}
16561650
}
16571651
Ok(projections)
16581652
}
@@ -1672,10 +1666,7 @@ impl Parser {
16721666
};
16731667

16741668
expr_list.push(SQLOrderByExpr { expr, asc });
1675-
1676-
if let Some(Token::Comma) = self.peek_token() {
1677-
self.next_token();
1678-
} else {
1669+
if !self.consume_token(&Token::Comma) {
16791670
break;
16801671
}
16811672
}

0 commit comments

Comments
 (0)