1
0
mirror of https://github.com/fluencelabs/llamadb synced 2025-03-16 03:00:50 +00:00

Add divide operator to parser

This commit is contained in:
Dan Spencer 2015-04-13 06:18:47 -06:00
parent 54e957ad24
commit 4b85ff0323
5 changed files with 7 additions and 1 deletions
src

@ -658,6 +658,7 @@ fn ast_binaryop_to_sexpression_binaryop(ast: ast::BinaryOp) -> BinaryOp {
ast::BinaryOp::Add => BinaryOp::Add,
ast::BinaryOp::Subtract => BinaryOp::Subtract,
ast::BinaryOp::Multiply => BinaryOp::Multiply,
ast::BinaryOp::Divide => BinaryOp::Divide,
ast::BinaryOp::BitAnd => BinaryOp::BitAnd,
ast::BinaryOp::BitOr => BinaryOp::BitOr,
ast::BinaryOp::Concatenate => BinaryOp::Concatenate,

@ -148,6 +148,7 @@ pub enum BinaryOp {
Add,
Subtract,
Multiply,
Divide,
BitAnd,
BitOr,
Concatenate,
@ -169,6 +170,7 @@ impl BinaryOp {
&Add => "+",
&Subtract => "-",
&Multiply => "*",
&Divide => "/",
&BitAnd => "&",
&BitOr => "|",
&Concatenate => "concat"

@ -16,6 +16,7 @@ pub enum BinaryOp {
Add,
Subtract,
Multiply,
Divide,
BitAnd,
BitOr,
Concatenate,

@ -23,6 +23,7 @@ mod test {
fn test_sql_parser() {
parse("SELECT *, (name + 4), count(*) AS amount FROM (SELECT * FROM foo) subq, table1 GROUP BY name HAVING count(*) > 5;");
parse("SELECT * FROM foo INNER JOIN bar ON foo.id = bar.fooId ORDER BY a DESC, b;");
parse("SELECT avg(milliseconds) / 1000 seconds FROM track;");
parse("INSERT INTO table1 VALUES (1, 2), (3, 4), (5, 6);");
parse("INSERT INTO table1 (a, b) VALUES ('foo' || 'bar', 2);");

@ -163,6 +163,7 @@ impl Rule for BinaryOp {
&Token::Plus => Ok(BinaryOp::Add),
&Token::Minus => Ok(BinaryOp::Subtract),
&Token::Asterisk => Ok(BinaryOp::Multiply),
&Token::ForwardSlash => Ok(BinaryOp::Divide),
&Token::Ampersand => Ok(BinaryOp::BitAnd),
&Token::Pipe => Ok(BinaryOp::BitOr),
&Token::DoublePipe => Ok(BinaryOp::Concatenate),
@ -187,7 +188,7 @@ impl BinaryOp {
use super::ast::BinaryOp::*;
match self {
&Multiply => 5,
&Multiply | &Divide => 5,
&Add | &Subtract | &BitAnd | &BitOr | &Concatenate => 4,
// comparison
&Equal | &NotEqual | &LessThan | &LessThanOrEqual | &GreaterThan | &GreaterThanOrEqual => 3,