diff --git a/src/parser/mod.rs b/src/parser/mod.rs index f2bf76f..7567bef 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1365,7 +1365,7 @@ impl Parser { fn parse_infix_expr(&mut self, exp: Expression) -> Result { 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), @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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), @@ -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), @@ -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), @@ -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 => { @@ -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) } } diff --git a/src/parser/operator.rs b/src/parser/operator.rs index 87cf712..0979070 100644 --- a/src/parser/operator.rs +++ b/src/parser/operator.rs @@ -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