From 8a0d0e3e201936a354c59897ff51e02f4cbb9cba Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 5 Aug 2020 10:00:20 +0800 Subject: [PATCH 1/3] Unbox error return for Engine::register_custom_syntax. --- RELEASES.md | 1 + src/syntax.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index 7e72c56b..23973fe7 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -36,6 +36,7 @@ Breaking changes * `PackagesCollection::get_fn`, `PackagesCollection::contains_fn`, `Module::get_fn` and `Module::contains_fn` now take an additional `public_only` parameter indicating whether only public functions are accepted. * The iterator returned by `Scope::iter` now contains a clone of the `Dynamic` value (unshared). * `Engine::load_package` takes any type that is `Into`. +* Error in `Engine::register_custom_syntax` is no longer `Box`-ed. Housekeeping ------------ diff --git a/src/syntax.rs b/src/syntax.rs index 9dfc255f..4cc937e6 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -100,7 +100,7 @@ impl Engine { ) -> Result> + SendSync + 'static, - ) -> Result<&mut Self, Box> { + ) -> Result<&mut Self, ParseError> { let mut segments: StaticVec<_> = Default::default(); for s in keywords { From 07af296ab0125383587abfff028d1c291795785e Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 5 Aug 2020 17:02:11 +0800 Subject: [PATCH 2/3] Fix custom syntax test. --- tests/syntax.rs | 71 ++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/tests/syntax.rs b/tests/syntax.rs index b5a8d7d9..a0cfa5b1 100644 --- a/tests/syntax.rs +++ b/tests/syntax.rs @@ -1,6 +1,4 @@ -use rhai::{ - Engine, EvalAltResult, EvalContext, Expression, ParseError, ParseErrorType, Scope, INT, -}; +use rhai::{Engine, EvalAltResult, EvalContext, Expression, ParseErrorType, Scope, INT}; #[test] fn test_custom_syntax() -> Result<(), Box> { @@ -19,43 +17,35 @@ fn test_custom_syntax() -> Result<(), Box> { ParseErrorType::Reserved(err) if err == "while" )); - engine - .register_custom_syntax( - &[ - "do", "|", "$ident$", "|", "->", "$block$", "while", "$expr$", - ], - 1, - |engine: &Engine, - context: &mut EvalContext, - scope: &mut Scope, - inputs: &[Expression]| { - let var_name = inputs[0].get_variable_name().unwrap().to_string(); - let stmt = inputs.get(1).unwrap(); - let expr = inputs.get(2).unwrap(); + engine.register_custom_syntax( + &[ + "do", "|", "$ident$", "|", "->", "$block$", "while", "$expr$", + ], + 1, + |engine: &Engine, context: &mut EvalContext, scope: &mut Scope, inputs: &[Expression]| { + let var_name = inputs[0].get_variable_name().unwrap().to_string(); + let stmt = inputs.get(1).unwrap(); + let expr = inputs.get(2).unwrap(); - scope.push(var_name, 0 as INT); + scope.push(var_name, 0 as INT); - loop { - engine.eval_expression_tree(context, scope, stmt)?; + loop { + engine.eval_expression_tree(context, scope, stmt)?; - if !engine - .eval_expression_tree(context, scope, expr)? - .as_bool() - .map_err(|_| { - EvalAltResult::ErrorBooleanArgMismatch( - "do-while".into(), - expr.position(), - ) - })? - { - break; - } + if !engine + .eval_expression_tree(context, scope, expr)? + .as_bool() + .map_err(|_| { + EvalAltResult::ErrorBooleanArgMismatch("do-while".into(), expr.position()) + })? + { + break; } + } - Ok(().into()) - }, - ) - .unwrap(); + Ok(().into()) + }, + )?; // 'while' is now a custom keyword so this it can no longer be a variable engine.consume("let while = 0").expect_err("should error"); @@ -71,10 +61,13 @@ fn test_custom_syntax() -> Result<(), Box> { ); // The first symbol must be an identifier - assert!(matches!( - *engine.register_custom_syntax(&["!"], 0, |_, _, _, _| Ok(().into())).expect_err("should error"), - ParseError(err, _) if *err == ParseErrorType::BadInput("Improper symbol for custom syntax: '!'".to_string()) - )); + assert_eq!( + *engine + .register_custom_syntax(&["!"], 0, |_, _, _, _| Ok(().into())) + .expect_err("should error") + .0, + ParseErrorType::BadInput("Improper symbol for custom syntax: '!'".to_string()) + ); Ok(()) } From f791c64f9631c63530c46ff98ea068564b14022f Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 5 Aug 2020 17:02:30 +0800 Subject: [PATCH 3/3] Remove plugins feature. --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 11216cc3..db8a63d9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,6 @@ jobs: flags: - "" - "--features serde" - - "--features plugins" - "--features unchecked" - "--features sync" - "--features no_optimize"