Skip to content

Commit

Permalink
feat: modulo
Browse files Browse the repository at this point in the history
Banyc committed Dec 13, 2023
1 parent 70e97af commit a181837
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/df.rs
Original file line number Diff line number Diff line change
@@ -108,6 +108,7 @@ fn convert_expr(expr: &sql::expr::Expr) -> polars::lazy::dsl::Expr {
sql::expr::BinaryOperator::Sub => left - right,
sql::expr::BinaryOperator::Mul => left * right,
sql::expr::BinaryOperator::Div => left / right,
sql::expr::BinaryOperator::Modulo => left % right,
sql::expr::BinaryOperator::Eq => left.eq(right),
sql::expr::BinaryOperator::NotEq => left.neq(right),
sql::expr::BinaryOperator::LtEq => left.lt_eq(right),
4 changes: 3 additions & 1 deletion src/sql/expr.rs
Original file line number Diff line number Diff line change
@@ -102,6 +102,7 @@ pub enum BinaryOperator {
Sub,
Mul,
Div,
Modulo,
Eq,
NotEq,
LtEq,
@@ -126,7 +127,8 @@ fn term_expr<'a>(
) -> impl Parser<'a, &'a [Token], Expr, extra::Err<Rich<'a, Token>>> + Clone {
let mul = just(Token::Symbol(Symbol::Mul)).to(BinaryOperator::Mul);
let div = just(Token::Symbol(Symbol::Div)).to(BinaryOperator::Div);
let operator = choice((mul, div));
let modulo = just(Token::Symbol(Symbol::Percent)).to(BinaryOperator::Modulo);
let operator = choice((mul, div, modulo));
binary_expr(operator, expr)
}

3 changes: 3 additions & 0 deletions src/sql/lexer.rs
Original file line number Diff line number Diff line change
@@ -97,6 +97,7 @@ pub enum Symbol {
Ampersand,
Pipe,
Comma,
Percent,
}

fn symbol<'a>() -> impl Parser<'a, &'a str, Symbol, extra::Err<Rich<'a, char>>> + Clone {
@@ -111,6 +112,7 @@ fn symbol<'a>() -> impl Parser<'a, &'a str, Symbol, extra::Err<Rich<'a, char>>>
let pipe = just('|').to(Symbol::Pipe);
let comma = just(',').to(Symbol::Comma);
let bang = just('!').to(Symbol::Bang);
let percent = just('%').to(Symbol::Percent);
choice((
left_angle,
right_angle,
@@ -123,6 +125,7 @@ fn symbol<'a>() -> impl Parser<'a, &'a str, Symbol, extra::Err<Rich<'a, char>>>
pipe,
comma,
bang,
percent,
))
}

0 comments on commit a181837

Please sign in to comment.