From c245fe88fdfba692fcb1c2e0ff48103776fae139 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 24 Jan 2021 21:21:15 +0800 Subject: [PATCH] Allow stacking ! operators. --- Cargo.toml | 3 ++- RELEASES.md | 1 + src/parser.rs | 2 +- tests/internal_fn.rs | 6 +++--- tests/not.rs | 3 +-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2b12fb19..4404a367 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,9 +17,10 @@ license = "MIT OR Apache-2.0" include = [ "**/*.rs", "scripts/*.rhai", + "**/*.md", "Cargo.toml" ] -keywords = [ "scripting" ] +keywords = [ "scripting", "scripting-engine", "scripting language", "embedded" ] categories = [ "no-std", "embedded", "wasm", "parser-implementations" ] [dependencies] diff --git a/RELEASES.md b/RELEASES.md index 904627bc..90876d33 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -19,6 +19,7 @@ Bug fixes * Parameters passed to plugin module functions were sometimes erroneously consumed. This is now fixed. * Fixes compilation errors in `metadata` feature build. +* Stacking `!` operators now work properly. New features ------------ diff --git a/src/parser.rs b/src/parser.rs index fbf17165..12eb9649 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1338,7 +1338,7 @@ fn parse_unary( Token::Bang => { let pos = eat_token(input, Token::Bang); let mut args = StaticVec::new(); - let expr = parse_primary(input, state, lib, settings.level_up())?; + let expr = parse_unary(input, state, lib, settings.level_up())?; args.push(expr); let op = "!"; diff --git a/tests/internal_fn.rs b/tests/internal_fn.rs index 80d904e7..70a94a7c 100644 --- a/tests/internal_fn.rs +++ b/tests/internal_fn.rs @@ -62,9 +62,9 @@ fn test_internal_fn_overloading() -> Result<(), Box> { *engine .compile( r" - fn abc(x) { x + 42 } - fn abc(x) { x - 42 } - " + fn abc(x) { x + 42 } + fn abc(x) { x - 42 } + " ) .expect_err("should error") .0, diff --git a/tests/not.rs b/tests/not.rs index ffc1d21d..41220389 100644 --- a/tests/not.rs +++ b/tests/not.rs @@ -12,8 +12,7 @@ fn test_not() -> Result<(), Box> { #[cfg(not(feature = "no_function"))] assert_eq!(engine.eval::("fn not(x) { !x } not(false)")?, true); - // TODO - do we allow stacking unary operators directly? e.g '!!!!!!!true' - assert_eq!(engine.eval::("!(!(!(!(true))))")?, true); + assert_eq!(engine.eval::("!!!!true")?, true); Ok(()) }