Skip to content

Commit

Permalink
added comparison operators < > <= >=
Browse files Browse the repository at this point in the history
  • Loading branch information
riederm committed Dec 15, 2019
1 parent 6ce38a4 commit 448037d
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target
**/*.rs.bk
**/*.rs.bk
**/*.un~
**/*.toml~
104 changes: 104 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ edition = "2018"

[dependencies]
logos = "0.9.7"

[dev-dependencies]
pretty_assertions = "0.6.1"
9 changes: 7 additions & 2 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ pub enum Operator {
Minus,
Multiplication,
Division,
OperatorEqual,
OperatorNotEqual,
Equal,
NotEqual,
Modulo,
Less,
Greater,
LessOrEqual,
GreaterOrEqual,

}
26 changes: 25 additions & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ pub enum Token {
#[token = "<>"]
OperatorNotEqual,

#[token = "<"]
OperatorLess,

#[token = ">"]
OperatorGreater,

#[token = "<="]
OperatorLessOrEqual,

#[token = ">="]
OperatorGreaterOrEqual,

#[token = "MOD"]
OperatorModulo,

Expand Down Expand Up @@ -133,7 +145,7 @@ mod tests {

#[test]
fn operator_test() {
let mut lexer = super::lex("+ - * / MOD");
let mut lexer = super::lex("+ - * / MOD = <> < > <= >=");
assert_eq!(lexer.token, super::Token::OperatorPlus);
lexer.advance();
assert_eq!(lexer.token, super::Token::OperatorMinus);
Expand All @@ -143,6 +155,18 @@ mod tests {
assert_eq!(lexer.token, super::Token::OperatorDivision);
lexer.advance();
assert_eq!(lexer.token, super::Token::OperatorModulo);
lexer.advance();
assert_eq!(lexer.token, super::Token::OperatorEqual);
lexer.advance();
assert_eq!(lexer.token, super::Token::OperatorNotEqual);
lexer.advance();
assert_eq!(lexer.token, super::Token::OperatorLess);
lexer.advance();
assert_eq!(lexer.token, super::Token::OperatorGreater);
lexer.advance();
assert_eq!(lexer.token, super::Token::OperatorLessOrEqual);
lexer.advance();
assert_eq!(lexer.token, super::Token::OperatorGreaterOrEqual);
}

#[test]
Expand Down
Loading

0 comments on commit 448037d

Please sign in to comment.