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
This commit is contained in:
Nickolay Ponomarev 2019-06-03 01:27:18 +03:00
parent 2308c1c6f7
commit 8206523416

View file

@ -702,14 +702,10 @@ impl Parser {
/// Consume the next token if it matches the expected token, otherwise return false
#[must_use]
pub fn consume_token(&mut self, expected: &Token) -> bool {
match self.peek_token() {
Some(ref t) => {
if *t == *expected {
match &self.peek_token() {
Some(t) if *t == *expected => {
self.next_token();
true
} else {
false
}
}
_ => false,
}
@ -1611,10 +1607,9 @@ impl Parser {
let mut expr_list: Vec<ASTNode> = vec![];
loop {
expr_list.push(self.parse_expr()?);
match self.peek_token() {
Some(Token::Comma) => self.next_token(),
_ => break,
};
if !self.consume_token(&Token::Comma) {
break;
}
}
Ok(expr_list)
}
@ -1649,10 +1644,9 @@ impl Parser {
}
}
match self.peek_token() {
Some(Token::Comma) => self.next_token(),
_ => break,
};
if !self.consume_token(&Token::Comma) {
break;
}
}
Ok(projections)
}
@ -1672,10 +1666,7 @@ impl Parser {
};
expr_list.push(SQLOrderByExpr { expr, asc });
if let Some(Token::Comma) = self.peek_token() {
self.next_token();
} else {
if !self.consume_token(&Token::Comma) {
break;
}
}