Skip to content

Commit

Permalink
Add: !, != and !~ operations into nasl-syntax-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtsfrei committed Nov 11, 2022
1 parent 4ba4717 commit 4e4d61d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions rust/nasl-syntax/src/infix_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ mod test {
assert_eq!(result("a >>= 1"), expected(GreaterGreaterEqual, 1));
assert_eq!(result("a <<= 1"), expected(LessLessEqual, 1));
assert_eq!(result("a >>>= 1"), expected(GreaterGreaterGreaterEqual, 2));
assert_eq!(result("a != 1"), expected(BangEqual, 0));
assert_eq!(result("a !~ 1"), expected(BangTilde, 0));
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions rust/nasl-syntax/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ impl Operation {
| Category::Ampersand
| Category::Pipe
| Category::Caret
| Category::Bang
| Category::StarStar => Some(Operation::Operator(token.category())),
Category::Equal
| Category::MinusEqual
| Category::BangEqual
| Category::BangTilde
| Category::PlusEqual
| Category::SlashEqual
| Category::StarEqual
Expand Down
3 changes: 2 additions & 1 deletion rust/nasl-syntax/src/prefix_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) trait Prefix {
/// Is used to verify operations.
fn prefix_binding_power(token: Token) -> Result<u8, TokenError> {
match token.category() {
Category::Plus | Category::Minus | Category::Tilde => Ok(9),
Category::Plus | Category::Minus | Category::Tilde | Category::Bang => Ok(9),
_ => Err(unexpected_token!(token)),
}
}
Expand Down Expand Up @@ -133,6 +133,7 @@ mod test {
assert_eq!(result("-1"), expected(Category::Minus));
assert_eq!(result("+1"), expected(Category::Plus));
assert_eq!(result("~1"), expected(Category::Tilde));
assert_eq!(result("!1"), expected(Category::Bang));
}

#[test]
Expand Down

0 comments on commit 4e4d61d

Please sign in to comment.