Implement missing modulo operator in new parser (#4182)
This commit is contained in:
parent
1530f9107e
commit
17ea0d881e
5 changed files with 18 additions and 1 deletions
|
@ -281,6 +281,7 @@ impl<'a> Lexer<'a> {
|
|||
}
|
||||
_ => t!("/"),
|
||||
},
|
||||
b'%' => t!("%"),
|
||||
b'*' => match self.reader.peek() {
|
||||
Some(b'*') => {
|
||||
self.reader.next();
|
||||
|
|
|
@ -113,7 +113,7 @@ impl Parser<'_> {
|
|||
| t!("<|") => Some((9, 10)),
|
||||
|
||||
t!("+") | t!("-") => Some((11, 12)),
|
||||
t!("*") | t!("×") | t!("/") | t!("÷") => Some((13, 14)),
|
||||
t!("*") | t!("×") | t!("/") | t!("÷") | t!("%") => Some((13, 14)),
|
||||
t!("**") => Some((15, 16)),
|
||||
t!("?:") | t!("??") => Some((17, 18)),
|
||||
_ => None,
|
||||
|
@ -271,6 +271,7 @@ impl Parser<'_> {
|
|||
t!("-") => Operator::Sub,
|
||||
t!("*") | t!("×") => Operator::Mul,
|
||||
t!("/") | t!("÷") => Operator::Div,
|
||||
t!("%") => Operator::Rem,
|
||||
t!("∋") | t!("CONTAINS") => Operator::Contain,
|
||||
t!("∌") | t!("CONTAINSNOT") => Operator::NotContain,
|
||||
t!("∈") | t!("INSIDE") => Operator::Inside,
|
||||
|
|
|
@ -160,6 +160,9 @@ macro_rules! t {
|
|||
("+") => {
|
||||
$crate::syn::token::TokenKind::Operator($crate::syn::token::Operator::Add)
|
||||
};
|
||||
("%") => {
|
||||
$crate::syn::token::TokenKind::Operator($crate::syn::token::Operator::Modulo)
|
||||
};
|
||||
("-") => {
|
||||
$crate::syn::token::TokenKind::Operator($crate::syn::token::Operator::Subtract)
|
||||
};
|
||||
|
|
|
@ -78,6 +78,8 @@ pub enum Operator {
|
|||
Divide,
|
||||
/// `×` or `∙`
|
||||
Mult,
|
||||
/// `%`
|
||||
Modulo,
|
||||
/// `||`
|
||||
Or,
|
||||
/// `&&`
|
||||
|
@ -156,6 +158,7 @@ impl Operator {
|
|||
Operator::Or => "||",
|
||||
Operator::And => "&&",
|
||||
Operator::Mult => "×",
|
||||
Operator::Modulo => "%",
|
||||
Operator::LessEqual => "<=",
|
||||
Operator::GreaterEqual => ">=",
|
||||
Operator::Star => "*",
|
||||
|
|
9
lib/tests/expression.rs
Normal file
9
lib/tests/expression.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
mod helpers;
|
||||
use helpers::Test;
|
||||
use surrealdb::err::Error;
|
||||
|
||||
#[tokio::test]
|
||||
async fn modulo() -> Result<(), Error> {
|
||||
Test::new("8 % 3").await?.expect_val("2")?;
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in a new issue