LucaCappelletti94 commented on code in PR #2618:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2618#discussion_r4442838871


##########
src/parser/mod.rs:
##########
@@ -1521,6 +1522,46 @@ impl<'a> Parser<'a> {
         Ok(Statement::UNLISTEN { channel })
     }
 
+    /// Parse `DO` statement.
+    pub fn parse_do(&mut self) -> Result<Statement, ParserError> {
+        let mut options = Vec::new();
+        loop {
+            let language = self.parse_keyword(Keyword::LANGUAGE);
+            let string_literal = matches!(
+                self.peek_token_ref().token,
+                Token::SingleQuotedString(_)
+                    | Token::DollarQuotedString(_)
+                    | Token::EscapedStringLiteral(_)
+                    | Token::UnicodeStringLiteral(_)
+            );
+            let option = match (language, string_literal) {
+                (true, true) => DoOption::LanguageLiteral(self.parse_value()?),
+                (true, false)
+                    if matches!(self.peek_token_ref().token, 
Token::NationalStringLiteral(_)) =>
+                {
+                    // PostgreSQL lexes `N'...'` as the `NCHAR` keyword 
followed
+                    // by a string literal, so `LANGUAGE N'...'` is the 
language
+                    // name `nchar` followed by the code block.
+                    let next_token = self.next_token();
+                    let span = next_token.span;
+                    let Token::NationalStringLiteral(code) = next_token.token 
else {
+                        return self.expected("national string literal", 
next_token);
+                    };
+                    options.push(DoOption::Language(Ident::with_span(span, 
"nchar")));
+                    
DoOption::Code(Value::SingleQuotedString(code).with_span(span))
+                }
+                (true, false) => DoOption::Language(self.parse_identifier()?),

Review Comment:
   You could take the token once and step back when it is not `N'...'`. The 
guard already proved the token is a `NationalStringLiteral`, so the `else` arm 
returning `expected("national string literal", ...)` can never run.
   
   ```suggestion
                   (true, false) => match self.next_token() {
                       // PostgreSQL lexes `N'...'` as the `NCHAR` keyword 
followed
                       // by a string literal, so `LANGUAGE N'...'` is the 
language
                       // name `nchar` followed by the code block.
                       TokenWithSpan {
                           token: Token::NationalStringLiteral(code),
                           span,
                       } => {
                           
options.push(DoOption::Language(Ident::with_span(span, "nchar")));
                           
DoOption::Code(Value::SingleQuotedString(code).with_span(span))
                       }
                       _ => {
                           self.prev_token();
                           DoOption::Language(self.parse_identifier()?)
                       }
                   },
   ```



##########
src/ast/spans.rs:
##########
@@ -1149,9 +1150,7 @@ impl Spanned for CreateTableOptions {
         match self {
             CreateTableOptions::None => Span::empty(),
             CreateTableOptions::With(vec) => union_spans(vec.iter().map(|i| 
i.span())),
-            CreateTableOptions::Options(vec) => {

Review Comment:
   Is this a clippy code smell or what is its reason?



##########
tests/sqlparser_common.rs:
##########
@@ -6517,9 +6517,9 @@ fn parse_window_functions() {
         expr_from_projection(&select.projection[0])
     );
 
-    for i in 0..EXPECTED_PROJ_QTY {
+    for proj in select.projection.iter().take(EXPECTED_PROJ_QTY) {

Review Comment:
   Is this another clippy code smell?



-- 
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]

Reply via email to