Added support for the mod operator

This commit is contained in:
2025-11-24 22:53:00 -07:00
parent 56f0e292b7
commit 37d5643615
7 changed files with 161 additions and 140 deletions

View File

@@ -221,6 +221,7 @@ impl Tokenizer {
'.' => symbol!(Dot),
'^' => symbol!(Caret),
'%' => symbol!(Percent),
// multi-character symbols
'<' if self.peek_next_char()? == Some('=') => {
@@ -736,7 +737,7 @@ mod tests {
#[test]
fn test_symbol_parse() -> Result<()> {
let mut tokenizer = Tokenizer::from(String::from(
"^ ! () [] {} , . ; : + - * / < > = != && || >= <=**",
"^ ! () [] {} , . ; : + - * / < > = != && || >= <=**%",
));
let expected_tokens = vec![
@@ -765,6 +766,7 @@ mod tests {
TokenType::Symbol(Symbol::GreaterThanOrEqual),
TokenType::Symbol(Symbol::LessThanOrEqual),
TokenType::Symbol(Symbol::Exp),
TokenType::Symbol(Symbol::Percent),
];
for expected_token in expected_tokens {

View File

@@ -158,6 +158,8 @@ pub enum Symbol {
Dot,
/// Represents the `^` symbol
Caret,
/// Represents the `%` symbol
Percent,
// Double Character Symbols
/// Represents the `==` symbol
@@ -180,7 +182,12 @@ impl Symbol {
pub fn is_operator(&self) -> bool {
matches!(
self,
Symbol::Plus | Symbol::Minus | Symbol::Asterisk | Symbol::Slash | Symbol::Exp
Symbol::Plus
| Symbol::Minus
| Symbol::Asterisk
| Symbol::Slash
| Symbol::Exp
| Symbol::Percent
)
}