forked from AbleScript/ablescript
Obeyed clippy
This commit is contained in:
parent
35ddf85a92
commit
fa63fda7f8
|
@ -10,7 +10,6 @@ pub struct Error {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum ErrorKind {
|
||||
SyntaxError(String),
|
||||
UnexpectedEof,
|
||||
UnexpectedToken(Token),
|
||||
UnknownVariable(String),
|
||||
|
@ -48,7 +47,6 @@ impl std::error::Error for Error {}
|
|||
impl Display for ErrorKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
ErrorKind::SyntaxError(desc) => write!(f, "syntax error: {}", desc),
|
||||
ErrorKind::UnexpectedEof => write!(f, "unexpected end of file"),
|
||||
ErrorKind::UnexpectedToken(token) => write!(f, "unexpected token {:?}", token),
|
||||
ErrorKind::UnknownVariable(name) => write!(f, "unknown identifier \"{}\"", name),
|
||||
|
|
|
@ -138,8 +138,8 @@ impl ExecEnv {
|
|||
|
||||
Ok(match &expr.kind {
|
||||
BinOp { lhs, rhs, kind } => {
|
||||
let lhs = self.eval_expr(&lhs)?;
|
||||
let rhs = self.eval_expr(&rhs)?;
|
||||
let lhs = self.eval_expr(lhs)?;
|
||||
let rhs = self.eval_expr(rhs)?;
|
||||
match kind {
|
||||
// Arithmetic operators.
|
||||
Add | Subtract | Multiply | Divide => {
|
||||
|
@ -193,7 +193,7 @@ impl ExecEnv {
|
|||
}
|
||||
}
|
||||
}
|
||||
Not(expr) => Bool(!self.eval_expr(&expr)?.into_bool()),
|
||||
Not(expr) => Bool(!self.eval_expr(expr)?.into_bool()),
|
||||
Literal(value) => value.clone(),
|
||||
ExprKind::Cart(members) => Value::Cart(
|
||||
members
|
||||
|
@ -268,10 +268,10 @@ impl ExecEnv {
|
|||
}
|
||||
}
|
||||
StmtKind::Call { iden, args } => {
|
||||
let func = self.get_var(&iden)?;
|
||||
let func = self.get_var(iden)?;
|
||||
|
||||
if let Value::Functio(func) = func {
|
||||
self.fn_call(func, &args, &stmt.span)?;
|
||||
self.fn_call(func, args, &stmt.span)?;
|
||||
} else {
|
||||
// Fail silently for now.
|
||||
}
|
||||
|
@ -286,7 +286,7 @@ impl ExecEnv {
|
|||
},
|
||||
StmtKind::Assign { iden, value } => {
|
||||
let value = self.eval_expr(value)?;
|
||||
self.get_var_mut(&iden)?.value.replace(value);
|
||||
self.get_var_mut(iden)?.value.replace(value);
|
||||
}
|
||||
StmtKind::Break => {
|
||||
return Ok(HaltStatus::Break(stmt.span.clone()));
|
||||
|
@ -295,7 +295,7 @@ impl ExecEnv {
|
|||
return Ok(HaltStatus::Hopback(stmt.span.clone()));
|
||||
}
|
||||
StmtKind::Melo(iden) => {
|
||||
self.get_var_mut(&iden)?.melo = true;
|
||||
self.get_var_mut(iden)?.melo = true;
|
||||
}
|
||||
StmtKind::Rlyeh => {
|
||||
// Maybe print a creepy error message or something
|
||||
|
@ -314,7 +314,7 @@ impl ExecEnv {
|
|||
value += self.get_bit()? as i32;
|
||||
}
|
||||
|
||||
self.get_var_mut(&iden)?.value.replace(Value::Int(value));
|
||||
self.get_var_mut(iden)?.value.replace(Value::Int(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ pub fn repl(ast_print: bool) {
|
|||
break;
|
||||
}
|
||||
|
||||
let mut parser = Parser::new(&line);
|
||||
let mut parser = Parser::new(line);
|
||||
let value = parser.init().and_then(|ast| {
|
||||
if ast_print {
|
||||
println!("{:#?}", &ast);
|
||||
|
|
|
@ -122,7 +122,7 @@ impl Value {
|
|||
/// Coerce a Value to a boolean. The conversion cannot fail.
|
||||
pub fn into_bool(&self) -> bool {
|
||||
match self {
|
||||
Value::Abool(b) => b.clone().into(),
|
||||
Value::Abool(b) => (*b).into(),
|
||||
Value::Bool(b) => *b,
|
||||
Value::Functio(_) => true,
|
||||
Value::Int(x) => *x != 0,
|
||||
|
@ -138,13 +138,13 @@ impl Value {
|
|||
Value::Nul => Value::Nul,
|
||||
Value::Str(s) => Value::Int(s.as_bytes()[index.into_i32() as usize] as i32),
|
||||
Value::Int(i) => Value::Int(
|
||||
(format!("{}", i).as_bytes()[index.into_i32() as usize] - ('0' as u8)) as i32,
|
||||
(format!("{}", i).as_bytes()[index.into_i32() as usize] - b'0') as i32,
|
||||
),
|
||||
Value::Bool(b) => Value::Int(
|
||||
format!("{}", b)
|
||||
.chars()
|
||||
.nth(index.into_i32() as usize)
|
||||
.unwrap_or_else(|| '?') as i32,
|
||||
.unwrap_or('?') as i32,
|
||||
),
|
||||
Value::Abool(b) => Value::Int(*b as i32),
|
||||
Value::Functio(_) => Value::Int(42),
|
||||
|
|
Loading…
Reference in a new issue