diff --git a/forge-script-lang/src/lexer/_span.rs b/forge-script-lang/src/lexer/_span.rs index c7c08b2e21e9a75efc5163a4992978402cd6da0b..3026b06c12383a0cb5a9402cae9072abe06c6cf7 100644 --- a/forge-script-lang/src/lexer/_span.rs +++ b/forge-script-lang/src/lexer/_span.rs @@ -326,7 +326,7 @@ impl<'a> nom::Slice<RangeFrom<usize>> for TextSpan<'a> { } } impl<'a> nom::Slice<RangeFull> for TextSpan<'a> { - fn slice(&self, range: RangeFull) -> Self { + fn slice(&self, _range: RangeFull) -> Self { *self } } diff --git a/forge-script-lang/src/lexer/atoms.rs b/forge-script-lang/src/lexer/atoms.rs index 9c9740508bbb741c1e5a032fdeb2cf80ea831506..9f2500b2c45921c1eee6231923eb95ed141c89ce 100644 --- a/forge-script-lang/src/lexer/atoms.rs +++ b/forge-script-lang/src/lexer/atoms.rs @@ -1,7 +1,7 @@ use nom::branch::alt; -use nom::bytes::complete::{is_not, tag}; -use nom::character::complete::{alphanumeric1, char, multispace0, multispace1, none_of, one_of}; -use nom::combinator::{not, peek, value}; +use nom::bytes::complete::tag; +use nom::character::complete::{alphanumeric1, char, multispace0, one_of}; +use nom::combinator::{not, value}; use nom::multi::{many0, many1}; use nom::sequence::{delimited, terminated}; use nom::IResult; diff --git a/forge-script-lang/src/lexer/mod.rs b/forge-script-lang/src/lexer/mod.rs index 2cd83ce8d9499e201dd83c356fd3d222c008f980..c383370e8b029770f42a229f4b0237a6329ec939 100644 --- a/forge-script-lang/src/lexer/mod.rs +++ b/forge-script-lang/src/lexer/mod.rs @@ -23,7 +23,7 @@ use strings::token_string; pub use tokens::{ScriptToken, ScriptTokenType}; use crate::error::TokenError; -pub(crate) use atoms::{raw_decimal, raw_false, raw_true, OwnedSpan, Span}; +pub(crate) use atoms::{raw_decimal, raw_false, raw_true, Span}; mod _lex { use super::*; @@ -172,5 +172,4 @@ mod _lex { } } -use crate::parser::TokenSlice; pub use _lex::script_to_tokens; diff --git a/forge-script-lang/src/lexer/operators.rs b/forge-script-lang/src/lexer/operators.rs index 911cd7343c1a4f5d93abad9255c6b848af0c7929..da54c1b6090e88aab21d347103689859b822c844 100644 --- a/forge-script-lang/src/lexer/operators.rs +++ b/forge-script-lang/src/lexer/operators.rs @@ -1,9 +1,9 @@ use crate::lexer::Span; use crate::lexer::{ScriptToken, ScriptTokenType}; +use crate::parse_ops; use nom::bytes::complete::tag; use nom::IResult; use nom_locate::position; -use crate::parse_ops; parse_ops!( tag ; diff --git a/forge-script-lang/src/lexer/strings.rs b/forge-script-lang/src/lexer/strings.rs index 0b04579b6c43cbe1ba99fa338420de61b04f7d68..c99334a597c0a91b6f8f6f54328562fa1841eaee 100644 --- a/forge-script-lang/src/lexer/strings.rs +++ b/forge-script-lang/src/lexer/strings.rs @@ -37,7 +37,7 @@ fn parse_unicode(input: Span) -> IResult<Span, char> { // the function returns None, map_opt returns an error. In this case, because // not all u32 values are valid unicode code points, we have to fallibly // convert to p_char with from_u32. - let (span, char) = map_opt(parse_u32, move |val| char::from_u32(val))(input)?; + let (span, char) = map_opt(parse_u32, char::from_u32)(input)?; Ok((span, char)) } diff --git a/forge-script-lang/src/lexer/tokens.rs b/forge-script-lang/src/lexer/tokens.rs index 54ef760eca2bbd361382031b1494726dfe0ad2ba..5226c8ab0b7e355bd2908e5d1638d3a1c1440646 100644 --- a/forge-script-lang/src/lexer/tokens.rs +++ b/forge-script-lang/src/lexer/tokens.rs @@ -1,6 +1,6 @@ use crate::lexer::Span; use std::error::Error; -use std::fmt::{format, Debug, Display, Formatter}; +use std::fmt::{Debug, Display, Formatter}; #[derive(PartialEq, Clone, Debug)] pub enum ScriptTokenType { diff --git a/forge-script-lang/src/parser/ast.rs b/forge-script-lang/src/parser/ast.rs index 7bc290f786436aeccf0bf9c2fc9c47dfc127cbf6..bcd350d8f6218b52c85ec84ad07300ee3437fa30 100644 --- a/forge-script-lang/src/parser/ast.rs +++ b/forge-script-lang/src/parser/ast.rs @@ -1,5 +1,5 @@ use crate::runtime::numbers::Number; -use crate::runtime::value::ForgeValue; + use std::fmt::{Display, Formatter}; use std::ops::Deref; diff --git a/forge-script-lang/src/parser/forge_script.rs b/forge-script-lang/src/parser/forge_script.rs index c138d5fca8c7fa0b5ca6a5cfb5e3c5f692ac1c9e..deca8f817f3de9163be5f88318ac31d8ea3443ad 100644 --- a/forge-script-lang/src/parser/forge_script.rs +++ b/forge-script-lang/src/parser/forge_script.rs @@ -1,14 +1,6 @@ -use crate::error::ForgeResult; -use crate::lexer::{script_to_tokens, ScriptTokenType}; +use crate::lexer::script_to_tokens; use crate::parser::ast::{Expression, Program}; -use crate::pratt::{Scanner, ScannerError}; -use crate::{ForgeError, ForgeErrorKind, TokenError}; -use peg::Parse; - -pub type InputSpan<'a, Loc, Tok> = Result<(Loc, Tok, Loc), String>; -type ExprSpan<'a> = InputSpan<'a, usize, ScriptTokenType>; - -pub type SpanSpan<'a> = Result<(usize, ScriptTokenType, usize), ScannerError>; +use crate::ForgeError; macro_rules! export_grammar_fn { ($name:ident = $output:ty => $part: tt) => { diff --git a/forge-script-lang/src/pratt/parser.rs b/forge-script-lang/src/pratt/parser.rs index 9dd33158fdd43aea5decfe6fdf04124b1a81b624..caa55f235453a81fa34c717fff8a1daa437e996d 100644 --- a/forge-script-lang/src/pratt/parser.rs +++ b/forge-script-lang/src/pratt/parser.rs @@ -162,7 +162,7 @@ macro_rules! next_match { } impl<'a> Scanner<'a> { - pub fn new<'b>(source: &'b str) -> Scanner<'b> { + pub fn new(source: &str) -> Scanner<'_> { Scanner { source, position: PositionState::default(), @@ -357,20 +357,20 @@ impl<'a> Scanner<'a> { let result = if can_have_dot { // We haven't consumed a dot, it's an int - (&self.source[self.scan_state.lexeme_start..self.scan_state.lexeme_current]) + self.source[self.scan_state.lexeme_start..self.scan_state.lexeme_current] .replace('_', "") .parse::<i64>() - .map_err(|e| ScannerError { + .map_err(|_e| ScannerError { position: self.position, kind: ScannerErrorKind::InvalidLiteral { ltype: "integer" }, }) .map(ScriptTokenType::Integer) } else { // We have consumed a dot, it's a float - (&self.source[self.scan_state.lexeme_start..self.scan_state.lexeme_current]) + self.source[self.scan_state.lexeme_start..self.scan_state.lexeme_current] .replace('_', "") .parse::<f64>() - .map_err(|e| ScannerError { + .map_err(|_e| ScannerError { position: self.position, kind: ScannerErrorKind::InvalidLiteral { ltype: "float" }, }) diff --git a/forge-script-lang/src/pratt/test_cases.rs b/forge-script-lang/src/pratt/test_cases.rs index 7959a013b476d2d0f461e848def7fe046839786b..91bcbfba4e7e124af13229dac6641a7835eecb93 100644 --- a/forge-script-lang/src/pratt/test_cases.rs +++ b/forge-script-lang/src/pratt/test_cases.rs @@ -1,5 +1,5 @@ use crate::lexer::ScriptTokenType; -use crate::pratt::parser::{Scanner, ScannerError, ScannerResult}; +use crate::pratt::parser::{Scanner, ScannerError}; use test_case::test_case; #[test_case("", Ok(ScriptTokenType::Eof) ; "expects eof")] diff --git a/forge-script-lang/src/runtime/executor/printer.rs b/forge-script-lang/src/runtime/executor/printer.rs index 5ebad1361f87a3303cb2b1dab0bbcf69880522e5..3f6ebdead77c60ad8e8616281f560845931dec13 100644 --- a/forge-script-lang/src/runtime/executor/printer.rs +++ b/forge-script-lang/src/runtime/executor/printer.rs @@ -65,10 +65,10 @@ impl TreePrinter { inner_printer.indent = self.indent; let len = list.len(); - let mut iter = list.expressions.iter(); + let iter = list.expressions.iter(); let mut counter = 1; - while let Some(value) = iter.next() { + for value in iter { inner_printer.evaluate_expression(value); if counter < len { inner_printer.writeln(";"); @@ -142,10 +142,10 @@ impl Visitor for TreePrinter { self.evaluate_value_expression(assign.value.as_ref()); } ValueExpression::ConditionalBlock(condition) => { - let mut iter = condition.blocks.iter(); - let mut curr = 1; + let iter = condition.blocks.iter(); + let curr = 1; let count = iter.len(); - while let Some(item) = iter.next() { + for item in iter { self.write("if "); self.evaluate_value_expression(item.guard.as_ref()); self.writeln(" {"); @@ -175,7 +175,7 @@ impl Visitor for TreePrinter { ValueExpression::Identifier(ident) => { self.write(ident); } - ValueExpression::Accessor(accessor) => self.write("<ACCESSOR>"), + ValueExpression::Accessor(_accessor) => self.write("<ACCESSOR>"), ValueExpression::FunctionCall(call) => { self.write(&call.name); self.write("("); diff --git a/forge-script-lang/src/runtime/executor/simple.rs b/forge-script-lang/src/runtime/executor/simple.rs index f12efa25aecc848fecb85db45394f11e81c14eb2..0b7b3738a06e6f81bab83c611b025be7e544b117 100644 --- a/forge-script-lang/src/runtime/executor/simple.rs +++ b/forge-script-lang/src/runtime/executor/simple.rs @@ -206,7 +206,7 @@ impl Visitor for SimpleExecutor { .get_variable(ident) .cloned() .ok_or_else(|| RuntimeError::UndefinedVariable(ident.to_string())), - ValueExpression::Accessor(ident) => Err(RuntimeError::Unsupported("Accessor")), + ValueExpression::Accessor(_ident) => Err(RuntimeError::Unsupported("Accessor")), ValueExpression::FunctionCall(_) => Err(RuntimeError::Unsupported("FunctionCall")), ValueExpression::DeclareFunction(_) => { Err(RuntimeError::Unsupported("DeclareFunction")) diff --git a/forge-script-lang/src/runtime/vm/chunks.rs b/forge-script-lang/src/runtime/vm/chunks.rs index e7d9d5290e985175cd240502216a91198b15c909..aca2687d6000103df42494f2974b150cc8257c53 100644 --- a/forge-script-lang/src/runtime/vm/chunks.rs +++ b/forge-script-lang/src/runtime/vm/chunks.rs @@ -1,9 +1,8 @@ use crate::runtime::value::ForgeValue; use crate::runtime::vm::const_data::{ConstData, ConstDataRef}; -use crate::runtime::vm::opcode::{OpCode, OpCodeError}; +use crate::runtime::vm::opcode::OpCode; use crate::utilities::Clown; use std::fmt::{Display, Formatter}; -use std::ops::{Deref, DerefMut}; #[derive(Default)] pub struct Chunk { @@ -103,7 +102,7 @@ pub trait ChunkOps { _ => {} } - writeln!(f, "")?; + writeln!(f)?; offset = opcode.next_offset(offset); } diff --git a/forge-script-lang/src/runtime/vm/compile.rs b/forge-script-lang/src/runtime/vm/compile.rs index e1fb05078179bafbb5bfe2398d9e9484eaa66706..4af21e4e499f0debf5eee035c96c8d4b75350499 100644 --- a/forge-script-lang/src/runtime/vm/compile.rs +++ b/forge-script-lang/src/runtime/vm/compile.rs @@ -1,8 +1,8 @@ use crate::lexer::ScriptTokenType; use crate::pratt::{Scanner, ScannerError, ScannerErrorKind, ScannerIter, ScannerToken}; -use crate::rule_table; + use crate::runtime::vm::Chunk; -use crate::runtime::vm::{ParsingPrecedence, ParsingRuleType, ParsingRules}; +use crate::runtime::vm::ParsingPrecedence; #[derive(Clone, Default)] pub struct ParsingState { @@ -79,7 +79,7 @@ impl<'a> Compiler<'a> { Ok(self.chunk()) } - fn process_precedence(&mut self, precedence: ParsingPrecedence) -> CompilerOp { + fn process_precedence(&mut self, _precedence: ParsingPrecedence) -> CompilerOp { Ok(()) } @@ -139,6 +139,6 @@ impl<'a> Compiler<'a> { } } -fn compile_expression(compiler: &mut Compiler) -> CompilerOp { +fn compile_expression(_compiler: &mut Compiler) -> CompilerOp { Ok(()) } diff --git a/forge-script-lang/src/runtime/vm/machine.rs b/forge-script-lang/src/runtime/vm/machine.rs index 5e7c724e0fbac2abf1233b981f368af5bc9ecdb9..95feeab6c3de2912e1ab4a280f68daf641ea2629 100644 --- a/forge-script-lang/src/runtime/vm/machine.rs +++ b/forge-script-lang/src/runtime/vm/machine.rs @@ -1,10 +1,10 @@ use crate::parser::ast::BinaryOp; -use crate::parser::parse_program; + use crate::runtime::value::{ForgeValue, UnsupportedOperation}; use crate::runtime::vm::chunk_builder::ChunkBuilder; use crate::runtime::vm::chunks::Chunk; use crate::runtime::vm::{ChunkOps, OpCode}; -use crate::{format_forge_error, ForgeErrorKind}; + use std::collections::VecDeque; use std::error::Error; use std::fmt::{Display, Formatter}; diff --git a/forge-script-lang/src/runtime/vm/opcode.rs b/forge-script-lang/src/runtime/vm/opcode.rs index 9b300dd9b7f4d5adc63fedbd567e4f4b5cbb3c0c..3781382344cf337ed47bc23388aff7c2f94f7ad8 100644 --- a/forge-script-lang/src/runtime/vm/opcode.rs +++ b/forge-script-lang/src/runtime/vm/opcode.rs @@ -15,9 +15,7 @@ pub enum OpCode { impl OpCode { pub fn next_offset(&self, current: usize) -> usize { - match self { - _ => current + 1, - } + current + 1 } pub fn op_byte(&self) -> u8 { diff --git a/forge-script-lang/tests/program_tests.rs b/forge-script-lang/tests/program_tests.rs index 40e59fb4e1dc436931aa4c0b3efbb6db36ba0269..571721cd2ae3458ad5c32995e91afe6448a2c73f 100644 --- a/forge-script-lang/tests/program_tests.rs +++ b/forge-script-lang/tests/program_tests.rs @@ -1,4 +1,4 @@ -use forge_script_lang::parse::{parse_expression, parse_program}; +use forge_script_lang::parse::parse_program; use std::path::PathBuf; fn get_base_path() -> Result<PathBuf, std::io::Error> { diff --git a/forge-script/src/main.rs b/forge-script/src/main.rs index ef49ca6a046cea97102ebb9b5a91f9d8a46f3f79..27448f160bb25742a898c699f410a07cfdea2979 100644 --- a/forge-script/src/main.rs +++ b/forge-script/src/main.rs @@ -1,9 +1,8 @@ use forge_script_lang::parse::parse_program; -use forge_script_lang::runtime::vm::{ChunkOps, Compiler}; mod repl; fn main() { let program = "2+2"; - let ast = parse_program(program).expect("Failed"); + let _ast = parse_program(program).expect("Failed"); } diff --git a/forge-script/src/repl.rs b/forge-script/src/repl.rs index 1535fa84aa6e5f0f805c8354277c6d703429cf3c..a39877bafb76b0e2f3f3fc9cc9f33b4d767f25e4 100644 --- a/forge-script/src/repl.rs +++ b/forge-script/src/repl.rs @@ -8,7 +8,7 @@ pub struct Repl { } fn parse_hex(string: &str) -> Result<Vec<u8>, ParseIntError> { - let parts = string.split(" ").collect::<Vec<&str>>(); + let parts = string.split(' ').collect::<Vec<&str>>(); let mut out = Vec::with_capacity(parts.len()); for part in parts { out.push(u8::from_str_radix(part, 16)?);