mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-08 01:15:00 +00:00
Use expect_keyword() instead of consume_token() where appropriate
Before this missing keywords THEN/WHEN/AS would be parsed as if they were in the text as the code didn't check the return value of consume_token() - see upcoming commit.
This commit is contained in:
parent
de4ccd3cb7
commit
b3ab4aca88
1 changed files with 3 additions and 3 deletions
|
@ -204,7 +204,7 @@ impl Parser {
|
|||
let mut else_result = None;
|
||||
loop {
|
||||
conditions.push(self.parse_expr(0)?);
|
||||
self.consume_token(&Token::Keyword("THEN".to_string()))?;
|
||||
self.expect_keyword("THEN")?;
|
||||
results.push(self.parse_expr(0)?);
|
||||
if self.parse_keywords(vec!["ELSE"]) {
|
||||
else_result = Some(Box::new(self.parse_expr(0)?));
|
||||
|
@ -217,7 +217,7 @@ impl Parser {
|
|||
if self.parse_keywords(vec!["END"]) {
|
||||
break;
|
||||
}
|
||||
self.consume_token(&Token::Keyword("WHEN".to_string()))?;
|
||||
self.expect_keyword("WHEN")?;
|
||||
}
|
||||
Ok(ASTNode::SQLCase {
|
||||
conditions,
|
||||
|
@ -235,7 +235,7 @@ impl Parser {
|
|||
pub fn parse_cast_expression(&mut self) -> Result<ASTNode, ParserError> {
|
||||
self.consume_token(&Token::LParen)?;
|
||||
let expr = self.parse_expr(0)?;
|
||||
self.consume_token(&Token::Keyword("AS".to_string()))?;
|
||||
self.expect_keyword("AS")?;
|
||||
let data_type = self.parse_data_type()?;
|
||||
self.consume_token(&Token::RParen)?;
|
||||
Ok(ASTNode::SQLCast {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue