diff --git a/Cargo.toml b/Cargo.toml index 4047e8a..f8801d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "maiden" version = "0.1.0" authors = ["Tom Parker "] +edition = "2018" [dependencies] nom = "4" diff --git a/build.rs b/build.rs index 67aaafc..175d2d9 100644 --- a/build.rs +++ b/build.rs @@ -38,7 +38,8 @@ fn main() { name = name, test_name = test_name, function = function - ).unwrap(); + ) + .unwrap(); } } } diff --git a/src/common.rs b/src/common.rs index 4afc4b0..6355913 100644 --- a/src/common.rs +++ b/src/common.rs @@ -182,7 +182,7 @@ pub struct Program { pub functions: HashMap, } -error_chain!{ +error_chain! { foreign_links { Io(::std::io::Error); } diff --git a/src/main.rs b/src/main.rs index 54ff5ea..bbcf378 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ #![recursion_limit = "5000"] #![deny(warnings)] -#![cfg_attr(feature = "cargo-clippy", allow(needless_return))] +#![allow(clippy::needless_return)] #[macro_use] extern crate nom; @@ -50,7 +50,8 @@ fn main() -> common::Result<()> { .help("Sets the input file to use") .required(true) .index(1), - ).get_matches(); + ) + .get_matches(); let mut f = File::open(matches.value_of("INPUT").unwrap())?; let mut buffer = String::new(); f.read_to_string(&mut buffer)?; @@ -78,7 +79,7 @@ fn main() { #[cfg(test)] mod tests { use super::*; - use common::Expression; + use crate::common::Expression; use std::collections::HashMap; use std::io::Cursor; @@ -214,7 +215,7 @@ mod tests { #[test] fn double_increment() { - let end_variables = hashmap!{ + let end_variables = hashmap! { "my world" => Expression::Floating(2f64), }; test_program( @@ -226,7 +227,7 @@ mod tests { #[test] fn double_decrement() { - let end_variables = hashmap!{ + let end_variables = hashmap! { "the walls" => Expression::Floating(-2f64), }; test_program( diff --git a/src/parser.rs b/src/parser.rs index 3f4e740..1b0741d 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,8 +1,8 @@ // because nom macros -#![cfg_attr(feature = "cargo-clippy", allow(double_parens))] -#![cfg_attr(feature = "cargo-clippy", allow(double_comparisons))] +#![allow(clippy::double_parens)] +#![allow(clippy::double_comparisons)] -use common::*; +use crate::common::*; use nom; use nom::types::CompleteStr; use std::collections::HashMap; @@ -312,7 +312,7 @@ named!(not_expr(Span) -> SymbolType, ) ); -#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] // FIXME: break this up a bit +#[allow(clippy::cyclomatic_complexity)] // FIXME: break this up a bit fn multiply_expr(input: Span) -> nom::IResult> { let (rest, (mut res, mut times)) = do_parse!( input, @@ -338,7 +338,7 @@ fn multiply_expr(input: Span) -> nom::IResult> { return Ok((rest, res)); } -#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] // FIXME: break this up a bit +#[allow(clippy::cyclomatic_complexity)] // FIXME: break this up a bit fn add_expr(input: Span) -> nom::IResult> { let (rest, (mut res, mut adds)) = do_parse!( input, @@ -346,13 +346,14 @@ fn add_expr(input: Span) -> nom::IResult> { >> adds: many0!(do_parse!( take_while1!(is_space) >> op: alt_complete!( - alt_complete!( - tag_no_case!("without") | tag_no_case!("minus") - ) => {|_| SymbolType::Subtract} | - alt_complete!( - tag_no_case!("with") | tag_no_case!("plus") - ) => {|_| SymbolType::Add} - ) >> take_while1!(is_space) + alt_complete!( + tag_no_case!("without") | tag_no_case!("minus") + ) => {|_| SymbolType::Subtract} | + alt_complete!( + tag_no_case!("with") | tag_no_case!("plus") + ) => {|_| SymbolType::Add} + ) + >> take_while1!(is_space) >> other_me: multiply_expr >> (op, other_me) )) @@ -365,7 +366,7 @@ fn add_expr(input: Span) -> nom::IResult> { return Ok((rest, res)); } -#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] // FIXME: break this up a bit +#[allow(clippy::cyclomatic_complexity)] // FIXME: break this up a bit fn inequality_expr(input: Span) -> nom::IResult> { let (rest, (mut res, mut ineqs)) = do_parse!( input, @@ -389,7 +390,7 @@ fn inequality_expr(input: Span) -> nom::IResult> { return Ok((rest, res)); } -#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] // FIXME: break this up a bit +#[allow(clippy::cyclomatic_complexity)] // FIXME: break this up a bit fn equality_expr(input: Span) -> nom::IResult> { let (rest, (mut res, mut eqs)) = do_parse!( input, @@ -397,13 +398,14 @@ fn equality_expr(input: Span) -> nom::IResult> { >> eqs: many0!(do_parse!( take_while1!(is_space) >> kind: alt_complete!( - alt_complete!( - tag!("is") | tag!("was") | tag!("are") | tag!("were") - ) => {|_| SymbolType::Is} | - alt_complete!( - tag_no_case!("ain't") | tag_no_case!("aint") - ) => {|_| SymbolType::Aint} - ) >> take_while1!(is_space) + alt_complete!( + tag!("is") | tag!("was") | tag!("are") | tag!("were") + ) => {|_| SymbolType::Is} | + alt_complete!( + tag_no_case!("ain't") | tag_no_case!("aint") + ) => {|_| SymbolType::Aint} + ) + >> take_while1!(is_space) >> other_ie: inequality_expr >> (kind, other_ie) )) @@ -423,10 +425,11 @@ fn boolean_expr(input: Span) -> nom::IResult> { >> bqs: many0!(do_parse!( take_while1!(is_space) >> kind: alt_complete!( - tag_no_case!("and") => {|_| SymbolType::And} | - tag_no_case!("or") => {|_| SymbolType::Or} | - tag_no_case!("nor") => {|_| SymbolType::Nor} - ) >> take_while1!(is_space) + tag_no_case!("and") => {|_| SymbolType::And} | + tag_no_case!("or") => {|_| SymbolType::Or} | + tag_no_case!("nor") => {|_| SymbolType::Nor} + ) + >> take_while1!(is_space) >> other_ee: equality_expr >> (kind, other_ee) )) @@ -938,7 +941,7 @@ fn build_next(commands: &mut Vec, loop_starts: &mut Vec) -> return Command::Next { loop_start }; } -#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] // FIXME: break this up a bit +#[allow(clippy::cyclomatic_complexity)] // FIXME: break this up a bit pub fn parse(input: &str) -> Result { let raw_lines = lines(&input)?; if !raw_lines.0.fragment.is_empty() && raw_lines.0.fragment.chars().any(|c| !c.is_whitespace()) @@ -1365,7 +1368,8 @@ mod tests { "ladykiller".to_string() ]), 0 - ).unwrap(), + ) + .unwrap(), Expression::Floating(100f64) ); } diff --git a/src/runner.rs b/src/runner.rs index 37a464e..281a073 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -1,4 +1,4 @@ -use common::*; +use crate::common::*; use std; use std::collections::HashMap; use std::io::{self, Write}; @@ -81,9 +81,11 @@ fn run_binop_shortcut( } } }, - Expression::String(_) => if let Expression::String(_) = res_second { - return Ok(f(state, &res_first, &res_second)?); - }, + Expression::String(_) => { + if let Expression::String(_) = res_second { + return Ok(f(state, &res_first, &res_second)?); + } + } Expression::Mysterious => { if let Expression::Mysterious = res_second { return Ok(true); @@ -182,9 +184,11 @@ fn run_mathbinop( let second_value = *i; return Ok(Expression::Floating(f(0f64, second_value))); } - Expression::String(ref s_s) => if let Expression::Add(_, _) = op { - return Ok(Expression::String(format!("null{}", s_s))); - }, + Expression::String(ref s_s) => { + if let Expression::Add(_, _) = op { + return Ok(Expression::String(format!("null{}", s_s))); + } + } Expression::Null => { return Ok(Expression::Floating(f(0f64, 0f64))); } @@ -289,7 +293,7 @@ fn call_function( return run_core(&mut new_state, program, func.location + 1); } -#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] // FIXME: break this up a bit +#[allow(clippy::cyclomatic_complexity)] // FIXME: break this up a bit fn run_expression( state: &mut State, program: &Program, @@ -449,16 +453,14 @@ fn run_expression( pub fn run(program: &Program, writer: &mut Write) -> Result> { let pc = 0; let mut variables: HashMap = HashMap::new(); - { - let mut state = State { - variables: &mut variables, - writer, - current_line: 0, - depth: 0, - pronoun: None, - }; - run_core(&mut state, program, pc)?; - } // FIXME: Drop once NLL is merged + let mut state = State { + variables: &mut variables, + writer, + current_line: 0, + depth: 0, + pronoun: None, + }; + run_core(&mut state, program, pc)?; return Ok(variables); } diff --git a/src/web.rs b/src/web.rs index 5b88f2e..580a029 100644 --- a/src/web.rs +++ b/src/web.rs @@ -1,6 +1,6 @@ -use common; -use parser; -use runner; +use crate::common; +use crate::parser; +use crate::runner; use std; use yew::prelude::*;