Better encapsulate EvalContext.

This commit is contained in:
Stephen Chung
2022-05-17 16:21:17 +08:00
parent 591f7d7362
commit 7c8c6659ae
5 changed files with 64 additions and 77 deletions

View File

@@ -1,7 +1,6 @@
//! Module implementing custom syntax for [`Engine`].
use crate::ast::Expr;
use crate::eval::Caches;
use crate::func::native::SendSync;
use crate::parser::ParseResult;
use crate::tokenizer::{is_valid_identifier, Token};
@@ -140,34 +139,6 @@ impl Deref for Expression<'_> {
}
}
impl EvalContext<'_, '_, '_, '_, '_, '_, '_, '_> {
/// Evaluate an [expression tree][Expression] within this [evaluation context][`EvalContext`].
///
/// # WARNING - Low Level API
///
/// This function is very low level. It evaluates an expression from an [`AST`][crate::AST].
#[inline(always)]
pub fn eval_expression_tree(&mut self, expr: &Expression) -> RhaiResult {
let mut caches;
self.engine.eval_expr(
self.scope,
self.global,
match self.caches.as_mut() {
Some(c) => c,
None => {
caches = Caches::new();
&mut caches
}
},
self.lib,
self.this_ptr,
expr,
self.level,
)
}
}
/// Definition of a custom syntax definition.
pub struct CustomSyntax {
/// A parsing function to return the next token in a custom syntax based on the