Skip to content

Commit

Permalink
[fix]: fix parse empty args function
Browse files Browse the repository at this point in the history
Signed-off-by: fan <yfan3763@gmail.com>
  • Loading branch information
fansehep committed Oct 7, 2023
1 parent dca463f commit abf1b17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
37 changes: 21 additions & 16 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ impl Parser {
fn parse_infix_expr(&mut self, exp: Expression) -> Result<Expression> {
match self.pre_token {
Token::Add => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();
Ok(Expression::Operation(Operation::Add(
Box::new(exp),
Expand All @@ -1378,7 +1378,7 @@ impl Parser {
)))
}
Token::Equal => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();

Ok(Expression::Operation(Operation::Equal(
Expand All @@ -1392,7 +1392,7 @@ impl Parser {
)))
}
Token::GreaterThan => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();

Ok(Expression::Operation(Operation::GreaterThan(
Expand All @@ -1408,7 +1408,7 @@ impl Parser {
)))
}
Token::GreaterThanOrEqual => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();

Ok(Expression::Operation(Operation::GreaterThanOrEqual(
Expand All @@ -1424,7 +1424,7 @@ impl Parser {
)))
}
Token::LessThan => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();

Ok(Expression::Operation(Operation::LessThan(
Expand All @@ -1440,7 +1440,7 @@ impl Parser {
)))
}
Token::LessThanOrEqual => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();

Ok(Expression::Operation(Operation::LessThanOrEqual(
Expand All @@ -1456,7 +1456,7 @@ impl Parser {
)))
}
Token::Minus => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();

Ok(Expression::Operation(Operation::Subtract(
Expand All @@ -1470,7 +1470,7 @@ impl Parser {
)))
}
Token::NotEqual => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();

Ok(Expression::Operation(Operation::NotEqual(
Expand All @@ -1486,7 +1486,7 @@ impl Parser {
)))
}
Token::KeyWord(Keyword::And) => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();

Ok(Expression::Operation(Operation::And(
Expand All @@ -1500,7 +1500,7 @@ impl Parser {
)))
}
Token::KeyWord(Keyword::Or) => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();

Ok(Expression::Operation(Operation::Or(
Expand All @@ -1514,7 +1514,7 @@ impl Parser {
)))
}
Token::KeyWord(Keyword::Like) => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();

Ok(Expression::Operation(Operation::Like(
Expand All @@ -1528,7 +1528,7 @@ impl Parser {
)))
}
Token::Percent => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();
Ok(Expression::Operation(Operation::Modulo(
Box::new(exp),
Expand All @@ -1543,7 +1543,7 @@ impl Parser {
)))
}
Token::Asterisk => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();
Ok(Expression::Operation(Operation::Multiply(
Box::new(exp),
Expand All @@ -1558,7 +1558,7 @@ impl Parser {
)))
}
Token::Slash => {
let precedence = match_precedence(self.pre_token.clone());
let precedence = match_precedence(&self.pre_token);
self.next_token();
Ok(Expression::Operation(Operation::Divide(
Box::new(exp),
Expand Down Expand Up @@ -1596,6 +1596,11 @@ impl Parser {
}
}
}
Token::RightParen => {
// empty function args, like SUM(), NOW()
self.next_token();
vec![]
}
_ => match self.parse_expression_list()? {
Some(exprs) => exprs,
None => {
Expand Down Expand Up @@ -1652,8 +1657,8 @@ impl Parser {
Ok(Some(exprs))
}

fn peek_token_predence(&mut self) -> Precedence {
operator::match_precedence(self.peek_token.clone())
fn peek_token_predence(&self) -> Precedence {
operator::match_precedence(&self.peek_token)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn is_infix_oper(t: &token::Token) -> bool {
}
}

pub fn match_precedence(t: Token) -> Precedence {
pub fn match_precedence(t: &Token) -> Precedence {
match t {
Token::Equal | Token::NotEqual => Precedence::Equals,
Token::LessThan
Expand Down

0 comments on commit abf1b17

Please sign in to comment.