2020-03-08 12:54:02 +01:00
|
|
|
//! Module containing error definitions for the evaluation process.
|
2020-03-04 15:00:01 +01:00
|
|
|
|
|
|
|
use crate::any::Dynamic;
|
2020-06-12 12:04:16 +02:00
|
|
|
use crate::error::ParseErrorType;
|
2020-04-15 16:21:23 +02:00
|
|
|
use crate::parser::INT;
|
|
|
|
use crate::token::Position;
|
2020-03-11 04:03:18 +01:00
|
|
|
|
2020-03-17 19:26:11 +01:00
|
|
|
use crate::stdlib::{
|
2020-04-24 06:39:24 +02:00
|
|
|
boxed::Box,
|
2020-03-17 19:26:11 +01:00
|
|
|
error::Error,
|
|
|
|
fmt,
|
|
|
|
string::{String, ToString},
|
|
|
|
};
|
|
|
|
|
2020-03-18 05:04:26 +01:00
|
|
|
#[cfg(not(feature = "no_std"))]
|
2020-06-17 03:54:17 +02:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2020-03-17 19:26:11 +01:00
|
|
|
use crate::stdlib::path::PathBuf;
|
2020-03-04 15:00:01 +01:00
|
|
|
|
|
|
|
/// Evaluation result.
|
|
|
|
///
|
|
|
|
/// All wrapped `Position` values represent the location in the script where the error occurs.
|
2020-04-07 07:23:06 +02:00
|
|
|
///
|
|
|
|
/// Currently, `EvalAltResult` is neither `Send` nor `Sync`. Turn on the `sync` feature to make it `Send + Sync`.
|
2020-03-04 15:00:01 +01:00
|
|
|
#[derive(Debug)]
|
2020-06-25 05:07:46 +02:00
|
|
|
#[non_exhaustive]
|
2020-03-04 15:00:01 +01:00
|
|
|
pub enum EvalAltResult {
|
|
|
|
/// Syntax error.
|
2020-06-12 12:04:16 +02:00
|
|
|
ErrorParsing(ParseErrorType, Position),
|
2020-03-30 16:19:37 +02:00
|
|
|
|
|
|
|
/// Error reading from a script file. Wrapped value is the path of the script file.
|
2020-04-03 13:42:01 +02:00
|
|
|
///
|
2020-04-10 06:16:39 +02:00
|
|
|
/// Never appears under the `no_std` feature.
|
2020-03-30 16:19:37 +02:00
|
|
|
#[cfg(not(feature = "no_std"))]
|
2020-06-17 03:54:17 +02:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2020-05-05 18:09:04 +02:00
|
|
|
ErrorReadingScriptFile(PathBuf, Position, std::io::Error),
|
2020-03-30 16:19:37 +02:00
|
|
|
|
2020-07-26 09:53:22 +02:00
|
|
|
/// Call to an unknown function. Wrapped value is the signature of the function.
|
2020-03-04 15:00:01 +01:00
|
|
|
ErrorFunctionNotFound(String, Position),
|
2020-05-13 15:58:38 +02:00
|
|
|
/// An error has occurred inside a called function.
|
2020-07-26 09:53:22 +02:00
|
|
|
/// Wrapped values are the name of the function and the interior error.
|
2020-05-13 15:58:38 +02:00
|
|
|
ErrorInFunctionCall(String, Box<EvalAltResult>, Position),
|
2020-07-30 17:29:11 +02:00
|
|
|
/// Access to `this` that is not bound.
|
|
|
|
ErrorUnboundThis(Position),
|
2020-03-04 15:00:01 +01:00
|
|
|
/// Non-boolean operand encountered for boolean operator. Wrapped value is the operator.
|
|
|
|
ErrorBooleanArgMismatch(String, Position),
|
2020-03-07 15:50:46 +01:00
|
|
|
/// Non-character value encountered where a character is required.
|
|
|
|
ErrorCharMismatch(Position),
|
2020-03-04 15:00:01 +01:00
|
|
|
/// Array access out-of-bounds.
|
|
|
|
/// Wrapped values are the current number of elements in the array and the index number.
|
2020-03-10 16:06:20 +01:00
|
|
|
ErrorArrayBounds(usize, INT, Position),
|
2020-03-04 15:00:01 +01:00
|
|
|
/// String indexing out-of-bounds.
|
|
|
|
/// Wrapped values are the current number of characters in the string and the index number.
|
2020-03-10 16:06:20 +01:00
|
|
|
ErrorStringBounds(usize, INT, Position),
|
2020-05-05 14:38:48 +02:00
|
|
|
/// Trying to index into a type that is not an array, an object map, or a string, and has no indexer function defined.
|
2020-03-07 10:32:15 +01:00
|
|
|
ErrorIndexingType(String, Position),
|
2020-03-04 15:00:01 +01:00
|
|
|
/// Trying to index into an array or string with an index that is not `i64`.
|
2020-03-29 17:53:35 +02:00
|
|
|
ErrorNumericIndexExpr(Position),
|
|
|
|
/// Trying to index into a map with an index that is not `String`.
|
|
|
|
ErrorStringIndexExpr(Position),
|
2020-05-04 13:36:58 +02:00
|
|
|
/// Trying to import with an expression that is not `String`.
|
|
|
|
ErrorImportExpr(Position),
|
2020-04-06 11:47:34 +02:00
|
|
|
/// Invalid arguments for `in` operator.
|
|
|
|
ErrorInExpr(Position),
|
2020-03-20 12:50:58 +01:00
|
|
|
/// The guard expression in an `if` or `while` statement does not return a boolean value.
|
|
|
|
ErrorLogicGuard(Position),
|
2020-03-04 15:00:01 +01:00
|
|
|
/// The `for` statement encounters a type that is not an iterator.
|
|
|
|
ErrorFor(Position),
|
|
|
|
/// Usage of an unknown variable. Wrapped value is the name of the variable.
|
|
|
|
ErrorVariableNotFound(String, Position),
|
2020-05-04 13:36:58 +02:00
|
|
|
/// Usage of an unknown module. Wrapped value is the name of the module.
|
|
|
|
ErrorModuleNotFound(String, Position),
|
2020-08-02 07:33:51 +02:00
|
|
|
/// Data race detected when accessing a variable. Wrapped value is the name of the variable.
|
|
|
|
ErrorDataRace(String, Position),
|
2020-03-04 15:00:01 +01:00
|
|
|
/// Assignment to an inappropriate LHS (left-hand-side) expression.
|
|
|
|
ErrorAssignmentToUnknownLHS(Position),
|
2020-03-13 11:12:41 +01:00
|
|
|
/// Assignment to a constant variable.
|
|
|
|
ErrorAssignmentToConstant(String, Position),
|
2020-03-04 15:00:01 +01:00
|
|
|
/// Returned type is not the same as the required output type.
|
2020-07-03 04:45:01 +02:00
|
|
|
/// Wrapped values are the type requested and type of the actual result.
|
|
|
|
ErrorMismatchOutputType(String, String, Position),
|
2020-03-04 15:00:01 +01:00
|
|
|
/// Inappropriate member access.
|
2020-03-07 10:32:15 +01:00
|
|
|
ErrorDotExpr(String, Position),
|
2020-03-04 15:00:01 +01:00
|
|
|
/// Arithmetic error encountered. Wrapped value is the error message.
|
|
|
|
ErrorArithmetic(String, Position),
|
2020-05-15 05:43:32 +02:00
|
|
|
/// Number of operations over maximum limit.
|
|
|
|
ErrorTooManyOperations(Position),
|
2020-05-15 15:40:54 +02:00
|
|
|
/// Modules over maximum limit.
|
|
|
|
ErrorTooManyModules(Position),
|
2020-03-27 07:34:01 +01:00
|
|
|
/// Call stack over maximum limit.
|
|
|
|
ErrorStackOverflow(Position),
|
2020-06-14 08:25:47 +02:00
|
|
|
/// Data value over maximum size limit. Wrapped values are the data type, maximum size and current size.
|
|
|
|
ErrorDataTooLarge(String, usize, usize, Position),
|
2020-05-15 05:43:32 +02:00
|
|
|
/// The script is prematurely terminated.
|
|
|
|
ErrorTerminated(Position),
|
2020-03-04 15:00:01 +01:00
|
|
|
/// Run-time error encountered. Wrapped value is the error message.
|
|
|
|
ErrorRuntime(String, Position),
|
2020-03-30 16:19:37 +02:00
|
|
|
|
2020-03-17 10:33:37 +01:00
|
|
|
/// Breaking out of loops - not an error if within a loop.
|
2020-04-01 10:22:18 +02:00
|
|
|
/// The wrapped value, if true, means breaking clean out of the loop (i.e. a `break` statement).
|
|
|
|
/// The wrapped value, if false, means breaking the current context (i.e. a `continue` statement).
|
|
|
|
ErrorLoopBreak(bool, Position),
|
2020-03-04 15:00:01 +01:00
|
|
|
/// Not an error: Value returned from a script via the `return` keyword.
|
|
|
|
/// Wrapped value is the result value.
|
|
|
|
Return(Dynamic, Position),
|
|
|
|
}
|
|
|
|
|
2020-03-14 16:39:45 +01:00
|
|
|
impl EvalAltResult {
|
|
|
|
pub(crate) fn desc(&self) -> &str {
|
2020-03-04 15:00:01 +01:00
|
|
|
match self {
|
2020-03-30 16:19:37 +02:00
|
|
|
#[cfg(not(feature = "no_std"))]
|
2020-06-17 03:54:17 +02:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2020-06-17 10:49:51 +02:00
|
|
|
Self::ErrorReadingScriptFile(_, _, _) => "Cannot read from script file",
|
2020-03-30 16:19:37 +02:00
|
|
|
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorParsing(p, _) => p.desc(),
|
2020-05-13 15:58:38 +02:00
|
|
|
Self::ErrorInFunctionCall(_, _, _) => "Error in called function",
|
2020-03-04 15:00:01 +01:00
|
|
|
Self::ErrorFunctionNotFound(_, _) => "Function not found",
|
2020-07-30 17:29:11 +02:00
|
|
|
Self::ErrorUnboundThis(_) => "'this' is not bound",
|
2020-03-04 15:00:01 +01:00
|
|
|
Self::ErrorBooleanArgMismatch(_, _) => "Boolean operator expects boolean operands",
|
2020-03-07 15:50:46 +01:00
|
|
|
Self::ErrorCharMismatch(_) => "Character expected",
|
2020-03-29 17:53:35 +02:00
|
|
|
Self::ErrorNumericIndexExpr(_) => {
|
|
|
|
"Indexing into an array or string expects an integer index"
|
|
|
|
}
|
|
|
|
Self::ErrorStringIndexExpr(_) => "Indexing into an object map expects a string index",
|
2020-03-07 10:32:15 +01:00
|
|
|
Self::ErrorIndexingType(_, _) => {
|
2020-05-05 14:38:48 +02:00
|
|
|
"Indexing can only be performed on an array, an object map, a string, or a type with an indexer function defined"
|
2020-03-07 10:32:15 +01:00
|
|
|
}
|
2020-05-04 13:36:58 +02:00
|
|
|
Self::ErrorImportExpr(_) => "Importing a module expects a string path",
|
2020-03-04 15:00:01 +01:00
|
|
|
Self::ErrorArrayBounds(_, index, _) if *index < 0 => {
|
|
|
|
"Array access expects non-negative index"
|
|
|
|
}
|
2020-04-10 15:02:13 +02:00
|
|
|
Self::ErrorArrayBounds(0, _, _) => "Empty array has nothing to access",
|
2020-03-04 15:00:01 +01:00
|
|
|
Self::ErrorArrayBounds(_, _, _) => "Array index out of bounds",
|
|
|
|
Self::ErrorStringBounds(_, index, _) if *index < 0 => {
|
|
|
|
"Indexing a string expects a non-negative index"
|
|
|
|
}
|
2020-04-10 15:02:13 +02:00
|
|
|
Self::ErrorStringBounds(0, _, _) => "Empty string has nothing to index",
|
2020-03-04 15:00:01 +01:00
|
|
|
Self::ErrorStringBounds(_, _, _) => "String index out of bounds",
|
2020-04-10 15:02:13 +02:00
|
|
|
Self::ErrorLogicGuard(_) => "Boolean value expected",
|
|
|
|
Self::ErrorFor(_) => "For loop expects an array, object map, or range",
|
2020-03-04 15:00:01 +01:00
|
|
|
Self::ErrorVariableNotFound(_, _) => "Variable not found",
|
2020-08-02 07:33:51 +02:00
|
|
|
Self::ErrorModuleNotFound(_, _) => "Module not found",
|
|
|
|
Self::ErrorDataRace(_, _) => "Data race detected when accessing variable",
|
2020-03-04 15:00:01 +01:00
|
|
|
Self::ErrorAssignmentToUnknownLHS(_) => {
|
|
|
|
"Assignment to an unsupported left-hand side expression"
|
|
|
|
}
|
2020-03-13 11:12:41 +01:00
|
|
|
Self::ErrorAssignmentToConstant(_, _) => "Assignment to a constant variable",
|
2020-07-03 04:45:01 +02:00
|
|
|
Self::ErrorMismatchOutputType(_, _, _) => "Output type is incorrect",
|
2020-04-06 11:47:34 +02:00
|
|
|
Self::ErrorInExpr(_) => "Malformed 'in' expression",
|
2020-03-07 10:32:15 +01:00
|
|
|
Self::ErrorDotExpr(_, _) => "Malformed dot expression",
|
2020-03-04 15:00:01 +01:00
|
|
|
Self::ErrorArithmetic(_, _) => "Arithmetic error",
|
2020-05-15 05:43:32 +02:00
|
|
|
Self::ErrorTooManyOperations(_) => "Too many operations",
|
2020-05-15 15:40:54 +02:00
|
|
|
Self::ErrorTooManyModules(_) => "Too many modules imported",
|
2020-03-27 07:34:01 +01:00
|
|
|
Self::ErrorStackOverflow(_) => "Stack overflow",
|
2020-06-14 08:25:47 +02:00
|
|
|
Self::ErrorDataTooLarge(_, _, _, _) => "Data size exceeds maximum limit",
|
2020-05-15 05:43:32 +02:00
|
|
|
Self::ErrorTerminated(_) => "Script terminated.",
|
2020-03-04 15:00:01 +01:00
|
|
|
Self::ErrorRuntime(_, _) => "Runtime error",
|
2020-04-01 10:22:18 +02:00
|
|
|
Self::ErrorLoopBreak(true, _) => "Break statement not inside a loop",
|
|
|
|
Self::ErrorLoopBreak(false, _) => "Continue statement not inside a loop",
|
2020-03-04 15:00:01 +01:00
|
|
|
Self::Return(_, _) => "[Not Error] Function returns value",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-14 16:39:45 +01:00
|
|
|
impl Error for EvalAltResult {}
|
|
|
|
|
2020-03-08 12:54:02 +01:00
|
|
|
impl fmt::Display for EvalAltResult {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2020-03-14 16:39:45 +01:00
|
|
|
let desc = self.desc();
|
2020-06-12 12:04:16 +02:00
|
|
|
let pos = self.position();
|
2020-03-04 15:00:01 +01:00
|
|
|
|
|
|
|
match self {
|
2020-03-30 16:19:37 +02:00
|
|
|
#[cfg(not(feature = "no_std"))]
|
2020-06-17 03:54:17 +02:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorReadingScriptFile(path, _, err) => {
|
|
|
|
write!(f, "{} '{}': {}", desc, path.display(), err)?
|
2020-05-05 18:09:04 +02:00
|
|
|
}
|
2020-03-30 16:19:37 +02:00
|
|
|
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorParsing(p, _) => write!(f, "Syntax error: {}", p)?,
|
2020-03-30 16:19:37 +02:00
|
|
|
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorInFunctionCall(s, err, _) => {
|
|
|
|
write!(f, "Error in call to function '{}' : {}", s, err)?
|
2020-05-13 15:58:38 +02:00
|
|
|
}
|
|
|
|
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorFunctionNotFound(s, _)
|
|
|
|
| Self::ErrorVariableNotFound(s, _)
|
2020-08-02 07:33:51 +02:00
|
|
|
| Self::ErrorDataRace(s, _)
|
2020-06-12 12:04:16 +02:00
|
|
|
| Self::ErrorModuleNotFound(s, _) => write!(f, "{}: '{}'", desc, s)?,
|
2020-05-04 11:43:54 +02:00
|
|
|
|
2020-07-27 12:10:45 +02:00
|
|
|
Self::ErrorDotExpr(s, _) if !s.is_empty() => write!(f, "{}", s)?,
|
2020-03-29 17:53:35 +02:00
|
|
|
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorIndexingType(_, _)
|
|
|
|
| Self::ErrorNumericIndexExpr(_)
|
|
|
|
| Self::ErrorStringIndexExpr(_)
|
2020-07-30 17:29:11 +02:00
|
|
|
| Self::ErrorUnboundThis(_)
|
2020-06-12 12:04:16 +02:00
|
|
|
| Self::ErrorImportExpr(_)
|
|
|
|
| Self::ErrorLogicGuard(_)
|
|
|
|
| Self::ErrorFor(_)
|
|
|
|
| Self::ErrorAssignmentToUnknownLHS(_)
|
|
|
|
| Self::ErrorInExpr(_)
|
|
|
|
| Self::ErrorDotExpr(_, _)
|
|
|
|
| Self::ErrorTooManyOperations(_)
|
|
|
|
| Self::ErrorTooManyModules(_)
|
|
|
|
| Self::ErrorStackOverflow(_)
|
2020-07-02 15:46:08 +02:00
|
|
|
| Self::ErrorTerminated(_) => f.write_str(desc)?,
|
2020-03-29 17:53:35 +02:00
|
|
|
|
2020-07-02 15:46:08 +02:00
|
|
|
Self::ErrorRuntime(s, _) => f.write_str(if s.is_empty() { desc } else { s })?,
|
2020-03-30 16:19:37 +02:00
|
|
|
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorAssignmentToConstant(s, _) => write!(f, "{}: '{}'", desc, s)?,
|
2020-07-03 04:45:01 +02:00
|
|
|
Self::ErrorMismatchOutputType(r, s, _) => {
|
|
|
|
write!(f, "{} (expecting {}): {}", desc, s, r)?
|
|
|
|
}
|
2020-07-02 15:46:08 +02:00
|
|
|
Self::ErrorArithmetic(s, _) => f.write_str(s)?,
|
2020-03-30 16:19:37 +02:00
|
|
|
|
2020-07-02 15:46:08 +02:00
|
|
|
Self::ErrorLoopBreak(_, _) => f.write_str(desc)?,
|
|
|
|
Self::Return(_, _) => f.write_str(desc)?,
|
2020-03-30 16:19:37 +02:00
|
|
|
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorBooleanArgMismatch(op, _) => {
|
|
|
|
write!(f, "{} operator expects boolean operands", op)?
|
2020-03-07 15:50:46 +01:00
|
|
|
}
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorCharMismatch(_) => write!(f, "string indexing expects a character value")?,
|
|
|
|
Self::ErrorArrayBounds(_, index, _) if *index < 0 => {
|
|
|
|
write!(f, "{}: {} < 0", desc, index)?
|
2020-03-04 15:00:01 +01:00
|
|
|
}
|
2020-07-02 15:46:08 +02:00
|
|
|
Self::ErrorArrayBounds(0, _, _) => f.write_str(desc)?,
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorArrayBounds(1, index, _) => write!(
|
2020-03-11 04:03:18 +01:00
|
|
|
f,
|
2020-06-12 12:04:16 +02:00
|
|
|
"Array index {} is out of bounds: only one element in the array",
|
|
|
|
index
|
|
|
|
)?,
|
|
|
|
Self::ErrorArrayBounds(max, index, _) => write!(
|
2020-03-05 13:28:03 +01:00
|
|
|
f,
|
2020-06-12 12:04:16 +02:00
|
|
|
"Array index {} is out of bounds: only {} elements in the array",
|
|
|
|
index, max
|
|
|
|
)?,
|
|
|
|
Self::ErrorStringBounds(_, index, _) if *index < 0 => {
|
|
|
|
write!(f, "{}: {} < 0", desc, index)?
|
2020-03-04 15:00:01 +01:00
|
|
|
}
|
2020-07-02 15:46:08 +02:00
|
|
|
Self::ErrorStringBounds(0, _, _) => f.write_str(desc)?,
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorStringBounds(1, index, _) => write!(
|
2020-03-11 04:03:18 +01:00
|
|
|
f,
|
2020-06-12 12:04:16 +02:00
|
|
|
"String index {} is out of bounds: only one character in the string",
|
|
|
|
index
|
|
|
|
)?,
|
|
|
|
Self::ErrorStringBounds(max, index, _) => write!(
|
2020-03-05 13:28:03 +01:00
|
|
|
f,
|
2020-06-12 12:04:16 +02:00
|
|
|
"String index {} is out of bounds: only {} characters in the string",
|
|
|
|
index, max
|
|
|
|
)?,
|
2020-06-14 08:25:47 +02:00
|
|
|
Self::ErrorDataTooLarge(typ, max, size, _) => {
|
|
|
|
write!(f, "{} ({}) exceeds the maximum limit ({})", typ, size, max)?
|
|
|
|
}
|
2020-06-12 12:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Do not write any position if None
|
|
|
|
if !pos.is_none() {
|
|
|
|
write!(f, " ({})", pos)?;
|
2020-03-04 15:00:01 +01:00
|
|
|
}
|
|
|
|
|
2020-06-12 12:04:16 +02:00
|
|
|
Ok(())
|
2020-03-04 15:00:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-08 15:47:13 +01:00
|
|
|
|
2020-04-21 17:25:12 +02:00
|
|
|
impl<T: AsRef<str>> From<T> for Box<EvalAltResult> {
|
2020-03-10 10:10:33 +01:00
|
|
|
fn from(err: T) -> Self {
|
2020-04-21 17:25:12 +02:00
|
|
|
Box::new(EvalAltResult::ErrorRuntime(
|
|
|
|
err.as_ref().to_string(),
|
|
|
|
Position::none(),
|
|
|
|
))
|
2020-03-10 10:10:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-08 15:47:13 +01:00
|
|
|
impl EvalAltResult {
|
2020-05-13 15:58:38 +02:00
|
|
|
/// Get the `Position` of this error.
|
2020-03-10 02:30:12 +01:00
|
|
|
pub fn position(&self) -> Position {
|
|
|
|
match self {
|
2020-03-18 05:04:26 +01:00
|
|
|
#[cfg(not(feature = "no_std"))]
|
2020-06-17 03:54:17 +02:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2020-05-05 18:09:04 +02:00
|
|
|
Self::ErrorReadingScriptFile(_, pos, _) => *pos,
|
2020-03-10 02:30:12 +01:00
|
|
|
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorParsing(_, pos)
|
|
|
|
| Self::ErrorFunctionNotFound(_, pos)
|
2020-05-13 15:58:38 +02:00
|
|
|
| Self::ErrorInFunctionCall(_, _, pos)
|
2020-07-30 17:29:11 +02:00
|
|
|
| Self::ErrorUnboundThis(pos)
|
2020-03-10 02:30:12 +01:00
|
|
|
| Self::ErrorBooleanArgMismatch(_, pos)
|
|
|
|
| Self::ErrorCharMismatch(pos)
|
|
|
|
| Self::ErrorArrayBounds(_, _, pos)
|
|
|
|
| Self::ErrorStringBounds(_, _, pos)
|
|
|
|
| Self::ErrorIndexingType(_, pos)
|
2020-03-29 17:53:35 +02:00
|
|
|
| Self::ErrorNumericIndexExpr(pos)
|
|
|
|
| Self::ErrorStringIndexExpr(pos)
|
2020-05-04 13:36:58 +02:00
|
|
|
| Self::ErrorImportExpr(pos)
|
2020-03-20 12:50:58 +01:00
|
|
|
| Self::ErrorLogicGuard(pos)
|
2020-03-10 02:30:12 +01:00
|
|
|
| Self::ErrorFor(pos)
|
|
|
|
| Self::ErrorVariableNotFound(_, pos)
|
2020-05-04 13:36:58 +02:00
|
|
|
| Self::ErrorModuleNotFound(_, pos)
|
2020-08-02 07:33:51 +02:00
|
|
|
| Self::ErrorDataRace(_, pos)
|
2020-03-10 02:30:12 +01:00
|
|
|
| Self::ErrorAssignmentToUnknownLHS(pos)
|
2020-03-13 11:12:41 +01:00
|
|
|
| Self::ErrorAssignmentToConstant(_, pos)
|
2020-07-03 04:45:01 +02:00
|
|
|
| Self::ErrorMismatchOutputType(_, _, pos)
|
2020-04-06 11:47:34 +02:00
|
|
|
| Self::ErrorInExpr(pos)
|
2020-03-10 02:30:12 +01:00
|
|
|
| Self::ErrorDotExpr(_, pos)
|
|
|
|
| Self::ErrorArithmetic(_, pos)
|
2020-05-15 05:43:32 +02:00
|
|
|
| Self::ErrorTooManyOperations(pos)
|
2020-05-15 15:40:54 +02:00
|
|
|
| Self::ErrorTooManyModules(pos)
|
2020-03-27 07:34:01 +01:00
|
|
|
| Self::ErrorStackOverflow(pos)
|
2020-06-14 08:25:47 +02:00
|
|
|
| Self::ErrorDataTooLarge(_, _, _, pos)
|
2020-05-15 05:43:32 +02:00
|
|
|
| Self::ErrorTerminated(pos)
|
2020-03-10 02:30:12 +01:00
|
|
|
| Self::ErrorRuntime(_, pos)
|
2020-04-01 10:22:18 +02:00
|
|
|
| Self::ErrorLoopBreak(_, pos)
|
2020-03-10 02:30:12 +01:00
|
|
|
| Self::Return(_, pos) => *pos,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 15:58:38 +02:00
|
|
|
/// Override the `Position` of this error.
|
|
|
|
pub fn set_position(&mut self, new_position: Position) {
|
|
|
|
match self {
|
2020-03-18 05:04:26 +01:00
|
|
|
#[cfg(not(feature = "no_std"))]
|
2020-06-17 03:54:17 +02:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2020-05-05 18:09:04 +02:00
|
|
|
Self::ErrorReadingScriptFile(_, pos, _) => *pos = new_position,
|
2020-03-08 15:47:13 +01:00
|
|
|
|
2020-06-12 12:04:16 +02:00
|
|
|
Self::ErrorParsing(_, pos)
|
|
|
|
| Self::ErrorFunctionNotFound(_, pos)
|
2020-05-13 15:58:38 +02:00
|
|
|
| Self::ErrorInFunctionCall(_, _, pos)
|
2020-07-30 17:29:11 +02:00
|
|
|
| Self::ErrorUnboundThis(pos)
|
2020-04-05 06:37:07 +02:00
|
|
|
| Self::ErrorBooleanArgMismatch(_, pos)
|
|
|
|
| Self::ErrorCharMismatch(pos)
|
|
|
|
| Self::ErrorArrayBounds(_, _, pos)
|
|
|
|
| Self::ErrorStringBounds(_, _, pos)
|
|
|
|
| Self::ErrorIndexingType(_, pos)
|
|
|
|
| Self::ErrorNumericIndexExpr(pos)
|
|
|
|
| Self::ErrorStringIndexExpr(pos)
|
2020-05-04 13:36:58 +02:00
|
|
|
| Self::ErrorImportExpr(pos)
|
2020-04-05 06:37:07 +02:00
|
|
|
| Self::ErrorLogicGuard(pos)
|
|
|
|
| Self::ErrorFor(pos)
|
|
|
|
| Self::ErrorVariableNotFound(_, pos)
|
2020-05-04 13:36:58 +02:00
|
|
|
| Self::ErrorModuleNotFound(_, pos)
|
2020-08-02 07:33:51 +02:00
|
|
|
| Self::ErrorDataRace(_, pos)
|
2020-04-05 06:37:07 +02:00
|
|
|
| Self::ErrorAssignmentToUnknownLHS(pos)
|
|
|
|
| Self::ErrorAssignmentToConstant(_, pos)
|
2020-07-03 04:45:01 +02:00
|
|
|
| Self::ErrorMismatchOutputType(_, _, pos)
|
2020-04-06 11:47:34 +02:00
|
|
|
| Self::ErrorInExpr(pos)
|
2020-04-05 06:37:07 +02:00
|
|
|
| Self::ErrorDotExpr(_, pos)
|
|
|
|
| Self::ErrorArithmetic(_, pos)
|
2020-05-15 05:43:32 +02:00
|
|
|
| Self::ErrorTooManyOperations(pos)
|
2020-05-15 15:40:54 +02:00
|
|
|
| Self::ErrorTooManyModules(pos)
|
2020-04-05 06:37:07 +02:00
|
|
|
| Self::ErrorStackOverflow(pos)
|
2020-06-14 08:25:47 +02:00
|
|
|
| Self::ErrorDataTooLarge(_, _, _, pos)
|
2020-05-15 05:43:32 +02:00
|
|
|
| Self::ErrorTerminated(pos)
|
2020-04-05 06:37:07 +02:00
|
|
|
| Self::ErrorRuntime(_, pos)
|
|
|
|
| Self::ErrorLoopBreak(_, pos)
|
|
|
|
| Self::Return(_, pos) => *pos = new_position,
|
2020-03-08 15:47:13 +01:00
|
|
|
}
|
2020-05-13 15:58:38 +02:00
|
|
|
}
|
2020-03-26 13:26:05 +01:00
|
|
|
|
2020-06-01 09:25:22 +02:00
|
|
|
/// Consume the current `EvalAltResult` and return a new one with the specified `Position`
|
|
|
|
/// if the current position is `Position::None`.
|
2020-05-13 15:58:38 +02:00
|
|
|
pub(crate) fn new_position(mut self: Box<Self>, new_position: Position) -> Box<Self> {
|
2020-06-01 09:25:22 +02:00
|
|
|
if self.position().is_none() {
|
|
|
|
self.set_position(new_position);
|
|
|
|
}
|
2020-05-13 15:58:38 +02:00
|
|
|
self
|
2020-03-08 15:47:13 +01:00
|
|
|
}
|
|
|
|
}
|
2020-08-06 04:17:32 +02:00
|
|
|
|
|
|
|
impl<T> From<EvalAltResult> for Result<T, Box<EvalAltResult>> {
|
|
|
|
fn from(err: EvalAltResult) -> Self {
|
|
|
|
Err(err.into())
|
|
|
|
}
|
|
|
|
}
|