Remove ref modifiers.
This commit is contained in:
parent
3f247fd695
commit
e0514a4ec0
@ -831,7 +831,7 @@ impl<'e> Engine<'e> {
|
||||
ast: &AST,
|
||||
) -> Result<(), EvalAltResult> {
|
||||
let statements = {
|
||||
let AST(ref statements, ref functions) = ast;
|
||||
let AST(statements, functions) = ast;
|
||||
self.fn_lib = Some(functions.clone());
|
||||
statements
|
||||
};
|
||||
|
@ -420,7 +420,7 @@ impl Engine<'_> {
|
||||
};
|
||||
|
||||
// Search built-in's and external functions
|
||||
if let Some(ref functions) = self.functions {
|
||||
if let Some(functions) = &self.functions {
|
||||
if let Some(func) = functions.get(&spec) {
|
||||
// Run external function
|
||||
Ok(Some(func(args, pos)?))
|
||||
@ -443,7 +443,7 @@ impl Engine<'_> {
|
||||
level: usize,
|
||||
) -> Result<Dynamic, EvalAltResult> {
|
||||
// First search in script-defined functions (can override built-in)
|
||||
if let Some(ref fn_lib_arc) = self.fn_lib {
|
||||
if let Some(fn_lib_arc) = &self.fn_lib {
|
||||
if let Some(fn_def) = fn_lib_arc.clone().get_function(fn_name, args.len()) {
|
||||
match scope {
|
||||
// Extern scope passed in which is not empty
|
||||
@ -511,7 +511,7 @@ impl Engine<'_> {
|
||||
}
|
||||
|
||||
// Search built-in's and external functions
|
||||
if let Some(ref functions) = self.functions {
|
||||
if let Some(functions) = &self.functions {
|
||||
if let Some(func) = functions.get(&spec) {
|
||||
// Run external function
|
||||
let result = func(args, pos)?;
|
||||
@ -1395,7 +1395,7 @@ impl Engine<'_> {
|
||||
// If new functions are defined, merge it into the current functions library
|
||||
let merged = AST(
|
||||
ast.0,
|
||||
if let Some(ref fn_lib) = self.fn_lib {
|
||||
if let Some(fn_lib) = &self.fn_lib {
|
||||
#[cfg(feature = "sync")]
|
||||
{
|
||||
Arc::new(fn_lib.as_ref().merge(&ast.1))
|
||||
@ -1557,7 +1557,7 @@ impl Engine<'_> {
|
||||
let arr = self.eval_expr(scope, expr, level)?;
|
||||
let tid = Any::type_id(&*arr);
|
||||
|
||||
if let Some(ref type_iterators) = self.type_iterators {
|
||||
if let Some(type_iterators) = &self.type_iterators {
|
||||
if let Some(iter_fn) = type_iterators.get(&tid) {
|
||||
// Add the loop variable - variable name is copied
|
||||
scope.push(name.clone(), ());
|
||||
|
32
src/error.rs
32
src/error.rs
@ -130,8 +130,8 @@ impl ParseError {
|
||||
}
|
||||
|
||||
pub(crate) fn desc(&self) -> &str {
|
||||
match self.0 {
|
||||
ParseErrorType::BadInput(ref p) => p,
|
||||
match &self.0 {
|
||||
ParseErrorType::BadInput(p) => p,
|
||||
ParseErrorType::UnexpectedEOF => "Script is incomplete",
|
||||
ParseErrorType::UnknownOperator(_) => "Unknown operator",
|
||||
ParseErrorType::MissingToken(_, _) => "Expecting a certain token that is missing",
|
||||
@ -166,50 +166,48 @@ impl Error for ParseError {}
|
||||
|
||||
impl fmt::Display for ParseError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.0 {
|
||||
ParseErrorType::BadInput(ref s) | ParseErrorType::MalformedCallExpr(ref s) => {
|
||||
match &self.0 {
|
||||
ParseErrorType::BadInput(s) | ParseErrorType::MalformedCallExpr(s) => {
|
||||
write!(f, "{}", if s.is_empty() { self.desc() } else { s })?
|
||||
}
|
||||
ParseErrorType::ForbiddenConstantExpr(ref s) => {
|
||||
ParseErrorType::ForbiddenConstantExpr(s) => {
|
||||
write!(f, "Expecting a constant to assign to '{}'", s)?
|
||||
}
|
||||
ParseErrorType::UnknownOperator(ref s) => write!(f, "{}: '{}'", self.desc(), s)?,
|
||||
ParseErrorType::UnknownOperator(s) => write!(f, "{}: '{}'", self.desc(), s)?,
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
ParseErrorType::MalformedIndexExpr(ref s) => {
|
||||
ParseErrorType::MalformedIndexExpr(s) => {
|
||||
write!(f, "{}", if s.is_empty() { self.desc() } else { s })?
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
ParseErrorType::DuplicatedProperty(ref s) => {
|
||||
ParseErrorType::DuplicatedProperty(s) => {
|
||||
write!(f, "Duplicated property '{}' for object map literal", s)?
|
||||
}
|
||||
|
||||
ParseErrorType::ExprExpected(ref s) => write!(f, "Expecting {} expression", s)?,
|
||||
ParseErrorType::ExprExpected(s) => write!(f, "Expecting {} expression", s)?,
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
ParseErrorType::FnMissingParams(ref s) => {
|
||||
ParseErrorType::FnMissingParams(s) => {
|
||||
write!(f, "Expecting parameters for function '{}'", s)?
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
ParseErrorType::FnMissingBody(ref s) => {
|
||||
ParseErrorType::FnMissingBody(s) => {
|
||||
write!(f, "Expecting body statement block for function '{}'", s)?
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
ParseErrorType::FnDuplicatedParam(ref s, ref arg) => {
|
||||
ParseErrorType::FnDuplicatedParam(s, arg) => {
|
||||
write!(f, "Duplicated parameter '{}' for function '{}'", arg, s)?
|
||||
}
|
||||
|
||||
ParseErrorType::MissingToken(ref token, ref s) => {
|
||||
write!(f, "Expecting '{}' {}", token, s)?
|
||||
}
|
||||
ParseErrorType::MissingToken(token, s) => write!(f, "Expecting '{}' {}", token, s)?,
|
||||
|
||||
ParseErrorType::AssignmentToConstant(ref s) if s.is_empty() => {
|
||||
ParseErrorType::AssignmentToConstant(s) if s.is_empty() => {
|
||||
write!(f, "{}", self.desc())?
|
||||
}
|
||||
ParseErrorType::AssignmentToConstant(ref s) => {
|
||||
ParseErrorType::AssignmentToConstant(s) => {
|
||||
write!(f, "Cannot assign to constant '{}'", s)?
|
||||
}
|
||||
_ => write!(f, "{}", self.desc())?,
|
||||
|
@ -453,7 +453,7 @@ fn optimize_expr<'a>(expr: Expr, state: &mut State<'a>) -> Expr {
|
||||
&& args.iter().all(|expr| expr.is_constant()) // all arguments are constants
|
||||
=> {
|
||||
// First search in script-defined functions (can override built-in)
|
||||
if let Some(ref fn_lib_arc) = state.engine.fn_lib {
|
||||
if let Some(fn_lib_arc) = &state.engine.fn_lib {
|
||||
if fn_lib_arc.has_function(&id, args.len()) {
|
||||
// A script-defined function overrides the built-in function - do not make the call
|
||||
return Expr::FunctionCall(id, args.into_iter().map(|a| optimize_expr(a, state)).collect(), def_value, pos);
|
||||
@ -493,11 +493,11 @@ fn optimize_expr<'a>(expr: Expr, state: &mut State<'a>) -> Expr {
|
||||
Expr::FunctionCall(id, args.into_iter().map(|a| optimize_expr(a, state)).collect(), def_value, pos),
|
||||
|
||||
// constant-name
|
||||
Expr::Variable(ref name, _) if state.contains_constant(name) => {
|
||||
Expr::Variable(name, _) if state.contains_constant(&name) => {
|
||||
state.set_dirty();
|
||||
|
||||
// Replace constant with value
|
||||
state.find_constant(name).expect("should find constant in scope!").clone()
|
||||
state.find_constant(&name).expect("should find constant in scope!").clone()
|
||||
}
|
||||
|
||||
// All other expressions - skip
|
||||
|
@ -2061,7 +2061,7 @@ fn parse_binary_op<'a>(
|
||||
let mut current_lhs = lhs;
|
||||
|
||||
loop {
|
||||
let (current_precedence, bind_right) = if let Some((ref current_op, _)) = input.peek() {
|
||||
let (current_precedence, bind_right) = if let Some((current_op, _)) = input.peek() {
|
||||
(current_op.precedence(), current_op.is_bind_right())
|
||||
} else {
|
||||
(0, false)
|
||||
|
@ -268,32 +268,32 @@ impl EvalAltResult {
|
||||
/// Consume the current `EvalAltResult` and return a new one
|
||||
/// with the specified `Position`.
|
||||
pub(crate) fn set_position(mut self, new_position: Position) -> Self {
|
||||
match self {
|
||||
match &mut self {
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
Self::ErrorReadingScriptFile(_, _) => (),
|
||||
|
||||
Self::ErrorParsing(ParseError(_, ref mut pos))
|
||||
| Self::ErrorFunctionNotFound(_, ref mut pos)
|
||||
| Self::ErrorFunctionArgsMismatch(_, _, _, ref mut pos)
|
||||
| Self::ErrorBooleanArgMismatch(_, ref mut pos)
|
||||
| Self::ErrorCharMismatch(ref mut pos)
|
||||
| Self::ErrorArrayBounds(_, _, ref mut pos)
|
||||
| Self::ErrorStringBounds(_, _, ref mut pos)
|
||||
| Self::ErrorIndexingType(_, ref mut pos)
|
||||
| Self::ErrorNumericIndexExpr(ref mut pos)
|
||||
| Self::ErrorStringIndexExpr(ref mut pos)
|
||||
| Self::ErrorLogicGuard(ref mut pos)
|
||||
| Self::ErrorFor(ref mut pos)
|
||||
| Self::ErrorVariableNotFound(_, ref mut pos)
|
||||
| Self::ErrorAssignmentToUnknownLHS(ref mut pos)
|
||||
| Self::ErrorAssignmentToConstant(_, ref mut pos)
|
||||
| Self::ErrorMismatchOutputType(_, ref mut pos)
|
||||
| Self::ErrorDotExpr(_, ref mut pos)
|
||||
| Self::ErrorArithmetic(_, ref mut pos)
|
||||
| Self::ErrorStackOverflow(ref mut pos)
|
||||
| Self::ErrorRuntime(_, ref mut pos)
|
||||
| Self::ErrorLoopBreak(_, ref mut pos)
|
||||
| Self::Return(_, ref mut pos) => *pos = new_position,
|
||||
Self::ErrorParsing(ParseError(_, pos))
|
||||
| Self::ErrorFunctionNotFound(_, pos)
|
||||
| Self::ErrorFunctionArgsMismatch(_, _, _, pos)
|
||||
| Self::ErrorBooleanArgMismatch(_, pos)
|
||||
| Self::ErrorCharMismatch(pos)
|
||||
| Self::ErrorArrayBounds(_, _, pos)
|
||||
| Self::ErrorStringBounds(_, _, pos)
|
||||
| Self::ErrorIndexingType(_, pos)
|
||||
| Self::ErrorNumericIndexExpr(pos)
|
||||
| Self::ErrorStringIndexExpr(pos)
|
||||
| Self::ErrorLogicGuard(pos)
|
||||
| Self::ErrorFor(pos)
|
||||
| Self::ErrorVariableNotFound(_, pos)
|
||||
| Self::ErrorAssignmentToUnknownLHS(pos)
|
||||
| Self::ErrorAssignmentToConstant(_, pos)
|
||||
| Self::ErrorMismatchOutputType(_, pos)
|
||||
| Self::ErrorDotExpr(_, pos)
|
||||
| Self::ErrorArithmetic(_, pos)
|
||||
| Self::ErrorStackOverflow(pos)
|
||||
| Self::ErrorRuntime(_, pos)
|
||||
| Self::ErrorLoopBreak(_, pos)
|
||||
| Self::Return(_, pos) => *pos = new_position,
|
||||
}
|
||||
|
||||
self
|
||||
|
Loading…
Reference in New Issue
Block a user