From c84c38544bc6e81f0b0482e4e82b6c95848c1a0c Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 6 Apr 2021 14:54:54 +0530 Subject: apply clippy lints --- src/app.rs | 101 ++++++++++++++++----------------- src/bitmap.rs | 22 ++------ src/brush.rs | 4 +- src/cli.rs | 32 +++++------ src/command.rs | 8 ++- src/consts.rs | 6 +- src/dither.rs | 40 ++++++------- src/guide.rs | 16 +----- src/lisp/eval.rs | 55 +++++++++--------- src/lisp/expr.rs | 46 +++++++++++---- src/lisp/lex.rs | 25 ++++----- src/lisp/number.rs | 6 +- src/lisp/parse.rs | 159 +++++++++++++++++++++++++--------------------------- src/lisp/prelude.rs | 122 ++++++++++++++++++++-------------------- src/main.rs | 8 +-- src/message.rs | 20 ++++--- src/undo.rs | 16 +++++- src/utils.rs | 6 +- 18 files changed, 344 insertions(+), 348 deletions(-) (limited to 'src') diff --git a/src/app.rs b/src/app.rs index 33d4934..f42b48c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -108,10 +108,10 @@ impl<'ctx> AppState<'ctx> { let y_min = self.start.y(); let x_max = self.start.x() + (self.width() * self.zoom as u32) as i32; let y_max = self.start.y() + (self.height() * self.zoom as u32) as i32; - return ( + ( Point::new(x_min, y_min), Point::new(x_max as i32, y_max as i32), - ); + ) } pub fn change_active_color(&mut self) { @@ -125,7 +125,7 @@ impl<'ctx> AppState<'ctx> { let rel_p = p - self.start; // reduce p based on zoom and cell size let (sx, sy) = (rel_p.x() / self.zoom as i32, rel_p.y() / self.zoom as i32); - return Some((sx as u32, sy as u32)); + Some((sx as u32, sy as u32)) } else { None } @@ -254,7 +254,7 @@ impl<'ctx> AppState<'ctx> { let op = self .current_operation .drain(..) - .filter(|v| !v.old == v.new) + .filter(|v| v.old != v.new) .collect::>(); self.undo_stack.push(ModifyRecord::Paint(op)); } @@ -267,7 +267,7 @@ impl<'ctx> AppState<'ctx> { let (x2, y2) = (p.0 * (1 + self.zoom as u32), p.1 * (1 + self.zoom as u32)); let diffx = x2 as i32 - x1 as i32; let diffy = y2 as i32 - y1 as i32; - self.start = self.start - Point::from((diffx, diffy)); + self.start -= Point::from((diffx, diffy)); } self.zoom += 1; } @@ -280,7 +280,7 @@ impl<'ctx> AppState<'ctx> { let (x2, y2) = (p.0 * (self.zoom as u32 - 1), p.1 * (self.zoom as u32 - 1)); let diffx = x2 as i32 - x1 as i32; let diffy = y2 as i32 - y1 as i32; - self.start = self.start - Point::from((diffx, diffy)); + self.start -= Point::from((diffx, diffy)); } self.zoom -= 1; } @@ -310,7 +310,7 @@ impl<'ctx> AppState<'ctx> { pub fn eval_command(&mut self) { let lisp_expr = &self.command_box.text; - let mut parser = Parser::new(Lexer::new(lisp_expr, 0)); + let mut parser = Parser::new(Lexer::new(lisp_expr)); let res = parser.parse_single_expr(); match res { Ok(expr) => { @@ -393,7 +393,7 @@ impl<'ctx> AppState<'ctx> { let mouse_coords = if let Some((x, y)) = self.idx_at_coord(self.mouse) { format!("{:3}, {:3}", x + 1, y + 1) } else { - format!("---, ---") + String::from("---, ---") }; let status_text = format!( "{} [PT {}][KIND {}]", @@ -478,32 +478,29 @@ impl<'ctx> AppState<'ctx> { } } } - match self.brush { - Brush::Line(LineBrush { start, size, .. }) => { - let size = self.zoom as u32 * (size as u32 + 5); - if let (Some(from), Some(to)) = (start, pt) { - let line = self.pixmap.get_line(from, to.into()); - draw_text( - &mut self.canvas, - self.ttf_context, - format!("{}°", positive_angle_with_x(from, to.into())), - PINK, - (self.mouse.0 + size as i32, self.mouse.1 + size as i32), - ); - for MapPoint { x, y } in line.into_iter() { - self.canvas.set_draw_color(PINK); - self.canvas - .fill_rect(Rect::new( - x as i32 * cs as i32 + self.start.x(), - y as i32 * cs as i32 + self.start.y(), - cs, - cs, - )) - .unwrap(); - } + if let Brush::Line(LineBrush { start, size, .. }) = self.brush { + let size = self.zoom as u32 * (size as u32 + 5); + if let (Some(from), Some(to)) = (start, pt) { + let line = self.pixmap.get_line(from, to.into()); + draw_text( + &mut self.canvas, + self.ttf_context, + format!("{}°", positive_angle_with_x(from, to.into())), + PINK, + (self.mouse.0 + size as i32, self.mouse.1 + size as i32), + ); + for MapPoint { x, y } in line.into_iter() { + self.canvas.set_draw_color(PINK); + self.canvas + .fill_rect(Rect::new( + x as i32 * cs as i32 + self.start.x(), + y as i32 * cs as i32 + self.start.y(), + cs, + cs, + )) + .unwrap(); } } - _ => {} } } @@ -530,14 +527,12 @@ impl<'ctx> AppState<'ctx> { fn draw_symmetry(&mut self) { let Symmetry { x, y } = self.symmetry; - x.and_then(|line| { - self.draw_line_to_grid(line, Axis::X, CYAN); - Some(()) - }); - y.and_then(|line| { - self.draw_line_to_grid(line, Axis::Y, CYAN); - Some(()) - }); + if let Some(line) = x { + self.draw_line_to_grid(line, Axis::X, CYAN) + } + if let Some(line) = y { + self.draw_line_to_grid(line, Axis::Y, CYAN) + } } fn draw_guides(&mut self) { @@ -626,7 +621,7 @@ impl<'ctx> AppState<'ctx> { .build() .map_err(|e| AppError::Sdl(e.to_string()))?; - let data = start_data.unwrap_or(vec![false; (width * height) as usize]); + let data = start_data.unwrap_or_else(|| vec![false; (width * height) as usize]); let pixmap = Pixmap::new_with(width, height, data); let mut app = Self { active_color: true, @@ -668,7 +663,7 @@ impl<'ctx> AppState<'ctx> { let image = self.export().encode().unwrap(); let mut file = File::create(file_name).map_err(AppError::File)?; file.write_all(&image[..]).map_err(AppError::File)?; - return Ok(()); + Ok(()) } pub fn run(&mut self) { @@ -799,21 +794,21 @@ impl<'ctx> AppState<'ctx> { start, extend, }) => { - if start.is_none() { + if let Some(s) = start { + if let Ok(o) = self.paint_line(s, pt, val, size) { + self.current_operation.extend(o); + self.brush = Brush::Line(LineBrush { + size, + start: if extend { contact } else { None }, + extend, + }); + } + } else { self.brush = Brush::Line(LineBrush { size, start: contact, extend, }); - } else if let Ok(o) = - self.paint_line(start.unwrap(), pt, val, size) - { - self.current_operation.extend(o); - self.brush = Brush::Line(LineBrush { - size, - start: if extend { contact } else { None }, - extend, - }); } } Brush::Fill => { @@ -827,7 +822,7 @@ impl<'ctx> AppState<'ctx> { for o in operation.iter() { // this `set` is unchecked because the returned // value of flood_fill is checked to be within pixmap - self.pixmap.set(o.clone(), replacement); + self.pixmap.set(*o, replacement); } self.current_operation.extend( operation diff --git a/src/bitmap.rs b/src/bitmap.rs index 8010a4b..2f96a99 100644 --- a/src/bitmap.rs +++ b/src/bitmap.rs @@ -29,7 +29,7 @@ impl TryFrom<(i32, i32)> for MapPoint { type Error = (); fn try_from((x, y): (i32, i32)) -> Result { if x < 0 || y < 0 { - return Err(()); + Err(()) } else { Ok(MapPoint { x: x as u32, @@ -43,7 +43,7 @@ impl TryFrom<(i64, i64)> for MapPoint { type Error = (); fn try_from((x, y): (i64, i64)) -> Result { if x < 0 || y < 0 { - return Err(()); + Err(()) } else { Ok(MapPoint { x: x as u32, @@ -79,18 +79,6 @@ pub enum Axis { Y, } -impl Into for Axis { - fn into(self) -> LispExpr { - LispExpr::Quote( - Box::new(LispExpr::Ident(match self { - Self::X => "X".into(), - Self::Y => "Y".into(), - })), - 1, - ) - } -} - impl TryFrom<&LispExpr> for Axis { type Error = EvalError; fn try_from(value: &LispExpr) -> Result { @@ -224,7 +212,7 @@ where circle.extend((x - dy.abs() + 1..x + dy.abs()).map(|x| (x, y + dx))); circle.extend((x - dy.abs() + 1..x + dy.abs()).map(|x| (x, y - dx))); } - dy = dy + 1; + dy += 1; if err < 0 { err = err + 2 * dy + 1; } else { @@ -234,7 +222,7 @@ where } circle .into_iter() - .flat_map(|pt| MapPoint::try_from(pt)) + .flat_map(MapPoint::try_from) .filter(|&pt| self.contains(pt)) .collect() } @@ -279,7 +267,7 @@ where } coordinates .into_iter() - .flat_map(|pt| MapPoint::try_from(pt)) + .flat_map(MapPoint::try_from) .filter(|&pt| self.contains(pt)) .collect() } diff --git a/src/brush.rs b/src/brush.rs index 8ff0cda..8557ba7 100644 --- a/src/brush.rs +++ b/src/brush.rs @@ -66,8 +66,8 @@ impl Brush { pub fn size(&self) -> Option { match self { - Brush::Line(LineBrush { size, .. }) => Some(size.clone()), - Brush::Circle(CircleBrush { size }) => Some(size.clone()), + Brush::Line(LineBrush { size, .. }) => Some(*size), + Brush::Circle(CircleBrush { size }) => Some(*size), _ => None, } } diff --git a/src/cli.rs b/src/cli.rs index 1dbd098..6357355 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -4,7 +4,7 @@ use std::{ path::{Path, PathBuf}, }; -pub static HELP_TEXT: &'static str = " +pub static HELP_TEXT: &str = " Usage ----- @@ -83,11 +83,11 @@ pub fn parse_args() -> Result { if !Path::new(s).is_file() { return Err(CliError::FileDoesNotExist); } - return Ok(Config::ExistingProject { + Ok(Config::ExistingProject { file_name: PathBuf::from(s), - }); + }) } - None => return Ok(Config::Help), + None => Ok(Config::Help), }, _ => Err(CliError::SubCommandParseError), } @@ -104,25 +104,23 @@ fn new_project(args: &mut pico_args::Arguments) -> Result { .opt_value_from_fn(["-d", "--dimensions"], parse_dimensions) .map_err(|_| CliError::DimensionParseError)? .unwrap_or((200, 200)); - return Ok(Config::NewProject { + Ok(Config::NewProject { file_name: file_name.ok(), dimensions, - }); + }) } fn parse_dimensions(input: &str) -> Result<(u32, u32), CliError> { let dimensions: Vec<&str> = input.split('x').collect(); match &dimensions[..] { - [width, height] => { - return Ok(( - width - .parse::() - .map_err(|_| CliError::DimensionParseError)?, - height - .parse::() - .map_err(|_| CliError::DimensionParseError)?, - )) - } - _ => return Err(CliError::DimensionParseError), + [width, height] => Ok(( + width + .parse::() + .map_err(|_| CliError::DimensionParseError)?, + height + .parse::() + .map_err(|_| CliError::DimensionParseError)?, + )), + _ => Err(CliError::DimensionParseError), } } diff --git a/src/command.rs b/src/command.rs index 383389e..52ff7c8 100644 --- a/src/command.rs +++ b/src/command.rs @@ -111,7 +111,7 @@ impl CommandBox { return; } if let Some(idx) = self.hist_idx { - if !(idx + 1 >= self.history.items.len()) { + if idx + 1 < self.history.items.len() { self.hist_idx = Some(idx + 1); self.text = self.get_from_hist(); self.cursor_end(); @@ -138,6 +138,12 @@ impl CommandBox { } } +impl std::default::Default for CommandBox { + fn default() -> Self { + CommandBox::new() + } +} + #[derive(Debug)] pub struct History { pub items: Vec, diff --git a/src/consts.rs b/src/consts.rs index 3f9ecb9..0b43f0a 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -8,6 +8,6 @@ pub mod colors { pub const PINK: Color = Color::RGB(255, 50, 153); } -pub const FONT_PATH: &'static str = "./assets/NerdInput-Regular.ttf"; -pub const STDLIB_PATH: &'static str = "./src/lisp/std.lisp"; -pub const RC_PATH: &'static str = "/home/np/.config/sdl-tests"; +pub const FONT_PATH: &str = "./assets/NerdInput-Regular.ttf"; +pub const STDLIB_PATH: &str = "./src/lisp/std.lisp"; +pub const RC_PATH: &str = "/home/np/.config/sdl-tests"; diff --git a/src/dither.rs b/src/dither.rs index 99e2839..25c59c8 100644 --- a/src/dither.rs +++ b/src/dither.rs @@ -26,16 +26,16 @@ pub fn bayer(level: u8, pt: MapPoint) -> bool { let MapPoint { x, y } = pt; let r = (x % 4, y % 4); match level { - 01 => r == (0, 0) || bayer(00, pt), - 02 => r == (2, 2) || bayer(01, pt), - 03 => r == (0, 2) || bayer(02, pt), - 04 => r == (2, 0) || bayer(03, pt), - 05 => r == (1, 1) || bayer(04, pt), - 06 => r == (3, 3) || bayer(05, pt), - 07 => r == (1, 3) || bayer(06, pt), - 08 => r == (3, 1) || bayer(07, pt), - 09 => r == (0, 1) || bayer(08, pt), - 10 => r == (0, 3) || bayer(09, pt), + 1 => r == (0, 0) || bayer(0, pt), + 2 => r == (2, 2) || bayer(1, pt), + 3 => r == (0, 2) || bayer(2, pt), + 4 => r == (2, 0) || bayer(3, pt), + 5 => r == (1, 1) || bayer(4, pt), + 6 => r == (3, 3) || bayer(5, pt), + 7 => r == (1, 3) || bayer(6, pt), + 8 => r == (3, 1) || bayer(7, pt), + 9 => r == (0, 1) || bayer(8, pt), + 10 => r == (0, 3) || bayer(9, pt), 11 => r == (2, 3) || bayer(10, pt), 12 => r == (2, 1) || bayer(11, pt), 13 => r == (1, 0) || bayer(12, pt), @@ -73,16 +73,16 @@ pub fn rylander(level: u8, pt: MapPoint) -> bool { let MapPoint { x, y } = pt; let r = (x % 4, y % 4); match level { - 01 => r == (1, 3) || rylander(00, pt), - 02 => r == (3, 1) || rylander(01, pt), - 03 => r == (3, 3) || rylander(02, pt), - 04 => r == (1, 1) || rylander(03, pt), - 05 => r == (1, 2) || rylander(04, pt), - 06 => r == (3, 0) || rylander(05, pt), - 07 => r == (3, 2) || rylander(06, pt), - 08 => r == (1, 0) || rylander(07, pt), - 09 => r == (0, 3) || rylander(08, pt), - 10 => r == (2, 1) || rylander(09, pt), + 1 => r == (1, 3) || rylander(0, pt), + 2 => r == (3, 1) || rylander(1, pt), + 3 => r == (3, 3) || rylander(2, pt), + 4 => r == (1, 1) || rylander(3, pt), + 5 => r == (1, 2) || rylander(4, pt), + 6 => r == (3, 0) || rylander(5, pt), + 7 => r == (3, 2) || rylander(6, pt), + 8 => r == (1, 0) || rylander(7, pt), + 9 => r == (0, 3) || rylander(8, pt), + 10 => r == (2, 1) || rylander(9, pt), 11 => r == (2, 3) || rylander(10, pt), 12 => r == (0, 1) || rylander(11, pt), 13 => r == (0, 2) || rylander(12, pt), diff --git a/src/guide.rs b/src/guide.rs index 85d0594..0416e5c 100644 --- a/src/guide.rs +++ b/src/guide.rs @@ -1,21 +1,7 @@ -use crate::{ - bitmap::Axis, - lisp::{expr::LispExpr, number::LispNumber}, -}; - -use std::convert::Into; +use crate::bitmap::Axis; #[derive(Debug, Hash, PartialEq, Eq, Copy, Clone)] pub struct Guide { pub axis: Axis, pub offset: u32, } - -impl Into for Guide { - fn into(self) -> LispExpr { - LispExpr::List(vec![ - self.axis.into(), - LispExpr::Number(LispNumber::Integer(self.offset as i64)), - ]) - } -} diff --git a/src/lisp/eval.rs b/src/lisp/eval.rs index 9276ef5..329b6ab 100644 --- a/src/lisp/eval.rs +++ b/src/lisp/eval.rs @@ -76,7 +76,7 @@ where self.eval(&LispExpr::List(f.body.clone())) }; self.app.lisp_env.pop(); - return result; + result } } LispExpr::List(_) => { @@ -108,7 +108,7 @@ where error!("Unable to create global definition"); return Err(EvalError::BadForm.into()); } - return Ok(LispExpr::Unit); + Ok(LispExpr::Unit) } [LispExpr::List(shorthand), LispExpr::List(body)] => { // (define (func arg) ) shorthand @@ -130,12 +130,12 @@ where let local_env = &mut self.app.lisp_env.last_mut(); if let Some(env) = local_env { - env.insert(id.into(), value); + env.insert(id, value); } else { error!("Unable to create global definition"); return Err(EvalError::BadForm.into()); } - return Ok(LispExpr::Unit); + Ok(LispExpr::Unit) } _ => { error!("Invalid usage of `define`"); @@ -154,17 +154,16 @@ where let value = self.eval(&expr)?; let local_env = self.app.lisp_env.last_mut(); if let Some(env) = local_env { - return env - .insert(id.into(), value) - .ok_or(EvalError::UnboundVariable(id.into()).into()); + env.insert(id.into(), value) + .ok_or_else(|| EvalError::UnboundVariable(id.into()).into()) } else { error!("Unable to set in global env!"); - return Err(EvalError::BadForm.into()); + Err(EvalError::BadForm.into()) } } _ => { error!("Invalid usage of `set!`"); - return Err(EvalError::BadForm.into()); + Err(EvalError::BadForm.into()) } } } @@ -172,15 +171,15 @@ where pub fn eval_if(&mut self, args: &[LispExpr]) -> Result { let arity = Arity::Exact(3); if !arity.check(args) { - return Err(arity.to_error()); + Err(arity.to_error()) } else { match args { [predicate, then, else_] => { let predicate = self.eval(&predicate)?; if matches!(predicate, LispExpr::BoolLit(false)) { - return self.eval(&else_); + self.eval(&else_) } else { - return self.eval(&then); + self.eval(&then) } } _ => { @@ -194,7 +193,7 @@ where let arity = Arity::Atleast(1); let valid_cond_stmt = |expr: &LispExpr| matches!(expr, LispExpr::List(v) if v.len() == 2); if !arity.check(args) { - return Err(arity.to_error()); + Err(arity.to_error()) } else { for cond_stmt in args { if valid_cond_stmt(cond_stmt) { @@ -211,7 +210,7 @@ where return Err(EvalError::BadForm.into()); } } - return Ok(LispExpr::Unit); + Ok(LispExpr::Unit) } } @@ -220,7 +219,7 @@ where let valid_binding_stmt = |expr: &LispExpr| matches!(expr, LispExpr::List(v) if v.len() == 2); if !arity.check(args) { - return Err(arity.to_error()); + Err(arity.to_error()) } else { let nested_env = Environment::new(); self.app.lisp_env.push(nested_env); @@ -247,11 +246,11 @@ where } let result = self.eval(&body); self.app.lisp_env.pop(); - return result; + result } _ => { error!("bad `let` form"); - return Err(EvalError::BadForm.into()); + Err(EvalError::BadForm.into()) } } } @@ -277,32 +276,28 @@ pub fn create_lambda(cdr: &[LispExpr]) -> Result { return Err(arity.to_error()); } match cdr { - [LispExpr::List(params), LispExpr::List(body)] if type_match!(params, (..) => LispExpr::Ident(_)) => - { - return Ok(LispExpr::Function(LispFunction { - params: params - .into_iter() - .map(|p| p.unwrap_ident()) - .collect::>(), + [LispExpr::List(params), LispExpr::List(body)] if type_match!(params, (..) => LispExpr::Ident(_)) => { + Ok(LispExpr::Function(LispFunction { + params: params.iter().map(|p| p.unwrap_ident()).collect::>(), body: body.clone(), - })); + })) } _ => { error!("Invalid usage of `lambda`"); - return Err(EvalError::BadForm.into()); + Err(EvalError::BadForm.into()) } } } pub fn lookup(env_list: &[Environment], key: &str) -> Result { if env_list.is_empty() { - return Err(EvalError::UnboundVariable(key.into()).into()); + Err(EvalError::UnboundVariable(key.into()).into()) } else { let local_env = env_list.last().unwrap(); if let Some(val) = local_env.get(key) { - return Ok(val.clone()); + Ok(val.clone()) } else { - return lookup(&env_list[..env_list.len() - 1], key); + lookup(&env_list[..env_list.len() - 1], key) } } } @@ -314,7 +309,7 @@ mod tests { use crate::lisp::{expr::LispExpr, lex::Lexer, number::LispNumber, parse::Parser}; fn run(code: &str, app: &mut AppState) -> LispExpr { - let mut parser = Parser::new(Lexer::new(code, 0)); + let mut parser = Parser::new(Lexer::new(code)); let mut evaluator = Evaluator { app, context: Vec::new(), diff --git a/src/lisp/expr.rs b/src/lisp/expr.rs index d2066e7..692f951 100644 --- a/src/lisp/expr.rs +++ b/src/lisp/expr.rs @@ -1,12 +1,18 @@ -use std::{cmp::PartialEq, convert::TryFrom, fmt}; +use std::{ + cmp::PartialEq, + convert::{From, TryFrom}, + fmt, +}; use crate::{ app::AppState, + bitmap::Axis, + guide::Guide, lisp::{ error::{EvalError, LispError}, eval::lookup, number::LispNumber, - EnvList, + Environment, }, }; @@ -113,7 +119,7 @@ impl LispExpr { } } - pub fn compare(&self, other: &Self, envs: &EnvList) -> Result { + pub fn compare(&self, other: &Self, envs: &[Environment]) -> Result { match (self, other) { (LispExpr::Unit, LispExpr::Unit) => Ok(true), (LispExpr::Number(s), LispExpr::Number(o)) => Ok(s == o), @@ -121,8 +127,8 @@ impl LispExpr { .iter() .zip(o) .all(|(a, b)| matches!(a.compare(b, envs), Ok(true)))), - (LispExpr::List(s), LispExpr::Unit) => Ok(s.len() == 0), - (LispExpr::Unit, LispExpr::List(s)) => Ok(s.len() == 0), + (LispExpr::List(s), LispExpr::Unit) => Ok(s.is_empty()), + (LispExpr::Unit, LispExpr::List(s)) => Ok(s.is_empty()), (LispExpr::StringLit(s), LispExpr::StringLit(o)) => Ok(s == o), (LispExpr::Char(s), LispExpr::Char(o)) => Ok(s == o), (LispExpr::BoolLit(s), LispExpr::BoolLit(o)) => Ok(s == o), @@ -152,7 +158,7 @@ impl LispExpr { // have these be code gen'd somehow pub fn unwrap_number(&self) -> LispNumber { match &self { - LispExpr::Number(p) => p.clone(), + LispExpr::Number(p) => *p, _ => panic!("attempt to call `unwrap_number` on invalid type"), } } @@ -200,10 +206,7 @@ impl LispExpr { } pub fn cast_bool(&self) -> bool { - match &self { - LispExpr::BoolLit(false) => false, - _ => true, - } + !matches!(self, LispExpr::BoolLit(false)) } } @@ -347,3 +350,26 @@ impl TryFrom for BoolLit { } } } + +// conversion implementations + +impl From for LispExpr { + fn from(axis: Axis) -> LispExpr { + LispExpr::Quote( + Box::new(LispExpr::Ident(match axis { + Axis::X => "X".into(), + Axis::Y => "Y".into(), + })), + 1, + ) + } +} + +impl From for LispExpr { + fn from(guide: Guide) -> LispExpr { + LispExpr::List(vec![ + guide.axis.into(), + LispExpr::Number(LispNumber::Integer(guide.offset as i64)), + ]) + } +} diff --git a/src/lisp/lex.rs b/src/lisp/lex.rs index 2088421..754a23f 100644 --- a/src/lisp/lex.rs +++ b/src/lisp/lex.rs @@ -102,16 +102,11 @@ impl<'src, 'file> SpanDisplay<'src, 'file> { pub struct Lexer<'input> { input: &'input str, cur_pos: u32, - offset: u32, } impl<'a> Lexer<'a> { - pub fn new(input: &'a str, offset: u32) -> Self { - Self { - input, - cur_pos: 0, - offset, - } + pub fn new(input: &'a str) -> Self { + Self { input, cur_pos: 0 } } pub fn next_token(&mut self) -> Result<(Span, Token<'a>), ParseError> { @@ -166,11 +161,11 @@ impl<'a> Lexer<'a> { return Ok((sp, token)); } self.input = &self.input[..0]; - return Ok((Span::empty(self.cur_pos), Token::End)); + Ok((Span::empty(self.cur_pos), Token::End)) } } -fn parse_number<'a>(mut input: &'a str) -> Result<(usize, Token<'a>), ParseErrorKind> { +fn parse_number(mut input: &str) -> Result<(usize, Token<'_>), ParseErrorKind> { let mut dot = false; let mut minus = false; let mut size = 0; @@ -186,7 +181,7 @@ fn parse_number<'a>(mut input: &'a str) -> Result<(usize, Token<'a>), ParseError } } - while let Some(chr) = chars.next() { + for chr in chars { if chr.is_digit(10) { size += 1; } else if chr == '.' { @@ -210,10 +205,10 @@ fn parse_number<'a>(mut input: &'a str) -> Result<(usize, Token<'a>), ParseError } else { Token::Integer(&input[..size]) }; - return Ok((size, tok)); + Ok((size, tok)) } -fn parse_string<'a>(input: &'a str) -> Result<(usize, Token<'a>), ParseErrorKind> { +fn parse_string(input: &str) -> Result<(usize, Token<'_>), ParseErrorKind> { // count opening quote let mut size = 1; let mut closed = false; @@ -260,7 +255,7 @@ fn consume_comment(start: usize, chars: &mut CharIndices) -> usize { last - start + 1 } -fn parse_name<'a>(input: &'a str) -> Result<(usize, Token<'a>), ParseErrorKind> { +fn parse_name(input: &str) -> Result<(usize, Token<'_>), ParseErrorKind> { for (ind, chr) in input.char_indices() { if !is_ident(chr) { return Ok((ind, Token::Name(&input[..ind]))); @@ -269,7 +264,7 @@ fn parse_name<'a>(input: &'a str) -> Result<(usize, Token<'a>), ParseErrorKind> return Ok((input.len(), Token::Name(input))); } -fn parse_char<'a>(input: &'a str) -> Result<(usize, Token<'a>), ParseErrorKind> { +fn parse_char(input: &str) -> Result<(usize, Token<'_>), ParseErrorKind> { // first two chars of input are '#' and '\' let chr = &input[..3]; return Ok((chr.len(), Token::Char(chr))); @@ -284,7 +279,7 @@ mod tests { } fn tokens(input: &str) -> Vec<(Span, Token)> { - let mut lexer = Lexer::new(input, 0); + let mut lexer = Lexer::new(input); let mut tokens = Vec::new(); loop { match lexer.next_token().unwrap() { diff --git a/src/lisp/number.rs b/src/lisp/number.rs index 4ca890a..4824e21 100644 --- a/src/lisp/number.rs +++ b/src/lisp/number.rs @@ -16,14 +16,14 @@ impl LispNumber { pub fn div(self, rhs: Self) -> Result { use LispNumber::*; if rhs == Integer(0) || rhs == Float(0.) { - return Err(EvalError::DivByZero.into()); + Err(EvalError::DivByZero.into()) } else { - return Ok(match (self, rhs) { + Ok(match (self, rhs) { (Integer(a), Integer(b)) => Float(a as f64 / b as f64), (Float(a), Integer(b)) => Float(a / b as f64), (Integer(a), Float(b)) => Float(a as f64 / b), (Float(a), Float(b)) => Float(a / b), - }); + }) } } pub fn unwrap_integer(self) -> i64 { diff --git a/src/lisp/parse.rs b/src/lisp/parse.rs index 737e7ad..8aeb672 100644 --- a/src/lisp/parse.rs +++ b/src/lisp/parse.rs @@ -1,5 +1,5 @@ use crate::lisp::{ - error::{LispError, ParseError, ParseErrorKind}, + error::{ParseError, ParseErrorKind}, lex::{Lexer, Span, Token}, number::LispNumber, LispExpr, @@ -30,97 +30,91 @@ impl<'lex> Parser<'lex> { let mut total_backticks = 0; loop { let (span, token) = self.next()?; - let r: Result = match token { - Token::LeftParen => { - stack.push(Group::Parens(Vec::new())); - continue; - } - Token::RightParen => { - let group = stack - .pop() - .ok_or_else(|| (ParseError::new(span, ParseErrorKind::UnmatchedParen)))?; - match group { - Group::Parens(v) => { - if v.len() == 0 { - Ok(LispExpr::Unit) - } else { - Ok(LispExpr::List(v)) + let r: Result = + match token { + Token::LeftParen => { + stack.push(Group::Parens(Vec::new())); + continue; + } + Token::RightParen => { + let group = stack + .pop() + .ok_or_else(|| ParseError::new(span, ParseErrorKind::UnmatchedParen))?; + match group { + Group::Parens(v) => { + if v.is_empty() { + Ok(LispExpr::Unit) + } else { + Ok(LispExpr::List(v)) + } } + _ => Err(ParseError::new( + span, + ParseErrorKind::UnexpectedToken { + expected: "expression", + found: "(", + }, + )), } - _ => Err(From::from(ParseError::new( - span, - ParseErrorKind::UnexpectedToken { - expected: "expression", - found: "(", - }, - ))), } - } - Token::Float(f) => f - .parse::() - .map(|n| LispExpr::Number(LispNumber::Float(n))) - .map_err(|_| ParseError::new(span, ParseErrorKind::LiteralParseError).into()), - Token::Integer(i) => i - .parse::() - .map(|n| LispExpr::Number(LispNumber::Integer(n))) - .map_err(|_| ParseError::new(span, ParseErrorKind::LiteralParseError).into()), - Token::String(s) => Ok(LispExpr::StringLit(s[1..s.len() - 1].into())), - Token::Char(s) => { - Ok(LispExpr::Char(s.chars().nth(2).ok_or_else(|| { + Token::Float(f) => f + .parse::() + .map(|n| LispExpr::Number(LispNumber::Float(n))) + .map_err(|_| ParseError::new(span, ParseErrorKind::LiteralParseError)), + Token::Integer(i) => i + .parse::() + .map(|n| LispExpr::Number(LispNumber::Integer(n))) + .map_err(|_| ParseError::new(span, ParseErrorKind::LiteralParseError)), + Token::String(s) => Ok(LispExpr::StringLit(s[1..s.len() - 1].into())), + Token::Char(s) => Ok(LispExpr::Char(s.chars().nth(2).ok_or_else(|| { ParseError::new(span, ParseErrorKind::LiteralParseError) - })?)) - } - Token::Name(n) => Ok(name_expr(n)), - Token::BackQuote => { - total_backticks += 1; - if let Some(&mut Group::Backticks(ref mut n)) = stack.last_mut() { - *n += 1; + })?)), + Token::Name(n) => Ok(name_expr(n)), + Token::BackQuote => { + total_backticks += 1; + if let Some(&mut Group::Backticks(ref mut n)) = stack.last_mut() { + *n += 1; + continue; + } + stack.push(Group::Backticks(1)); continue; } - stack.push(Group::Backticks(1)); - continue; - } - Token::Comma => { - if total_backticks <= 0 { - return Err(ParseError::new(span, ParseErrorKind::UnbalancedComma)); - } - total_backticks -= 1; - if let Some(&mut Group::Backticks(ref mut n)) = stack.last_mut() { - *n -= 1; + Token::Comma => { + if total_backticks <= 0 { + return Err(ParseError::new(span, ParseErrorKind::UnbalancedComma)); + } + total_backticks -= 1; + if let Some(&mut Group::Backticks(ref mut n)) = stack.last_mut() { + *n -= 1; + continue; + } + stack.push(Group::Backticks(-1)); continue; } - stack.push(Group::Backticks(-1)); - continue; - } - Token::CommaAt => { - if total_backticks <= 0 { - return Err(ParseError::new(span, ParseErrorKind::UnbalancedComma)); + Token::CommaAt => { + if total_backticks <= 0 { + return Err(ParseError::new(span, ParseErrorKind::UnbalancedComma)); + } + total_backticks -= 1; + stack.push(Group::CommaAt); + continue; } - total_backticks -= 1; - stack.push(Group::CommaAt); - continue; - } - Token::Quote => { - if let Some(&mut Group::Quotes(ref mut n)) = stack.last_mut() { - *n += 1; + Token::Quote => { + if let Some(&mut Group::Quotes(ref mut n)) = stack.last_mut() { + *n += 1; + continue; + } + stack.push(Group::Quotes(1)); continue; } - stack.push(Group::Quotes(1)); - continue; - } - Token::End => { - let any_paren = stack.iter().any(|group| match *group { - Group::Parens(_) => true, - _ => false, - }); - - if any_paren { - Err(ParseError::new(span, ParseErrorKind::MissingCloseParen)) - } else { - Err(ParseError::new(span, ParseErrorKind::UnexpectedEof)) + Token::End => { + if stack.iter().any(|group| matches!(*group, Group::Parens(_))) { + Err(ParseError::new(span, ParseErrorKind::MissingCloseParen)) + } else { + Err(ParseError::new(span, ParseErrorKind::UnexpectedEof)) + } } - } - }; + }; let mut v = r?; loop { match stack.last_mut() { @@ -181,8 +175,7 @@ impl<'lex> Parser<'lex> { expected: "EOF", found: token.name(), }, - ) - .into()), + )), } } @@ -210,7 +203,7 @@ fn name_expr(input: &str) -> LispExpr { mod tests { use super::*; fn parse(input: &str) -> Result { - let mut parser = Parser::new(Lexer::new(input, 0)); + let mut parser = Parser::new(Lexer::new(input)); parser.parse_single_expr() } diff --git a/src/lisp/prelude.rs b/src/lisp/prelude.rs index aebff98..fee787e 100644 --- a/src/lisp/prelude.rs +++ b/src/lisp/prelude.rs @@ -66,7 +66,7 @@ pub fn new_env() -> Result { primitive!(env, Arity::Atleast(2), "+", |args, _| { let nums = args - .into_iter() + .iter() .map(|arg| arg.try_into()) .collect::, LispError>>()?; return Ok(LispExpr::Number( @@ -76,10 +76,10 @@ pub fn new_env() -> Result { primitive!(env, Arity::Atleast(2), "-", |args, _| { let nums = args - .into_iter() + .iter() .map(|arg| arg.try_into()) .collect::, LispError>>()?; - let mut acc = nums[0].clone(); + let mut acc = *nums[0]; for arg in nums.into_iter().skip(1) { acc = acc - *arg; } @@ -88,7 +88,7 @@ pub fn new_env() -> Result { primitive!(env, Arity::Atleast(2), "*", |args, _| { let nums = args - .into_iter() + .iter() .map(|arg| arg.try_into()) .collect::, LispError>>()?; return Ok(LispExpr::Number( @@ -98,10 +98,10 @@ pub fn new_env() -> Result { primitive!(env, Arity::Atleast(2), "/", |args, _| { let nums = args - .into_iter() + .iter() .map(|arg| arg.try_into()) .collect::, LispError>>()?; - let mut acc = nums[0].clone(); + let mut acc = *nums[0]; for arg in nums.into_iter().skip(1) { acc = acc.div(*arg)?; } @@ -139,7 +139,7 @@ pub fn new_env() -> Result { }); primitive!(env, Arity::Atleast(1), "begin", |args, _| { - Ok(args.into_iter().last().unwrap().clone()) + Ok(args.iter().last().unwrap().clone()) }); primitive!(env, Arity::Exact(0), "quit", |_, app| { @@ -157,8 +157,8 @@ pub fn new_env() -> Result { (LispExpr::DottedList(s), LispExpr::DottedList(o)) => { Ok(s.iter().zip(o).all(|(a, b)| a == b)) } - (LispExpr::List(s), LispExpr::Unit) => Ok(s.len() == 0), - (LispExpr::Unit, LispExpr::List(s)) => Ok(s.len() == 0), + (LispExpr::List(s), LispExpr::Unit) => Ok(s.is_empty()), + (LispExpr::Unit, LispExpr::List(s)) => Ok(s.is_empty()), (LispExpr::DottedList(_), LispExpr::Unit) => Ok(false), (LispExpr::Unit, LispExpr::DottedList(_)) => Ok(false), (LispExpr::StringLit(s), LispExpr::StringLit(o)) => Ok(s == o), @@ -176,10 +176,10 @@ pub fn new_env() -> Result { primitive!(env, Arity::Atleast(2), ">", |args, _| { let nums = args - .into_iter() + .iter() .map(|arg| arg.try_into()) .collect::, LispError>>()?; - let acc = nums[0].clone(); + let acc = *nums[0]; Ok(LispExpr::BoolLit( nums.into_iter().skip(1).all(|&arg| acc > arg), )) @@ -187,10 +187,10 @@ pub fn new_env() -> Result { primitive!(env, Arity::Atleast(2), ">=", |args, _| { let nums = args - .into_iter() + .iter() .map(|arg| arg.try_into()) .collect::, LispError>>()?; - let acc = nums[0].clone(); + let acc = *nums[0]; Ok(LispExpr::BoolLit( nums.into_iter().skip(1).all(|&arg| acc >= arg), )) @@ -198,10 +198,10 @@ pub fn new_env() -> Result { primitive!(env, Arity::Atleast(2), "<", |args, _| { let nums = args - .into_iter() + .iter() .map(|arg| arg.try_into()) .collect::, LispError>>()?; - let acc = nums[0].clone(); + let acc = *nums[0]; Ok(LispExpr::BoolLit( nums.into_iter().skip(1).all(|&arg| acc < arg), )) @@ -209,10 +209,10 @@ pub fn new_env() -> Result { primitive!(env, Arity::Atleast(2), "<=", |args, _| { let nums = args - .into_iter() + .iter() .map(|arg| arg.try_into()) .collect::, LispError>>()?; - let acc = nums[0].clone(); + let acc = *nums[0]; Ok(LispExpr::BoolLit( nums.into_iter().skip(1).all(|&arg| acc <= arg), )) @@ -235,18 +235,16 @@ pub fn new_env() -> Result { .map_err(|e| LispError::Stringified(e.to_string())) .map(|_| LispExpr::Unit); } - return Err(EvalError::NoFileName.into()); + Err(EvalError::NoFileName.into()) }); primitive!(env, Arity::Exact(1), "save-as", |args, app| { match &args[0] { - LispExpr::StringLit(s) => { - return app - .save_as(&s) - .map_err(|e| LispError::Stringified(e.to_string())) - .map(|_| LispExpr::Unit); - } - _ => return Err(EvalError::TypeMismatch.into()), + LispExpr::StringLit(s) => app + .save_as(&s) + .map_err(|e| LispError::Stringified(e.to_string())) + .map(|_| LispExpr::Unit), + _ => Err(EvalError::TypeMismatch.into()), } }); @@ -261,52 +259,52 @@ pub fn new_env() -> Result { primitive!(env, Arity::Exact(0), "brush-fill", |_, app| { app.brush = Brush::Fill; - return Ok(LispExpr::Unit); + Ok(LispExpr::Unit) }); primitive!(env, Arity::Exact(0), "brush-circle", |_, app| { app.brush = Brush::new(0); - return Ok(LispExpr::Unit); + Ok(LispExpr::Unit) }); primitive!(env, Arity::Exact(0), "brush-line", |_, app| { app.brush = Brush::line(0, false); - return Ok(LispExpr::Unit); + Ok(LispExpr::Unit) }); primitive!(env, Arity::Exact(0), "brush-line-extend", |_, app| { app.brush = Brush::line(0, true); - return Ok(LispExpr::Unit); + Ok(LispExpr::Unit) }); primitive!(env, Arity::Exact(2), "cons", |args, _| { if type_match!(args, 1 => LispExpr::Unit) { - return Ok(LispExpr::List(vec![args[0].clone()])); + Ok(LispExpr::List(vec![args[0].clone()])) } else if type_match!(args, 1 => LispExpr::DottedList(_)) { // cons of anything to an improper list is an improper list let mut rest = args[1].unwrap_dotted_list(); rest.insert(0, args[0].clone()); - return Ok(LispExpr::DottedList(rest)); + Ok(LispExpr::DottedList(rest)) } else if type_match!(args, 1 => LispExpr::List(_)) { // cons of anything to a proper list is a proper list let mut rest = args[1].unwrap_list(); rest.insert(0, args[0].clone()); - return Ok(LispExpr::List(rest)); + Ok(LispExpr::List(rest)) } else { // attempt to cons non-lists - return Ok(LispExpr::DottedList(vec![args[0].clone(), args[1].clone()])); + Ok(LispExpr::DottedList(vec![args[0].clone(), args[1].clone()])) } }); primitive!(env, Arity::Exact(1), "car", |args, _| { if type_match!(args, 0 => LispExpr::List(_)) { - return Ok(args[0].unwrap_list().swap_remove(0)); + Ok(args[0].unwrap_list().swap_remove(0)) } else if type_match!(args, 0 => LispExpr::DottedList(_)) { - return Ok(args[0].unwrap_dotted_list().swap_remove(0)); + Ok(args[0].unwrap_dotted_list().swap_remove(0)) } else if type_match!(args, 0 => LispExpr::Unit) { - return Err(EvalError::AccessEmptyList.into()); + Err(EvalError::AccessEmptyList.into()) } else { - return Err(EvalError::TypeMismatch.into()); + Err(EvalError::TypeMismatch.into()) } }); @@ -314,32 +312,32 @@ pub fn new_env() -> Result { if type_match!(args, 0 => LispExpr::List(_)) { // cdr of a proper list is a proper list let mut ls = args[0].unwrap_list(); - if ls.len() == 0 { - return Err(EvalError::AccessEmptyList.into()); + if ls.is_empty() { + Err(EvalError::AccessEmptyList.into()) } else if ls.len() == 1 { - return Ok(LispExpr::Unit); + Ok(LispExpr::Unit) } else { ls.remove(0); - return Ok(LispExpr::List(ls)); + Ok(LispExpr::List(ls)) } } else if type_match!(args, 0 => LispExpr::DottedList(_)) { // cdr of an improper list is an improper list or an atom let ls = args[0].unwrap_dotted_list(); if ls.len() == 2 { - return Ok(ls.into_iter().last().unwrap()); + Ok(ls.into_iter().last().unwrap()) } else { // should be unreachable - return Err(EvalError::AccessEmptyList.into()); + Err(EvalError::AccessEmptyList.into()) } } else if type_match!(args, 0 => LispExpr::Unit) { - return Err(EvalError::AccessEmptyList.into()); + Err(EvalError::AccessEmptyList.into()) } else { - return Err(EvalError::TypeMismatch.into()); + Err(EvalError::TypeMismatch.into()) } }); primitive!(env, Arity::Atleast(1), "list", |args, _| { - return Ok(LispExpr::List(args.to_vec())); + Ok(LispExpr::List(args.to_vec())) }); primitive!(env, Arity::Exact(1), "load-script", |args, app| { @@ -347,40 +345,40 @@ pub fn new_env() -> Result { let path = args[0].unwrap_stringlit(); load_script(&path, app).map(|_| LispExpr::Unit) } else { - return Err(EvalError::TypeMismatch.into()); + Err(EvalError::TypeMismatch.into()) } }); primitive!(env, Arity::Atleast(1), "error", |args, _| { if type_match!(args, 0 => LispExpr::StringLit(_)) { - let mut s = String::from(args[0].unwrap_stringlit()); - for arg in args.into_iter().skip(1) { + let mut s = args[0].unwrap_stringlit(); + for arg in args.iter().skip(1) { s.push_str(&format!(" {}", arg)); } - return Err(EvalError::Custom(s).into()); + Err(EvalError::Custom(s).into()) } else { - return Err(EvalError::TypeMismatch.into()); + Err(EvalError::TypeMismatch.into()) } }); primitive!(env, Arity::Exact(2), "assert-eq", |args, app| { if args[0].compare(&args[1], &app.lisp_env)? { - return Ok(LispExpr::Unit); + Ok(LispExpr::Unit) } else { - return Err(EvalError::AssertionError { + Err(EvalError::AssertionError { expected: args[0].clone(), got: args[1].clone(), } - .into()); + .into()) } }); primitive!(env, Arity::Exact(0), "canvas-width", |_, app| { - return Ok(LispExpr::Number(LispNumber::Integer(app.width() as i64))); + Ok(LispExpr::Number(LispNumber::Integer(app.width() as i64))) }); primitive!(env, Arity::Exact(0), "canvas-height", |_, app| { - return Ok(LispExpr::Number(LispNumber::Integer(app.height() as i64))); + Ok(LispExpr::Number(LispNumber::Integer(app.height() as i64))) }); primitive!(env, Arity::Exact(3), "set-pixel!", |args, app| { @@ -397,21 +395,21 @@ pub fn new_env() -> Result { .try_into() .map_err(|_| -> LispError { EvalError::InvalidCoordinates((x, y)).into() })?; if !app.pixmap.contains(set_loc) { - return Err(EvalError::InvalidCoordinates((x, y)).into()); + Err(EvalError::InvalidCoordinates((x, y)).into()) } else { let old_val = app.pixmap.set(set_loc, val); app.current_operation .push(PaintRecord::new(set_loc, old_val, val)); - return Ok(LispExpr::Unit); + Ok(LispExpr::Unit) } } else { - return Err(EvalError::TypeMismatch.into()); + Err(EvalError::TypeMismatch.into()) } }); primitive!(env, Arity::Exact(0), "commit", |_, app| { app.commit_operation(); - return Ok(LispExpr::Unit); + Ok(LispExpr::Unit) }); primitive!(env, Arity::Exact(2), "add-guide!", |args, app| { @@ -422,9 +420,9 @@ pub fn new_env() -> Result { offset: *offset as u32, }; app.guides.insert(guide, true); - return Ok(LispExpr::Unit); + Ok(LispExpr::Unit) } - _ => return Err(EvalError::TypeMismatch.into()), + _ => Err(EvalError::TypeMismatch.into()), } }); diff --git a/src/main.rs b/src/main.rs index 9370abf..245ee83 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![allow(clippy::upper_case_acronyms, clippy::vec_init_then_push)] mod app; mod bitmap; mod brush; @@ -62,13 +63,12 @@ pub fn error_sink() -> Result<(), AppError> { .run(); } } - return Ok(()); + Ok(()) } pub fn main() { env_logger::init(); - match error_sink() { - Err(e) => error!("{}", e), - _ => (), + if let Err(e) = error_sink() { + error!("{}", e); } } diff --git a/src/message.rs b/src/message.rs index 958dd68..b090b4d 100644 --- a/src/message.rs +++ b/src/message.rs @@ -67,13 +67,19 @@ where } } -impl Into for MessageKind { - fn into(self) -> Color { - match self { - Self::Error => PINK, - Self::Info => WHITE, - Self::Hint => CYAN, - Self::LispResult => GREY, +impl std::default::Default for Message { + fn default() -> Self { + Message::new() + } +} + +impl From for Color { + fn from(msg: MessageKind) -> Color { + match msg { + MessageKind::Error => PINK, + MessageKind::Info => WHITE, + MessageKind::Hint => CYAN, + MessageKind::LispResult => GREY, } } } diff --git a/src/undo.rs b/src/undo.rs index 1044c63..5effd79 100644 --- a/src/undo.rs +++ b/src/undo.rs @@ -67,9 +67,10 @@ where if let Some(p) = self.position { self.position = p.checked_sub(1); // we want to return a clone and not a reference because push deletes the item - return Some(self.operations[p as usize].clone()); + Some(self.operations[p as usize].clone()) + } else { + None } - return None; } pub fn redo(&mut self) -> Option { @@ -82,7 +83,16 @@ where self.position = Some(0); return Some(self.operations[0].clone()); } - return None; + None + } +} + +impl std::default::Default for UndoStack +where + T: Clone, +{ + fn default() -> Self { + UndoStack::new() } } diff --git a/src/utils.rs b/src/utils.rs index ab446f4..8c3b144 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -46,7 +46,7 @@ pub fn draw_text>( font.set_style(sdl2::ttf::FontStyle::NORMAL); font.set_hinting(sdl2::ttf::Hinting::Mono); let surface = font - .render(if text.is_empty() { " " } else { text.as_ref() }) + .render(if text.is_empty() { " " } else { text }) .blended(color) .unwrap(); let texture = texture_creator @@ -84,7 +84,7 @@ pub fn load_script>(path: P, app: &mut AppState) -> Result<(), Li .read_to_string(&mut buf) .map_err(EvalError::ScriptLoadError)?; - let mut parser = Parser::new(Lexer::new(&buf, 0)); + let mut parser = Parser::new(Lexer::new(&buf)); let mut evaluator = Evaluator { app, context: Vec::new(), @@ -94,7 +94,7 @@ pub fn load_script>(path: P, app: &mut AppState) -> Result<(), Li })? { evaluator.eval(&expr)?; } - return Ok(()); + Ok(()) } pub fn load_file>(path: P) -> Result { -- cgit v1.2.3