From 02861953e65008147215139f1da08b2af7d235fc Mon Sep 17 00:00:00 2001 From: yukunpeng Date: Fri, 8 Sep 2023 12:50:58 +0800 Subject: [PATCH] optimize code logic --- src/parser/mod.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 1428325eb..13fca65c0 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -3894,14 +3894,17 @@ impl<'a> Parser<'a> { match next_token.token { Token::Word(w) if w.keyword == Keyword::PRIMARY || w.keyword == Keyword::UNIQUE => { let is_primary = w.keyword == Keyword::PRIMARY; - let name = if is_primary { + if is_primary { self.expect_keyword(Keyword::KEY)?; - name - } else if self.parse_keyword(Keyword::KEY) { - self.maybe_parse(|parser| parser.parse_identifier()) - } else { - name - }; + } + + let name = self + .maybe_parse(|parser| { + let _ = parser.parse_keyword(Keyword::KEY); + + parser.parse_identifier() + }) + .or(name); let columns = self.parse_parenthesized_column_list(Mandatory, false)?; Ok(Some(TableConstraint::Unique {