Merge pull request #209 from schungx/master

General fixups for version 0.18.0
This commit is contained in:
Stephen Chung 2020-08-05 17:49:31 +08:00 committed by GitHub
commit 75fd9f9f98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 41 deletions

View File

@ -19,7 +19,6 @@ jobs:
flags: flags:
- "" - ""
- "--features serde" - "--features serde"
- "--features plugins"
- "--features unchecked" - "--features unchecked"
- "--features sync" - "--features sync"
- "--features no_optimize" - "--features no_optimize"

View File

@ -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. * `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). * The iterator returned by `Scope::iter` now contains a clone of the `Dynamic` value (unshared).
* `Engine::load_package` takes any type that is `Into<PackageLibrary>`. * `Engine::load_package` takes any type that is `Into<PackageLibrary>`.
* Error in `Engine::register_custom_syntax` is no longer `Box`-ed.
Housekeeping Housekeeping
------------ ------------

View File

@ -100,7 +100,7 @@ impl Engine {
) -> Result<Dynamic, Box<EvalAltResult>> ) -> Result<Dynamic, Box<EvalAltResult>>
+ SendSync + SendSync
+ 'static, + 'static,
) -> Result<&mut Self, Box<ParseError>> { ) -> Result<&mut Self, ParseError> {
let mut segments: StaticVec<_> = Default::default(); let mut segments: StaticVec<_> = Default::default();
for s in keywords { for s in keywords {

View File

@ -1,6 +1,4 @@
use rhai::{ use rhai::{Engine, EvalAltResult, EvalContext, Expression, ParseErrorType, Scope, INT};
Engine, EvalAltResult, EvalContext, Expression, ParseError, ParseErrorType, Scope, INT,
};
#[test] #[test]
fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> { fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
@ -19,16 +17,12 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
ParseErrorType::Reserved(err) if err == "while" ParseErrorType::Reserved(err) if err == "while"
)); ));
engine engine.register_custom_syntax(
.register_custom_syntax(
&[ &[
"do", "|", "$ident$", "|", "->", "$block$", "while", "$expr$", "do", "|", "$ident$", "|", "->", "$block$", "while", "$expr$",
], ],
1, 1,
|engine: &Engine, |engine: &Engine, context: &mut EvalContext, scope: &mut Scope, inputs: &[Expression]| {
context: &mut EvalContext,
scope: &mut Scope,
inputs: &[Expression]| {
let var_name = inputs[0].get_variable_name().unwrap().to_string(); let var_name = inputs[0].get_variable_name().unwrap().to_string();
let stmt = inputs.get(1).unwrap(); let stmt = inputs.get(1).unwrap();
let expr = inputs.get(2).unwrap(); let expr = inputs.get(2).unwrap();
@ -42,10 +36,7 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
.eval_expression_tree(context, scope, expr)? .eval_expression_tree(context, scope, expr)?
.as_bool() .as_bool()
.map_err(|_| { .map_err(|_| {
EvalAltResult::ErrorBooleanArgMismatch( EvalAltResult::ErrorBooleanArgMismatch("do-while".into(), expr.position())
"do-while".into(),
expr.position(),
)
})? })?
{ {
break; break;
@ -54,8 +45,7 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
Ok(().into()) Ok(().into())
}, },
) )?;
.unwrap();
// 'while' is now a custom keyword so this it can no longer be a variable // 'while' is now a custom keyword so this it can no longer be a variable
engine.consume("let while = 0").expect_err("should error"); engine.consume("let while = 0").expect_err("should error");
@ -71,10 +61,13 @@ fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
); );
// The first symbol must be an identifier // The first symbol must be an identifier
assert!(matches!( assert_eq!(
*engine.register_custom_syntax(&["!"], 0, |_, _, _, _| Ok(().into())).expect_err("should error"), *engine
ParseError(err, _) if *err == ParseErrorType::BadInput("Improper symbol for custom syntax: '!'".to_string()) .register_custom_syntax(&["!"], 0, |_, _, _, _| Ok(().into()))
)); .expect_err("should error")
.0,
ParseErrorType::BadInput("Improper symbol for custom syntax: '!'".to_string())
);
Ok(()) Ok(())
} }