From 4ef82025ccb6a9d5db8b7b3aa7106f9e5131ae3d Mon Sep 17 00:00:00 2001
From: wupeng <1399094187@qq.com>
Date: Tue, 17 Oct 2023 10:38:00 +0800
Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf(parser):?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
remove the return value option
---
src/parser/mod.rs | 249 ++++++++--------------------------------------
1 file changed, 44 insertions(+), 205 deletions(-)
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 3479786..2cbf2a7 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -460,7 +460,7 @@ impl Parser {
loop {
self.next_token();
- exprs.push(self.parse_expression(Precedence::Lowest)?);
+ exprs.push(Some(self.parse_expression(Precedence::Lowest)?));
match self.next_token() {
Token::RightParen => break,
Token::Comma => {}
@@ -683,7 +683,7 @@ impl Parser {
Keyword::Default => {
self.next_token();
self.next_token();
- column.default = self.parse_expression(Precedence::Lowest)?
+ column.default = Some(self.parse_expression(Precedence::Lowest)?);
}
Keyword::Unique => {
self.next_token();
@@ -752,14 +752,7 @@ impl Parser {
match &self.pre_token {
Token::KeyWord(Keyword::Offset) => {
self.next_token();
- Some(match self.parse_expression(Precedence::Lowest)? {
- Some(exp) => exp,
- None => {
- return Err(Error::ParseErr(fmt_err!(
- "OFFSET exp should't be none"
- )));
- }
- })
+ Some(self.parse_expression(Precedence::Lowest)?)
}
_ => None,
}
@@ -769,14 +762,7 @@ impl Parser {
Token::KeyWord(Keyword::Limit) => {
self.next_token();
self.next_token();
- Some(match self.parse_expression(Precedence::Lowest)? {
- Some(exp) => exp,
- None => {
- return Err(Error::ParseErr(fmt_err!(
- "LIMIT exp should't be none"
- )));
- }
- })
+ Some(self.parse_expression(Precedence::Lowest)?)
}
_ => None,
}
@@ -793,11 +779,7 @@ impl Parser {
self.next_token();
break;
}
-
- let expr = match self.parse_expression(Precedence::Lowest)? {
- Some(e) => e,
- None => return Err(Error::ParseErr(fmt_err!("SELECT expression is not valid!"))),
- };
+ let expr = self.parse_expression(Precedence::Lowest)?;
// SELECT 1 + 2 AS c1; 1 + 2 是一个表达式, c1 是 alias 的一个名字
// Keyword::As 是一个可选项
@@ -864,14 +846,7 @@ impl Parser {
self.next_expected_keyword(Keyword::On)?;
self.next_token();
- Some(match self.parse_expression(Precedence::Lowest)? {
- Some(expr) => expr,
- None => {
- return Err(Error::ParseErr(fmt_err!(
- "ON Predicate expression is not valid!"
- )));
- }
- })
+ Some(self.parse_expression(Precedence::Lowest)?)
}
};
@@ -1025,12 +1000,7 @@ impl Parser {
self.next_token();
loop {
- exprs.push(match self.parse_expression(Precedence::Lowest)? {
- Some(e) => e,
- None => {
- return Err(Error::ParseErr("GROUP BY exp should't be none".to_owned()));
- }
- });
+ exprs.push(self.parse_expression(Precedence::Lowest)?);
self.next_token();
match self.peek_token {
@@ -1051,29 +1021,18 @@ impl Parser {
}
self.next_token();
- return Ok(Some(match self.parse_expression(Precedence::Lowest)? {
- Some(exp) => {
- self.next_token();
- exp
- }
- None => {
- return Err(Error::ParseErr(fmt_err!("WHERE exp should't be none")));
- }
- }));
+ return Ok(Some(self.parse_expression(Precedence::Lowest)?));
}
fn parse_clause_having(&mut self) -> Result