diff --git a/src/ast.rs b/src/ast.rs index 87af9821..66a29558 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1394,7 +1394,7 @@ pub struct CustomExpr { /// List of keywords. pub keywords: StaticVec, /// Is the current [`Scope`][crate::Scope] modified? - pub scope_changed: bool, + pub scope_may_be_changed: bool, /// List of tokens actually parsed. pub tokens: StaticVec, } diff --git a/src/custom_syntax.rs b/src/custom_syntax.rs index 36c97003..3df71978 100644 --- a/src/custom_syntax.rs +++ b/src/custom_syntax.rs @@ -156,19 +156,19 @@ pub struct CustomSyntax { /// Custom syntax implementation function. pub func: Shared, /// Any variables added/removed in the scope? - pub scope_changed: bool, + pub scope_may_be_changed: bool, } impl Engine { /// Register a custom syntax with the [`Engine`]. /// /// * `keywords` holds a slice of strings that define the custom syntax. - /// * `scope_changed` specifies variables have been added/removed by this custom syntax. + /// * `scope_may_be_changed` specifies variables have been added/removed by this custom syntax. /// * `func` is the implementation function. /// /// # Caveat - Do not change beyond block scope /// - /// If `scope_changed` is `true`, then the current [`Scope`][crate::Scope] is assumed to be + /// If `scope_may_be_changed` is `true`, then the current [`Scope`][crate::Scope] is assumed to be /// modified by this custom syntax. /// /// Adding new variables and/or removing variables are allowed. Simply modifying the values of @@ -182,7 +182,7 @@ impl Engine { pub fn register_custom_syntax + Into>( &mut self, keywords: &[S], - scope_changed: bool, + scope_may_be_changed: bool, func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static, ) -> Result<&mut Self, ParseError> { let keywords = keywords.as_ref(); @@ -289,7 +289,7 @@ impl Engine { Ok(Some(segments[stream.len()].clone())) } }, - scope_changed, + scope_may_be_changed, func, ); @@ -301,7 +301,7 @@ impl Engine { /// /// This function is very low level. /// - /// * `scope_changed` specifies variables have been added/removed by this custom syntax. + /// * `scope_may_be_changed` specifies variables have been added/removed by this custom syntax. /// * `parse` is the parsing function. /// * `func` is the implementation function. /// @@ -313,7 +313,7 @@ impl Engine { parse: impl Fn(&[ImmutableString], &str) -> Result, ParseError> + SendSync + 'static, - scope_changed: bool, + scope_may_be_changed: bool, func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static, ) -> &mut Self { self.custom_syntax.insert( @@ -321,7 +321,7 @@ impl Engine { CustomSyntax { parse: Box::new(parse), func: (Box::new(func) as Box).into(), - scope_changed, + scope_may_be_changed, } .into(), ); diff --git a/src/optimize.rs b/src/optimize.rs index 22a67ac8..44ce7478 100644 --- a/src/optimize.rs +++ b/src/optimize.rs @@ -1051,7 +1051,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut State, _chaining: bool) { // Custom syntax Expr::Custom(x, _) => { - if x.scope_changed { + if x.scope_may_be_changed { state.propagate_constants = false; } x.keywords.iter_mut().for_each(|expr| optimize_expr(expr, state, false));