@@ -3940,7 +3940,11 @@ impl<'a> Parser<'a> {
39403940 let trailing_commas =
39413941 self.options.trailing_commas | self.dialect.supports_projection_trailing_commas();
39423942
3943- self.parse_comma_separated_with_trailing_commas(|p| p.parse_select_item(), trailing_commas)
3943+ self.parse_comma_separated_with_trailing_commas(
3944+ |p| p.parse_select_item(),
3945+ trailing_commas,
3946+ None,
3947+ )
39443948 }
39453949
39463950 pub fn parse_actions_list(&mut self) -> Result<Vec<ParsedAction>, ParserError> {
@@ -3966,20 +3970,32 @@ impl<'a> Parser<'a> {
39663970 Ok(values)
39673971 }
39683972
3973+ /// Parse a list of [TableWithJoins]
3974+ fn parse_table_with_joins(&mut self) -> Result<Vec<TableWithJoins>, ParserError> {
3975+ let trailing_commas = self.dialect.supports_from_trailing_commas();
3976+
3977+ self.parse_comma_separated_with_trailing_commas(
3978+ Parser::parse_table_and_joins,
3979+ trailing_commas,
3980+ Some(self.dialect.get_reserved_keywords_for_table_factor()),
3981+ )
3982+ }
3983+
39693984 /// Parse the comma of a comma-separated syntax element.
39703985 /// Allows for control over trailing commas
39713986 /// Returns true if there is a next element
3972- fn is_parse_comma_separated_end_with_trailing_commas(&mut self, trailing_commas: bool) -> bool {
3987+ fn is_parse_comma_separated_end_with_trailing_commas(
3988+ &mut self,
3989+ trailing_commas: bool,
3990+ reserved_keywords: Option<&[Keyword]>,
3991+ ) -> bool {
3992+ let reserved_keywords = reserved_keywords.unwrap_or(keywords::RESERVED_FOR_COLUMN_ALIAS);
39733993 if !self.consume_token(&Token::Comma) {
39743994 true
39753995 } else if trailing_commas {
39763996 let token = self.peek_token().token;
39773997 match token {
3978- Token::Word(ref kw)
3979- if keywords::RESERVED_FOR_COLUMN_ALIAS.contains(&kw.keyword) =>
3980- {
3981- true
3982- }
3998+ Token::Word(ref kw) if reserved_keywords.contains(&kw.keyword) => true,
39833999 Token::RParen | Token::SemiColon | Token::EOF | Token::RBracket | Token::RBrace => {
39844000 true
39854001 }
@@ -3993,15 +4009,15 @@ impl<'a> Parser<'a> {
39934009 /// Parse the comma of a comma-separated syntax element.
39944010 /// Returns true if there is a next element
39954011 fn is_parse_comma_separated_end(&mut self) -> bool {
3996- self.is_parse_comma_separated_end_with_trailing_commas(self.options.trailing_commas)
4012+ self.is_parse_comma_separated_end_with_trailing_commas(self.options.trailing_commas, None )
39974013 }
39984014
39994015 /// Parse a comma-separated list of 1+ items accepted by `F`
40004016 pub fn parse_comma_separated<T, F>(&mut self, f: F) -> Result<Vec<T>, ParserError>
40014017 where
40024018 F: FnMut(&mut Parser<'a>) -> Result<T, ParserError>,
40034019 {
4004- self.parse_comma_separated_with_trailing_commas(f, self.options.trailing_commas)
4020+ self.parse_comma_separated_with_trailing_commas(f, self.options.trailing_commas, None )
40054021 }
40064022
40074023 /// Parse a comma-separated list of 1+ items accepted by `F`
@@ -4010,14 +4026,18 @@ impl<'a> Parser<'a> {
40104026 &mut self,
40114027 mut f: F,
40124028 trailing_commas: bool,
4029+ reserved_keywords: Option<&[Keyword]>,
40134030 ) -> Result<Vec<T>, ParserError>
40144031 where
40154032 F: FnMut(&mut Parser<'a>) -> Result<T, ParserError>,
40164033 {
40174034 let mut values = vec![];
40184035 loop {
40194036 values.push(f(self)?);
4020- if self.is_parse_comma_separated_end_with_trailing_commas(trailing_commas) {
4037+ if self.is_parse_comma_separated_end_with_trailing_commas(
4038+ trailing_commas,
4039+ reserved_keywords,
4040+ ) {
40214041 break;
40224042 }
40234043 }
@@ -10073,7 +10093,7 @@ impl<'a> Parser<'a> {
1007310093 // or `from`.
1007410094
1007510095 let from = if self.parse_keyword(Keyword::FROM) {
10076- self.parse_comma_separated(Parser::parse_table_and_joins )?
10096+ self.parse_table_with_joins( )?
1007710097 } else {
1007810098 vec![]
1007910099 };
0 commit comments