Skip to content
Snippets Groups Projects
Verified Commit c81303fe authored by Louis's avatar Louis :fire:
Browse files

Linting

parent 1dc36874
No related branches found
No related tags found
No related merge requests found
Pipeline #513 passed with stages
in 1 minute and 21 seconds
Showing
with 36 additions and 49 deletions
...@@ -326,7 +326,7 @@ impl<'a> nom::Slice<RangeFrom<usize>> for TextSpan<'a> { ...@@ -326,7 +326,7 @@ impl<'a> nom::Slice<RangeFrom<usize>> for TextSpan<'a> {
} }
} }
impl<'a> nom::Slice<RangeFull> for TextSpan<'a> { impl<'a> nom::Slice<RangeFull> for TextSpan<'a> {
fn slice(&self, range: RangeFull) -> Self { fn slice(&self, _range: RangeFull) -> Self {
*self *self
} }
} }
use nom::branch::alt; use nom::branch::alt;
use nom::bytes::complete::{is_not, tag}; use nom::bytes::complete::tag;
use nom::character::complete::{alphanumeric1, char, multispace0, multispace1, none_of, one_of}; use nom::character::complete::{alphanumeric1, char, multispace0, one_of};
use nom::combinator::{not, peek, value}; use nom::combinator::{not, value};
use nom::multi::{many0, many1}; use nom::multi::{many0, many1};
use nom::sequence::{delimited, terminated}; use nom::sequence::{delimited, terminated};
use nom::IResult; use nom::IResult;
......
...@@ -23,7 +23,7 @@ use strings::token_string; ...@@ -23,7 +23,7 @@ use strings::token_string;
pub use tokens::{ScriptToken, ScriptTokenType}; pub use tokens::{ScriptToken, ScriptTokenType};
use crate::error::TokenError; 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 { mod _lex {
use super::*; use super::*;
...@@ -172,5 +172,4 @@ mod _lex { ...@@ -172,5 +172,4 @@ mod _lex {
} }
} }
use crate::parser::TokenSlice;
pub use _lex::script_to_tokens; pub use _lex::script_to_tokens;
use crate::lexer::Span; use crate::lexer::Span;
use crate::lexer::{ScriptToken, ScriptTokenType}; use crate::lexer::{ScriptToken, ScriptTokenType};
use crate::parse_ops;
use nom::bytes::complete::tag; use nom::bytes::complete::tag;
use nom::IResult; use nom::IResult;
use nom_locate::position; use nom_locate::position;
use crate::parse_ops;
parse_ops!( parse_ops!(
tag ; tag ;
......
...@@ -37,7 +37,7 @@ fn parse_unicode(input: Span) -> IResult<Span, char> { ...@@ -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 // 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 // not all u32 values are valid unicode code points, we have to fallibly
// convert to p_char with from_u32. // 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)) Ok((span, char))
} }
......
use crate::lexer::Span; use crate::lexer::Span;
use std::error::Error; use std::error::Error;
use std::fmt::{format, Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
#[derive(PartialEq, Clone, Debug)] #[derive(PartialEq, Clone, Debug)]
pub enum ScriptTokenType { pub enum ScriptTokenType {
......
use crate::runtime::numbers::Number; use crate::runtime::numbers::Number;
use crate::runtime::value::ForgeValue;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
use std::ops::Deref; use std::ops::Deref;
......
use crate::error::ForgeResult; use crate::lexer::script_to_tokens;
use crate::lexer::{script_to_tokens, ScriptTokenType};
use crate::parser::ast::{Expression, Program}; use crate::parser::ast::{Expression, Program};
use crate::pratt::{Scanner, ScannerError}; use crate::ForgeError;
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>;
macro_rules! export_grammar_fn { macro_rules! export_grammar_fn {
($name:ident = $output:ty => $part: tt) => { ($name:ident = $output:ty => $part: tt) => {
......
...@@ -162,7 +162,7 @@ macro_rules! next_match { ...@@ -162,7 +162,7 @@ macro_rules! next_match {
} }
impl<'a> Scanner<'a> { impl<'a> Scanner<'a> {
pub fn new<'b>(source: &'b str) -> Scanner<'b> { pub fn new(source: &str) -> Scanner<'_> {
Scanner { Scanner {
source, source,
position: PositionState::default(), position: PositionState::default(),
...@@ -357,20 +357,20 @@ impl<'a> Scanner<'a> { ...@@ -357,20 +357,20 @@ impl<'a> Scanner<'a> {
let result = if can_have_dot { let result = if can_have_dot {
// We haven't consumed a dot, it's an int // 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('_', "") .replace('_', "")
.parse::<i64>() .parse::<i64>()
.map_err(|e| ScannerError { .map_err(|_e| ScannerError {
position: self.position, position: self.position,
kind: ScannerErrorKind::InvalidLiteral { ltype: "integer" }, kind: ScannerErrorKind::InvalidLiteral { ltype: "integer" },
}) })
.map(ScriptTokenType::Integer) .map(ScriptTokenType::Integer)
} else { } else {
// We have consumed a dot, it's a float // 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('_', "") .replace('_', "")
.parse::<f64>() .parse::<f64>()
.map_err(|e| ScannerError { .map_err(|_e| ScannerError {
position: self.position, position: self.position,
kind: ScannerErrorKind::InvalidLiteral { ltype: "float" }, kind: ScannerErrorKind::InvalidLiteral { ltype: "float" },
}) })
......
use crate::lexer::ScriptTokenType; use crate::lexer::ScriptTokenType;
use crate::pratt::parser::{Scanner, ScannerError, ScannerResult}; use crate::pratt::parser::{Scanner, ScannerError};
use test_case::test_case; use test_case::test_case;
#[test_case("", Ok(ScriptTokenType::Eof) ; "expects eof")] #[test_case("", Ok(ScriptTokenType::Eof) ; "expects eof")]
......
...@@ -65,10 +65,10 @@ impl TreePrinter { ...@@ -65,10 +65,10 @@ impl TreePrinter {
inner_printer.indent = self.indent; inner_printer.indent = self.indent;
let len = list.len(); let len = list.len();
let mut iter = list.expressions.iter(); let iter = list.expressions.iter();
let mut counter = 1; let mut counter = 1;
while let Some(value) = iter.next() { for value in iter {
inner_printer.evaluate_expression(value); inner_printer.evaluate_expression(value);
if counter < len { if counter < len {
inner_printer.writeln(";"); inner_printer.writeln(";");
...@@ -142,10 +142,10 @@ impl Visitor for TreePrinter { ...@@ -142,10 +142,10 @@ impl Visitor for TreePrinter {
self.evaluate_value_expression(assign.value.as_ref()); self.evaluate_value_expression(assign.value.as_ref());
} }
ValueExpression::ConditionalBlock(condition) => { ValueExpression::ConditionalBlock(condition) => {
let mut iter = condition.blocks.iter(); let iter = condition.blocks.iter();
let mut curr = 1; let curr = 1;
let count = iter.len(); let count = iter.len();
while let Some(item) = iter.next() { for item in iter {
self.write("if "); self.write("if ");
self.evaluate_value_expression(item.guard.as_ref()); self.evaluate_value_expression(item.guard.as_ref());
self.writeln(" {"); self.writeln(" {");
...@@ -175,7 +175,7 @@ impl Visitor for TreePrinter { ...@@ -175,7 +175,7 @@ impl Visitor for TreePrinter {
ValueExpression::Identifier(ident) => { ValueExpression::Identifier(ident) => {
self.write(ident); self.write(ident);
} }
ValueExpression::Accessor(accessor) => self.write("<ACCESSOR>"), ValueExpression::Accessor(_accessor) => self.write("<ACCESSOR>"),
ValueExpression::FunctionCall(call) => { ValueExpression::FunctionCall(call) => {
self.write(&call.name); self.write(&call.name);
self.write("("); self.write("(");
......
...@@ -206,7 +206,7 @@ impl Visitor for SimpleExecutor { ...@@ -206,7 +206,7 @@ impl Visitor for SimpleExecutor {
.get_variable(ident) .get_variable(ident)
.cloned() .cloned()
.ok_or_else(|| RuntimeError::UndefinedVariable(ident.to_string())), .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::FunctionCall(_) => Err(RuntimeError::Unsupported("FunctionCall")),
ValueExpression::DeclareFunction(_) => { ValueExpression::DeclareFunction(_) => {
Err(RuntimeError::Unsupported("DeclareFunction")) Err(RuntimeError::Unsupported("DeclareFunction"))
......
use crate::runtime::value::ForgeValue; use crate::runtime::value::ForgeValue;
use crate::runtime::vm::const_data::{ConstData, ConstDataRef}; 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 crate::utilities::Clown;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
use std::ops::{Deref, DerefMut};
#[derive(Default)] #[derive(Default)]
pub struct Chunk { pub struct Chunk {
...@@ -103,7 +102,7 @@ pub trait ChunkOps { ...@@ -103,7 +102,7 @@ pub trait ChunkOps {
_ => {} _ => {}
} }
writeln!(f, "")?; writeln!(f)?;
offset = opcode.next_offset(offset); offset = opcode.next_offset(offset);
} }
......
use crate::lexer::ScriptTokenType; use crate::lexer::ScriptTokenType;
use crate::pratt::{Scanner, ScannerError, ScannerErrorKind, ScannerIter, ScannerToken}; use crate::pratt::{Scanner, ScannerError, ScannerErrorKind, ScannerIter, ScannerToken};
use crate::rule_table;
use crate::runtime::vm::Chunk; use crate::runtime::vm::Chunk;
use crate::runtime::vm::{ParsingPrecedence, ParsingRuleType, ParsingRules}; use crate::runtime::vm::ParsingPrecedence;
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct ParsingState { pub struct ParsingState {
...@@ -79,7 +79,7 @@ impl<'a> Compiler<'a> { ...@@ -79,7 +79,7 @@ impl<'a> Compiler<'a> {
Ok(self.chunk()) Ok(self.chunk())
} }
fn process_precedence(&mut self, precedence: ParsingPrecedence) -> CompilerOp { fn process_precedence(&mut self, _precedence: ParsingPrecedence) -> CompilerOp {
Ok(()) Ok(())
} }
...@@ -139,6 +139,6 @@ impl<'a> Compiler<'a> { ...@@ -139,6 +139,6 @@ impl<'a> Compiler<'a> {
} }
} }
fn compile_expression(compiler: &mut Compiler) -> CompilerOp { fn compile_expression(_compiler: &mut Compiler) -> CompilerOp {
Ok(()) Ok(())
} }
use crate::parser::ast::BinaryOp; use crate::parser::ast::BinaryOp;
use crate::parser::parse_program;
use crate::runtime::value::{ForgeValue, UnsupportedOperation}; use crate::runtime::value::{ForgeValue, UnsupportedOperation};
use crate::runtime::vm::chunk_builder::ChunkBuilder; use crate::runtime::vm::chunk_builder::ChunkBuilder;
use crate::runtime::vm::chunks::Chunk; use crate::runtime::vm::chunks::Chunk;
use crate::runtime::vm::{ChunkOps, OpCode}; use crate::runtime::vm::{ChunkOps, OpCode};
use crate::{format_forge_error, ForgeErrorKind};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::error::Error; use std::error::Error;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
......
...@@ -15,9 +15,7 @@ pub enum OpCode { ...@@ -15,9 +15,7 @@ pub enum OpCode {
impl OpCode { impl OpCode {
pub fn next_offset(&self, current: usize) -> usize { pub fn next_offset(&self, current: usize) -> usize {
match self { current + 1
_ => current + 1,
}
} }
pub fn op_byte(&self) -> u8 { pub fn op_byte(&self) -> u8 {
......
use forge_script_lang::parse::{parse_expression, parse_program}; use forge_script_lang::parse::parse_program;
use std::path::PathBuf; use std::path::PathBuf;
fn get_base_path() -> Result<PathBuf, std::io::Error> { fn get_base_path() -> Result<PathBuf, std::io::Error> {
......
use forge_script_lang::parse::parse_program; use forge_script_lang::parse::parse_program;
use forge_script_lang::runtime::vm::{ChunkOps, Compiler};
mod repl; mod repl;
fn main() { fn main() {
let program = "2+2"; let program = "2+2";
let ast = parse_program(program).expect("Failed"); let _ast = parse_program(program).expect("Failed");
} }
...@@ -8,7 +8,7 @@ pub struct Repl { ...@@ -8,7 +8,7 @@ pub struct Repl {
} }
fn parse_hex(string: &str) -> Result<Vec<u8>, ParseIntError> { 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()); let mut out = Vec::with_capacity(parts.len());
for part in parts { for part in parts {
out.push(u8::from_str_radix(part, 16)?); out.push(u8::from_str_radix(part, 16)?);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment