mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-01 19:57:30 +00:00
Simplify by using expect_keyword / expect_token (3/8)
...instead of parse_keyword / consume_token - to reduce nesting of `if`s. (Follow-up to PR #35)
This commit is contained in:
parent
f87230553e
commit
8c3479969f
1 changed files with 49 additions and 64 deletions
|
@ -589,7 +589,7 @@ impl Parser {
|
||||||
} else if is_unique_key {
|
} else if is_unique_key {
|
||||||
Ok(TableKey::UniqueKey(key))
|
Ok(TableKey::UniqueKey(key))
|
||||||
} else if is_foreign_key {
|
} else if is_foreign_key {
|
||||||
if self.parse_keyword("REFERENCES") {
|
self.expect_keyword("REFERENCES")?;
|
||||||
let foreign_table = self.parse_tablename()?;
|
let foreign_table = self.parse_tablename()?;
|
||||||
self.expect_token(&Token::LParen)?;
|
self.expect_token(&Token::LParen)?;
|
||||||
let referred_columns = self.parse_column_names()?;
|
let referred_columns = self.parse_column_names()?;
|
||||||
|
@ -599,9 +599,6 @@ impl Parser {
|
||||||
foreign_table,
|
foreign_table,
|
||||||
referred_columns,
|
referred_columns,
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
parser_err!("Expecting references")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
parser_err!(format!(
|
parser_err!(format!(
|
||||||
"Expecting primary key, unique key, or foreign key, found: {:?}",
|
"Expecting primary key, unique key, or foreign key, found: {:?}",
|
||||||
|
@ -611,7 +608,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_alter(&mut self) -> Result<ASTNode, ParserError> {
|
pub fn parse_alter(&mut self) -> Result<ASTNode, ParserError> {
|
||||||
if self.parse_keyword("TABLE") {
|
self.expect_keyword("TABLE")?;
|
||||||
let _ = self.parse_keyword("ONLY");
|
let _ = self.parse_keyword("ONLY");
|
||||||
let table_name = self.parse_tablename()?;
|
let table_name = self.parse_tablename()?;
|
||||||
let operation: Result<AlterOperation, ParserError> =
|
let operation: Result<AlterOperation, ParserError> =
|
||||||
|
@ -638,12 +635,6 @@ impl Parser {
|
||||||
name: table_name,
|
name: table_name,
|
||||||
operation: operation?,
|
operation: operation?,
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
parser_err!(format!(
|
|
||||||
"Expecting TABLE after ALTER, found {:?}",
|
|
||||||
self.peek_token()
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a copy statement
|
/// Parse a copy statement
|
||||||
|
@ -1142,7 +1133,7 @@ impl Parser {
|
||||||
let constraint = self.parse_expr(0)?;
|
let constraint = self.parse_expr(0)?;
|
||||||
Ok(JoinConstraint::On(constraint))
|
Ok(JoinConstraint::On(constraint))
|
||||||
} else if self.parse_keyword("USING") {
|
} else if self.parse_keyword("USING") {
|
||||||
if self.consume_token(&Token::LParen) {
|
self.expect_token(&Token::LParen)?;
|
||||||
let attributes = self
|
let attributes = self
|
||||||
.parse_expr_list()?
|
.parse_expr_list()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -1154,14 +1145,8 @@ impl Parser {
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<String>, ParserError>>()?;
|
.collect::<Result<Vec<String>, ParserError>>()?;
|
||||||
|
|
||||||
if self.consume_token(&Token::RParen) {
|
self.expect_token(&Token::RParen)?;
|
||||||
Ok(JoinConstraint::Using(attributes))
|
Ok(JoinConstraint::Using(attributes))
|
||||||
} else {
|
|
||||||
parser_err!(format!("Expected token ')', found {:?}", self.peek_token()))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
parser_err!(format!("Expected token '(', found {:?}", self.peek_token()))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
parser_err!(format!(
|
parser_err!(format!(
|
||||||
"Unexpected token after JOIN: {:?}",
|
"Unexpected token after JOIN: {:?}",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue