Skip to content

Commit a9223e7

Browse files
committed
feat: added modulo operator
1 parent 4cf4391 commit a9223e7

4 files changed

Lines changed: 7 additions & 2 deletions

File tree

compiler/ast/src/operators.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use lexer::token::{LexerToken, LexerTokenType};
77
pub fn parse_math_operator(tokens: &Vec<LexerToken>, ind: &mut usize) -> DiagnosticResult<MathOperator> {
88
let op = match tokens[*ind].tok_type {
99
LexerTokenType::Plus => MathOperatorType::Add,
10+
LexerTokenType::PercentSign => MathOperatorType::Modulo,
1011
LexerTokenType::Minus => MathOperatorType::Subtract,
1112
LexerTokenType::Asterisk => {
1213
if tokens[*ind + 1].tok_type == LexerTokenType::Asterisk {

compiler/compiler_utils/src/operators.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ pub enum MathOperatorType {
88
Multiply,
99
Divide,
1010
ShiftLeft,
11-
ShiftRight
11+
ShiftRight,
12+
Modulo
1213
}
1314

1415
/// Represents an actual math operator

compiler/lexer/src/lexer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ pub fn lexer_parse_file(file_path: &String) -> DiagnosticResult<Vec<LexerToken>>
123123
'-' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::Minus)),
124124
'/' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::Divide)),
125125
'~' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::Tidle)),
126+
'%' => tokens.push(LexerToken::make_single_sized(pos, LexerTokenType::PercentSign)),
126127
_ => continue
127128
}
128129

compiler/lexer/src/token.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub enum LexerTokenType {
6060
Minus,
6161
Divide,
6262
Tidle,
63+
PercentSign,
6364

6465
BracketOpen,
6566
BracketClose,
@@ -198,7 +199,8 @@ impl Display for LexerTokenType {
198199
Self::Plus => "+",
199200
Self::Minus => "-",
200201
Self::Divide => "/",
201-
Self::Tidle => "~"
202+
Self::Tidle => "~",
203+
Self::PercentSign => "%"
202204
};
203205

204206
write!(f, "{}", s)?;

0 commit comments

Comments
 (0)