iffyio commented on code in PR #2095:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2095#discussion_r2527740658
##########
src/parser/mod.rs:
##########
@@ -10224,17 +10224,32 @@ impl<'a> Parser<'a> {
/// Parse the body of a `CREATE FUNCTION` specified as a string.
/// e.g. `CREATE FUNCTION ... AS $$ body $$`.
fn parse_create_function_body_string(&mut self) -> Result<Expr,
ParserError> {
- let peek_token = self.peek_token();
- let span = peek_token.span;
- match peek_token.token {
- Token::DollarQuotedString(s) if dialect_of!(self is
PostgreSqlDialect | GenericDialect) =>
- {
- self.next_token();
- Ok(Expr::Value(Value::DollarQuotedString(s).with_span(span)))
+ // Helper closure to parse a single string value (quoted or
dollar-quoted)
+ let parse_string_expr = |parser: &mut Parser| -> Result<Expr,
ParserError> {
+ let peek_token = parser.peek_token();
+ let span = peek_token.span;
+ match peek_token.token {
+ Token::DollarQuotedString(s) if dialect_of!(parser is
PostgreSqlDialect | GenericDialect) =>
+ {
+ parser.next_token();
+
Ok(Expr::Value(Value::DollarQuotedString(s).with_span(span)))
+ }
+ _ => Ok(Expr::Value(
+
Value::SingleQuotedString(parser.parse_literal_string()?).with_span(span),
+ )),
}
- _ => Ok(Expr::Value(
-
Value::SingleQuotedString(self.parse_literal_string()?).with_span(span),
- )),
+ };
+
+ let first_expr = parse_string_expr(self)?;
+
+ // Check if there's a comma, indicating multiple strings (e.g., AS
'obj_file', 'link_symbol')
+ // This is used for C language functions: AS 'MODULE_PATHNAME',
'link_symbol'
+ if self.consume_token(&Token::Comma) {
+ let mut exprs = vec![first_expr];
+ exprs.extend(self.parse_comma_separated(parse_string_expr)?);
+ Ok(Expr::Tuple(exprs))
Review Comment:
```suggestion
Ok(Expr::Tuple(vec![
first_expr,
self.parse_comma_separated(parse_string_expr)?
]))
```
looks like this can be simplified?
##########
src/parser/mod.rs:
##########
@@ -10224,17 +10224,32 @@ impl<'a> Parser<'a> {
/// Parse the body of a `CREATE FUNCTION` specified as a string.
/// e.g. `CREATE FUNCTION ... AS $$ body $$`.
fn parse_create_function_body_string(&mut self) -> Result<Expr,
ParserError> {
- let peek_token = self.peek_token();
- let span = peek_token.span;
- match peek_token.token {
- Token::DollarQuotedString(s) if dialect_of!(self is
PostgreSqlDialect | GenericDialect) =>
- {
- self.next_token();
- Ok(Expr::Value(Value::DollarQuotedString(s).with_span(span)))
+ // Helper closure to parse a single string value (quoted or
dollar-quoted)
+ let parse_string_expr = |parser: &mut Parser| -> Result<Expr,
ParserError> {
+ let peek_token = parser.peek_token();
+ let span = peek_token.span;
+ match peek_token.token {
+ Token::DollarQuotedString(s) if dialect_of!(parser is
PostgreSqlDialect | GenericDialect) =>
+ {
+ parser.next_token();
+
Ok(Expr::Value(Value::DollarQuotedString(s).with_span(span)))
+ }
+ _ => Ok(Expr::Value(
+
Value::SingleQuotedString(parser.parse_literal_string()?).with_span(span),
+ )),
}
- _ => Ok(Expr::Value(
-
Value::SingleQuotedString(self.parse_literal_string()?).with_span(span),
- )),
+ };
+
+ let first_expr = parse_string_expr(self)?;
+
+ // Check if there's a comma, indicating multiple strings (e.g., AS
'obj_file', 'link_symbol')
+ // This is used for C language functions: AS 'MODULE_PATHNAME',
'link_symbol'
+ if self.consume_token(&Token::Comma) {
+ let mut exprs = vec![first_expr];
+ exprs.extend(self.parse_comma_separated(parse_string_expr)?);
+ Ok(Expr::Tuple(exprs))
Review Comment:
oh, does wrapping this in a Tuple not include a parenthesis `(first_expr,
second_expr)` when displaying the AST? wondering if/how we worked around that
somehow in this case
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]