diff --git a/src/ast.rs b/src/ast.rs index 1fc091fe..e9823156 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -858,11 +858,11 @@ impl Stmt { #[derive(Clone)] pub struct CustomExpr { /// Implementation function. - pub(crate) func: Shared, + pub func: Shared, /// List of keywords. - pub(crate) keywords: StaticVec, + pub keywords: StaticVec, /// List of tokens actually parsed. - pub(crate) tokens: Vec, + pub tokens: Vec, } impl fmt::Debug for CustomExpr { @@ -876,24 +876,6 @@ impl fmt::Debug for CustomExpr { } } -impl CustomExpr { - /// Get the implementation function for this custom syntax. - #[inline(always)] - pub fn func(&self) -> &FnCustomSyntaxEval { - self.func.as_ref() - } - /// Get the keywords for this custom syntax. - #[inline(always)] - pub fn keywords(&self) -> &[Expr] { - &self.keywords - } - /// Get the actual parsed tokens for this custom syntax. - #[inline(always)] - pub fn tokens(&self) -> &[ImmutableString] { - &self.tokens - } -} - /// _(INTERNALS)_ A binary expression. /// Exported under the `internals` feature only. /// diff --git a/src/engine.rs b/src/engine.rs index 0fad8de5..0fa2ee9f 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -532,7 +532,7 @@ pub struct Limits { #[derive(Debug)] pub struct EvalContext<'e, 'x, 'px: 'x, 'a, 's, 'm, 'pm: 'm, 't, 'pt: 't> { pub(crate) engine: &'e Engine, - pub scope: &'x mut Scope<'px>, + pub(crate) scope: &'x mut Scope<'px>, pub(crate) mods: &'a mut Imports, pub(crate) state: &'s mut State, pub(crate) lib: &'m [&'pm Module], @@ -546,6 +546,16 @@ impl<'e, 'x, 'px, 'a, 's, 'm, 'pm, 't, 'pt> EvalContext<'e, 'x, 'px, 'a, 's, 'm, pub fn engine(&self) -> &'e Engine { self.engine } + /// The current [`Scope`]. + #[inline(always)] + pub fn scope(&self) -> &Scope<'px> { + self.scope + } + /// Mutable reference to the current [`Scope`]. + #[inline(always)] + pub fn scope_mut(&mut self) -> &mut &'x mut Scope<'px> { + &mut self.scope + } /// _(INTERNALS)_ The current set of modules imported via `import` statements. /// Available under the `internals` feature only. #[cfg(feature = "internals")] @@ -1822,7 +1832,7 @@ impl Engine { Expr::Custom(custom, _) => { let expressions = custom - .keywords() + .keywords .iter() .map(Into::into) .collect::>(); diff --git a/tests/syntax.rs b/tests/syntax.rs index 04cfaabf..2f35eca3 100644 --- a/tests/syntax.rs +++ b/tests/syntax.rs @@ -27,7 +27,7 @@ fn test_custom_syntax() -> Result<(), Box> { let stmt = inputs.get(1).unwrap(); let condition = inputs.get(2).unwrap(); - context.scope.push(var_name, 0 as INT); + context.scope_mut().push(var_name, 0 as INT); loop { context.eval_expression_tree(stmt)?; @@ -110,7 +110,7 @@ fn test_custom_syntax_raw() -> Result<(), Box> { }, 1, |context, inputs| { - context.scope.push("foo", 999 as INT); + context.scope_mut().push("foo", 999 as INT); Ok(match inputs[0].get_variable_name().unwrap() { "world" => 123 as INT, diff --git a/tests/var_scope.rs b/tests/var_scope.rs index 52fff87f..6c4c41aa 100644 --- a/tests/var_scope.rs +++ b/tests/var_scope.rs @@ -71,7 +71,7 @@ fn test_var_resolver() -> Result<(), Box> { } // Silently maps 'chameleon' into 'innocent'. "chameleon" => context - .scope + .scope() .get_value("innocent") .map(Some) .ok_or_else(|| {