Obeyed clippy

This commit is contained in:
Erin 2021-07-29 23:22:38 +02:00 committed by ondra05
parent e3cfaaf32c
commit b451503a27
4 changed files with 12 additions and 14 deletions

View file

@ -10,7 +10,6 @@ pub struct Error {
#[derive(Debug)] #[derive(Debug)]
pub enum ErrorKind { pub enum ErrorKind {
SyntaxError(String),
UnexpectedEof, UnexpectedEof,
UnexpectedToken(Token), UnexpectedToken(Token),
UnknownVariable(String), UnknownVariable(String),
@ -48,7 +47,6 @@ impl std::error::Error for Error {}
impl Display for ErrorKind { impl Display for ErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
ErrorKind::SyntaxError(desc) => write!(f, "syntax error: {}", desc),
ErrorKind::UnexpectedEof => write!(f, "unexpected end of file"), ErrorKind::UnexpectedEof => write!(f, "unexpected end of file"),
ErrorKind::UnexpectedToken(token) => write!(f, "unexpected token {:?}", token), ErrorKind::UnexpectedToken(token) => write!(f, "unexpected token {:?}", token),
ErrorKind::UnknownVariable(name) => write!(f, "unknown identifier \"{}\"", name), ErrorKind::UnknownVariable(name) => write!(f, "unknown identifier \"{}\"", name),

View file

@ -138,8 +138,8 @@ impl ExecEnv {
Ok(match &expr.kind { Ok(match &expr.kind {
BinOp { lhs, rhs, kind } => { BinOp { lhs, rhs, kind } => {
let lhs = self.eval_expr(&lhs)?; let lhs = self.eval_expr(lhs)?;
let rhs = self.eval_expr(&rhs)?; let rhs = self.eval_expr(rhs)?;
match kind { match kind {
// Arithmetic operators. // Arithmetic operators.
Add | Subtract | Multiply | Divide => { 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(), Literal(value) => value.clone(),
ExprKind::Cart(members) => Value::Cart( ExprKind::Cart(members) => Value::Cart(
members members
@ -268,10 +268,10 @@ impl ExecEnv {
} }
} }
StmtKind::Call { iden, args } => { StmtKind::Call { iden, args } => {
let func = self.get_var(&iden)?; let func = self.get_var(iden)?;
if let Value::Functio(func) = func { if let Value::Functio(func) = func {
self.fn_call(func, &args, &stmt.span)?; self.fn_call(func, args, &stmt.span)?;
} else { } else {
// Fail silently for now. // Fail silently for now.
} }
@ -286,7 +286,7 @@ impl ExecEnv {
}, },
StmtKind::Assign { iden, value } => { StmtKind::Assign { iden, value } => {
let value = self.eval_expr(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 => { StmtKind::Break => {
return Ok(HaltStatus::Break(stmt.span.clone())); return Ok(HaltStatus::Break(stmt.span.clone()));
@ -295,7 +295,7 @@ impl ExecEnv {
return Ok(HaltStatus::Hopback(stmt.span.clone())); return Ok(HaltStatus::Hopback(stmt.span.clone()));
} }
StmtKind::Melo(iden) => { StmtKind::Melo(iden) => {
self.get_var_mut(&iden)?.melo = true; self.get_var_mut(iden)?.melo = true;
} }
StmtKind::Rlyeh => { StmtKind::Rlyeh => {
// Maybe print a creepy error message or something // Maybe print a creepy error message or something
@ -314,7 +314,7 @@ impl ExecEnv {
value += self.get_bit()? as i32; 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));
} }
} }

View file

@ -21,7 +21,7 @@ pub fn repl(ast_print: bool) {
break; break;
} }
let mut parser = Parser::new(&line); let mut parser = Parser::new(line);
let value = parser.init().and_then(|ast| { let value = parser.init().and_then(|ast| {
if ast_print { if ast_print {
println!("{:#?}", &ast); println!("{:#?}", &ast);

View file

@ -122,7 +122,7 @@ impl Value {
/// Coerce a Value to a boolean. The conversion cannot fail. /// Coerce a Value to a boolean. The conversion cannot fail.
pub fn into_bool(&self) -> bool { pub fn into_bool(&self) -> bool {
match self { match self {
Value::Abool(b) => b.clone().into(), Value::Abool(b) => (*b).into(),
Value::Bool(b) => *b, Value::Bool(b) => *b,
Value::Functio(_) => true, Value::Functio(_) => true,
Value::Int(x) => *x != 0, Value::Int(x) => *x != 0,
@ -138,13 +138,13 @@ impl Value {
Value::Nul => Value::Nul, Value::Nul => Value::Nul,
Value::Str(s) => Value::Int(s.as_bytes()[index.into_i32() as usize] as i32), Value::Str(s) => Value::Int(s.as_bytes()[index.into_i32() as usize] as i32),
Value::Int(i) => Value::Int( 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( Value::Bool(b) => Value::Int(
format!("{}", b) format!("{}", b)
.chars() .chars()
.nth(index.into_i32() as usize) .nth(index.into_i32() as usize)
.unwrap_or_else(|| '?') as i32, .unwrap_or('?') as i32,
), ),
Value::Abool(b) => Value::Int(*b as i32), Value::Abool(b) => Value::Int(*b as i32),
Value::Functio(_) => Value::Int(42), Value::Functio(_) => Value::Int(42),