Minor refactor.
This commit is contained in:
14
src/error.rs
14
src/error.rs
@@ -49,7 +49,7 @@ impl fmt::Display for LexError {
|
||||
"Length of string literal exceeds the maximum limit ({})",
|
||||
max
|
||||
),
|
||||
Self::ImproperSymbol(s) => write!(f, "{}", s),
|
||||
Self::ImproperSymbol(s) => f.write_str(s),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,18 +185,16 @@ impl fmt::Display for ParseErrorType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::BadInput(s) | ParseErrorType::MalformedCallExpr(s) => {
|
||||
write!(f, "{}", if s.is_empty() { self.desc() } else { s })
|
||||
f.write_str(if s.is_empty() { self.desc() } else { s })
|
||||
}
|
||||
Self::ForbiddenConstantExpr(s) => {
|
||||
write!(f, "Expecting a constant to assign to '{}'", s)
|
||||
}
|
||||
Self::UnknownOperator(s) => write!(f, "{}: '{}'", self.desc(), s),
|
||||
|
||||
Self::MalformedIndexExpr(s) => {
|
||||
write!(f, "{}", if s.is_empty() { self.desc() } else { s })
|
||||
}
|
||||
Self::MalformedIndexExpr(s) => f.write_str(if s.is_empty() { self.desc() } else { s }),
|
||||
|
||||
Self::MalformedInExpr(s) => write!(f, "{}", if s.is_empty() { self.desc() } else { s }),
|
||||
Self::MalformedInExpr(s) => f.write_str(if s.is_empty() { self.desc() } else { s }),
|
||||
|
||||
Self::DuplicatedProperty(s) => {
|
||||
write!(f, "Duplicated property '{}' for object map literal", s)
|
||||
@@ -222,12 +220,12 @@ impl fmt::Display for ParseErrorType {
|
||||
|
||||
Self::MissingToken(token, s) => write!(f, "Expecting '{}' {}", token, s),
|
||||
|
||||
Self::AssignmentToConstant(s) if s.is_empty() => write!(f, "{}", self.desc()),
|
||||
Self::AssignmentToConstant(s) if s.is_empty() => f.write_str(self.desc()),
|
||||
Self::AssignmentToConstant(s) => write!(f, "Cannot assign to constant '{}'", s),
|
||||
Self::LiteralTooLarge(typ, max) => {
|
||||
write!(f, "{} exceeds the maximum limit ({})", typ, max)
|
||||
}
|
||||
_ => write!(f, "{}", self.desc()),
|
||||
_ => f.write_str(self.desc()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -876,12 +876,10 @@ impl Module {
|
||||
.functions
|
||||
.iter()
|
||||
.filter(|(_, (_, _, _, v))| match v {
|
||||
CallableFunction::Pure(_)
|
||||
| CallableFunction::Method(_)
|
||||
| CallableFunction::Iterator(_) => true,
|
||||
CallableFunction::Script(ref f) => {
|
||||
filter(f.access, f.name.as_str(), f.params.len())
|
||||
}
|
||||
_ => true,
|
||||
})
|
||||
.map(|(&k, v)| (k, v.clone())),
|
||||
);
|
||||
@@ -897,10 +895,8 @@ impl Module {
|
||||
/// Filter out the functions, retaining only some based on a filter predicate.
|
||||
pub(crate) fn retain_functions(&mut self, filter: impl Fn(FnAccess, &str, usize) -> bool) {
|
||||
self.functions.retain(|_, (_, _, _, v)| match v {
|
||||
CallableFunction::Pure(_)
|
||||
| CallableFunction::Method(_)
|
||||
| CallableFunction::Iterator(_) => true,
|
||||
CallableFunction::Script(ref f) => filter(f.access, f.name.as_str(), f.params.len()),
|
||||
_ => true,
|
||||
});
|
||||
|
||||
self.all_functions.clear();
|
||||
|
@@ -197,16 +197,16 @@ impl fmt::Display for EvalAltResult {
|
||||
| Self::ErrorTooManyOperations(_)
|
||||
| Self::ErrorTooManyModules(_)
|
||||
| Self::ErrorStackOverflow(_)
|
||||
| Self::ErrorTerminated(_) => write!(f, "{}", desc)?,
|
||||
| Self::ErrorTerminated(_) => f.write_str(desc)?,
|
||||
|
||||
Self::ErrorRuntime(s, _) => write!(f, "{}", if s.is_empty() { desc } else { s })?,
|
||||
Self::ErrorRuntime(s, _) => f.write_str(if s.is_empty() { desc } else { s })?,
|
||||
|
||||
Self::ErrorAssignmentToConstant(s, _) => write!(f, "{}: '{}'", desc, s)?,
|
||||
Self::ErrorMismatchOutputType(s, _) => write!(f, "{}: {}", desc, s)?,
|
||||
Self::ErrorArithmetic(s, _) => write!(f, "{}", s)?,
|
||||
Self::ErrorArithmetic(s, _) => f.write_str(s)?,
|
||||
|
||||
Self::ErrorLoopBreak(_, _) => write!(f, "{}", desc)?,
|
||||
Self::Return(_, _) => write!(f, "{}", desc)?,
|
||||
Self::ErrorLoopBreak(_, _) => f.write_str(desc)?,
|
||||
Self::Return(_, _) => f.write_str(desc)?,
|
||||
|
||||
Self::ErrorBooleanArgMismatch(op, _) => {
|
||||
write!(f, "{} operator expects boolean operands", op)?
|
||||
@@ -215,7 +215,7 @@ impl fmt::Display for EvalAltResult {
|
||||
Self::ErrorArrayBounds(_, index, _) if *index < 0 => {
|
||||
write!(f, "{}: {} < 0", desc, index)?
|
||||
}
|
||||
Self::ErrorArrayBounds(0, _, _) => write!(f, "{}", desc)?,
|
||||
Self::ErrorArrayBounds(0, _, _) => f.write_str(desc)?,
|
||||
Self::ErrorArrayBounds(1, index, _) => write!(
|
||||
f,
|
||||
"Array index {} is out of bounds: only one element in the array",
|
||||
@@ -229,7 +229,7 @@ impl fmt::Display for EvalAltResult {
|
||||
Self::ErrorStringBounds(_, index, _) if *index < 0 => {
|
||||
write!(f, "{}: {} < 0", desc, index)?
|
||||
}
|
||||
Self::ErrorStringBounds(0, _, _) => write!(f, "{}", desc)?,
|
||||
Self::ErrorStringBounds(0, _, _) => f.write_str(desc)?,
|
||||
Self::ErrorStringBounds(1, index, _) => write!(
|
||||
f,
|
||||
"String index {} is out of bounds: only one character in the string",
|
||||
|
Reference in New Issue
Block a user