iffyio commented on code in PR #1655:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1655#discussion_r1918787980


##########
src/parser/mod.rs:
##########
@@ -8452,6 +8458,42 @@ impl<'a> Parser<'a> {
         }
     }
 
+    /// Parse a literal unicode normalization clause
+    pub fn parse_unicode_is_normalized(
+        &mut self,
+    ) -> Result<(Option<NormalizationForm>, bool), ParserError> {
+        let neg = self.parse_keyword(Keyword::NOT);
+        if self.parse_keyword(Keyword::NORMALIZED) {
+            return Ok((None, neg));
+        }
+        let index = self.index;
+        let next_token = self.next_token();
+        let normalized_form = if let Token::Word(Word {
+            value: ref s,
+            quote_style: None,
+            keyword: Keyword::NoKeyword,
+        }) = next_token.token
+        {
+            match s.to_uppercase().as_str() {
+                "NFC" => Some(NormalizationForm::NFC),
+                "NFD" => Some(NormalizationForm::NFD),
+                "NFKC" => Some(NormalizationForm::NFKC),
+                "NFKD" => Some(NormalizationForm::NFKD),
+                _ => {
+                    self.index = index;
+                    return self.expected("unicode normalization", next_token);
+                }
+            }
+        } else {
+            None
+        };
+        if self.parse_keyword(Keyword::NORMALIZED) {
+            return Ok((normalized_form, neg));
+        }
+        self.index = index;

Review Comment:
   Thinking it might be simpler to declare the strings as keywords, also 
instead of manually tracking the index in the function would it be possible to 
use `maybe_parse`? roughly thinking something like:
   ```rust
   let normalized_form = self.maybe_parse(|parser| {
        match parser.parse_one_of_keywords(&[
                Keyword::NFC, ...
        ]) {
                Some(Keyword::NFC) = Some(NormalizationForm::NFC)
                ...
        }
   })?;
   if self.parse_keyword(Keyword::NORMALIZED) {
        return Ok((normalized_form, neg));
   }
   ```
   



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to