mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-31 19:27:21 +00:00
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:
parent
2308c1c6f7
commit
8206523416
1 changed files with 11 additions and 20 deletions
|
@ -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 {
|
||||
self.next_token();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
match &self.peek_token() {
|
||||
Some(t) if *t == *expected => {
|
||||
self.next_token();
|
||||
true
|
||||
}
|
||||
_ => 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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue