Merge branch 'master' into plugins
This commit is contained in:
@@ -95,6 +95,36 @@ pub const MARKER_BLOCK: &str = "$block$";
|
||||
#[cfg(feature = "internals")]
|
||||
pub const MARKER_IDENT: &str = "$ident$";
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
pub struct Expression<'a>(&'a Expr);
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
impl<'a> From<&'a Expr> for Expression<'a> {
|
||||
fn from(expr: &'a Expr) -> Self {
|
||||
Self(expr)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
impl Expression<'_> {
|
||||
/// If this expression is a variable name, return it. Otherwise `None`.
|
||||
#[cfg(feature = "internals")]
|
||||
pub fn get_variable_name(&self) -> Option<&str> {
|
||||
match self.0 {
|
||||
Expr::Variable(x) => Some((x.0).0.as_str()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
/// Get the expression.
|
||||
pub(crate) fn expr(&self) -> &Expr {
|
||||
&self.0
|
||||
}
|
||||
/// Get the position of this expression.
|
||||
pub fn position(&self) -> Position {
|
||||
self.0.position()
|
||||
}
|
||||
}
|
||||
|
||||
/// A type specifying the method of chaining.
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
||||
enum ChainType {
|
||||
@@ -1691,10 +1721,10 @@ impl Engine {
|
||||
state: &mut State,
|
||||
lib: &Module,
|
||||
this_ptr: &mut Option<&mut Dynamic>,
|
||||
expr: &Expr,
|
||||
expr: &Expression,
|
||||
level: usize,
|
||||
) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)
|
||||
self.eval_expr(scope, mods, state, lib, this_ptr, expr.expr(), level)
|
||||
}
|
||||
|
||||
/// Evaluate an expression
|
||||
@@ -2132,8 +2162,8 @@ impl Engine {
|
||||
#[cfg(feature = "internals")]
|
||||
Expr::Custom(x) => {
|
||||
let func = (x.0).1.as_ref();
|
||||
let exprs = (x.0).0.as_ref();
|
||||
func(self, scope, mods, state, lib, this_ptr, exprs, level)
|
||||
let ep: StaticVec<_> = (x.0).0.iter().map(|e| e.into()).collect();
|
||||
func(self, scope, mods, state, lib, this_ptr, ep.as_ref(), level)
|
||||
}
|
||||
|
||||
_ => unreachable!(),
|
||||
|
@@ -173,7 +173,7 @@ pub use parser::{CustomExpr, Expr, ReturnType, ScriptFnDef, Stmt};
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
#[deprecated(note = "this type is volatile and may change")]
|
||||
pub use engine::{Imports, State as EvalState};
|
||||
pub use engine::{Expression, Imports, State as EvalState};
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
#[deprecated(note = "this type is volatile and may change")]
|
||||
|
@@ -342,7 +342,11 @@ impl Module {
|
||||
/// Set a Rust function into the module, returning a hash key.
|
||||
///
|
||||
/// If there is an existing Rust function of the same hash, it is replaced.
|
||||
pub(crate) fn set_fn(
|
||||
///
|
||||
/// ## WARNING - Low Level API
|
||||
///
|
||||
/// This function is very low level.
|
||||
pub fn set_fn(
|
||||
&mut self,
|
||||
name: impl Into<String>,
|
||||
access: FnAccess,
|
||||
|
@@ -908,14 +908,6 @@ impl Expr {
|
||||
_ => self,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
pub fn get_variable_name(&self) -> Option<&str> {
|
||||
match self {
|
||||
Self::Variable(x) => Some((x.0).0.as_str()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Consume a particular token, checking that it is the expected one.
|
||||
|
@@ -2,11 +2,10 @@
|
||||
#![cfg(feature = "internals")]
|
||||
|
||||
use crate::any::Dynamic;
|
||||
use crate::engine::{Engine, Imports, State, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT};
|
||||
use crate::engine::{Engine, Expression, Imports, State, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT};
|
||||
use crate::error::LexError;
|
||||
use crate::fn_native::{SendSync, Shared};
|
||||
use crate::module::Module;
|
||||
use crate::parser::Expr;
|
||||
use crate::result::EvalAltResult;
|
||||
use crate::scope::Scope;
|
||||
use crate::token::{is_valid_identifier, Token};
|
||||
@@ -28,7 +27,7 @@ pub type FnCustomSyntaxEval = dyn Fn(
|
||||
&mut State,
|
||||
&Module,
|
||||
&mut Option<&mut Dynamic>,
|
||||
&[Expr],
|
||||
&[Expression],
|
||||
usize,
|
||||
) -> Result<Dynamic, Box<EvalAltResult>>;
|
||||
/// A general function trail object.
|
||||
@@ -71,7 +70,7 @@ impl Engine {
|
||||
&mut State,
|
||||
&Module,
|
||||
&mut Option<&mut Dynamic>,
|
||||
&[Expr],
|
||||
&[Expression],
|
||||
usize,
|
||||
) -> Result<Dynamic, Box<EvalAltResult>>
|
||||
+ SendSync
|
||||
|
Reference in New Issue
Block a user