Skip to content

Commit f5bd9c3

Browse files
committed
Simplify by avoiding SQLCompoundIdentifier (4.3/4.4)
...instead make `parse_compound_identifier()` return the underlying Vec<> directly, and rename it to `parse_list_of_ids()`, since it's used both for parsing compound identifiers and lists of identifiers.
1 parent 39e98cb commit f5bd9c3

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/sqlparser.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ impl Parser {
10281028
}
10291029

10301030
/// Parse one or more identifiers with the specified separator between them
1031-
pub fn parse_compound_identifier(&mut self, separator: &Token) -> Result<ASTNode, ParserError> {
1031+
pub fn parse_list_of_ids(&mut self, separator: &Token) -> Result<Vec<SQLIdent>, ParserError> {
10321032
let mut idents = vec![];
10331033
let mut expect_identifier = true;
10341034
loop {
@@ -1056,27 +1056,19 @@ impl Parser {
10561056
self.peek_token()
10571057
))
10581058
} else {
1059-
Ok(ASTNode::SQLCompoundIdentifier(idents))
1059+
Ok(idents)
10601060
}
10611061
}
10621062

10631063
/// Parse a possibly qualified, possibly quoted identifier, e.g.
10641064
/// `foo` or `myschema."table"`
10651065
pub fn parse_object_name(&mut self) -> Result<SQLObjectName, ParserError> {
1066-
let identifier = self.parse_compound_identifier(&Token::Period)?;
1067-
match identifier {
1068-
// TODO: should store the compound identifier itself
1069-
ASTNode::SQLCompoundIdentifier(idents) => Ok(SQLObjectName(idents)),
1070-
other => parser_err!(format!("Expecting compound identifier, found: {:?}", other)),
1071-
}
1066+
Ok(SQLObjectName(self.parse_list_of_ids(&Token::Period)?))
10721067
}
10731068

1069+
/// Parse a comma-separated list of unqualified, possibly quoted identifiers
10741070
pub fn parse_column_names(&mut self) -> Result<Vec<SQLIdent>, ParserError> {
1075-
let identifier = self.parse_compound_identifier(&Token::Comma)?;
1076-
match identifier {
1077-
ASTNode::SQLCompoundIdentifier(idents) => Ok(idents),
1078-
other => parser_err!(format!("Expecting compound identifier, found: {:?}", other)),
1079-
}
1071+
Ok(self.parse_list_of_ids(&Token::Comma)?)
10801072
}
10811073

10821074
pub fn parse_precision(&mut self) -> Result<usize, ParserError> {
@@ -1194,7 +1186,7 @@ impl Parser {
11941186
self.expect_token(&Token::RParen)?;
11951187
ASTNode::SQLSubquery(subquery)
11961188
} else {
1197-
self.parse_compound_identifier(&Token::Period)?
1189+
ASTNode::SQLCompoundIdentifier(self.parse_object_name()?.0)
11981190
};
11991191
let alias = self.parse_optional_alias(keywords::RESERVED_FOR_TABLE_ALIAS)?;
12001192
Ok(ASTNode::TableFactor {

0 commit comments

Comments
 (0)