Fix clippy warnings
This commit is contained in:
		
							parent
							
								
									bc9b755ab9
								
							
						
					
					
						commit
						4aa032139d
					
				| @ -1,3 +1,4 @@ | ||||
| use std::collections::hash_map::Entry; | ||||
| use std::collections::HashMap; | ||||
| use std::num::ParseIntError; | ||||
| 
 | ||||
| @ -216,14 +217,17 @@ impl Scope { | ||||
|         variable: String, | ||||
|         vtype: VariableType, | ||||
|     ) -> Result<(), CompilerError> { | ||||
|         if self.variables.contains_key(&variable) { | ||||
|             Err(CompilerError::VariableExists(pos, variable)) | ||||
|         } else if let Some(inner) = &mut self.inner_scope { | ||||
|             inner.add_var(pos, variable, vtype) | ||||
|         let entry = self.variables.entry(variable.clone()); | ||||
|         if let Entry::Vacant(e) = entry { | ||||
|             if let Some(inner) = &mut self.inner_scope { | ||||
|                 inner.add_var(pos, variable, vtype) | ||||
|             } else { | ||||
|                 e.insert((self.counter, vtype)); | ||||
|                 self.counter += 1; | ||||
|                 Ok(()) | ||||
|             } | ||||
|         } else { | ||||
|             self.variables.insert(variable, (self.counter, vtype)); | ||||
|             self.counter += 1; | ||||
|             Ok(()) | ||||
|             Err(CompilerError::VariableExists(pos, variable)) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -89,7 +89,7 @@ impl Display for CompilerError { | ||||
|             CompilerError::LetFailed(pos, error) => { | ||||
|                 format!("Let statement failed at {}:\n  {}", pos, error) | ||||
|             } | ||||
|             CompilerError::CanNotAssignVoidType => format!("Can not assign void type here"), | ||||
|             CompilerError::CanNotAssignVoidType => "Can not assign void type here".to_string(), | ||||
|             CompilerError::FunctionNotFound(pos, name, params) => format!( | ||||
|                 "Function with signature {}{} not found at {}", | ||||
|                 name, | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| #![forbid(unsafe_code)] | ||||
| #![warn(clippy::all)] | ||||
| 
 | ||||
| mod compiler; | ||||
| mod errors; | ||||
|  | ||||
| @ -122,14 +122,12 @@ impl Parser { | ||||
|                     } else { | ||||
|                         false | ||||
|                     } | ||||
|                 } else if ALLOWED_IDENT_BEGIN_CHARS.contains(lowercase) { | ||||
|                     ident = Some(peek.to_string()); | ||||
|                     self.inconfidence += 1; | ||||
|                     true | ||||
|                 } else { | ||||
|                     if ALLOWED_IDENT_BEGIN_CHARS.contains(lowercase) { | ||||
|                         ident = Some(peek.to_string()); | ||||
|                         self.inconfidence += 1; | ||||
|                         true | ||||
|                     } else { | ||||
|                         false | ||||
|                     } | ||||
|                     false | ||||
|                 } | ||||
|             } else { | ||||
|                 false | ||||
| @ -155,14 +153,12 @@ impl Parser { | ||||
|                         self.inconfidence += 1; | ||||
|                         true | ||||
|                     } | ||||
|                 } else if peek == '"' { | ||||
|                     content = Some(String::new()); | ||||
|                     self.inconfidence += 1; | ||||
|                     true | ||||
|                 } else { | ||||
|                     if peek == '"' { | ||||
|                         content = Some(String::new()); | ||||
|                         self.inconfidence += 1; | ||||
|                         true | ||||
|                     } else { | ||||
|                         false | ||||
|                     } | ||||
|                     false | ||||
|                 } | ||||
|             } else { | ||||
|                 false | ||||
| @ -273,7 +269,7 @@ impl<'a> Expect<'a> { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     pub fn and<'b, T: Into<String>>(self, other: Expectable<T>) -> Expects<'a> { | ||||
|     pub fn and<T: Into<String>>(self, other: Expectable<T>) -> Expects<'a> { | ||||
|         let texts = if let Some(text) = self.text { | ||||
|             Some(vec![text]) | ||||
|         } else { | ||||
| @ -281,7 +277,7 @@ impl<'a> Expect<'a> { | ||||
|         }; | ||||
|         Expects::and( | ||||
|             Expects { | ||||
|                 texts: texts, | ||||
|                 texts, | ||||
|                 parser: self.parser, | ||||
|             }, | ||||
|             other, | ||||
| @ -295,7 +291,7 @@ pub struct Expects<'a> { | ||||
| } | ||||
| 
 | ||||
| impl<'a> Expects<'a> { | ||||
|     pub fn and<'b, T: Into<String>>(mut self, expect: Expectable<T>) -> Expects<'a> { | ||||
|     pub fn and<T: Into<String>>(mut self, expect: Expectable<T>) -> Expects<'a> { | ||||
|         let other = self.parser.expect(expect); | ||||
|         if let Some(texts) = &mut self.texts { | ||||
|             if let Some(text) = other.get_inconfident() { | ||||
|  | ||||
| @ -15,7 +15,7 @@ impl Statement { | ||||
|     pub fn parse(parser: &mut Parser) -> Result<Statement, SyntaxError> { | ||||
|         let pos = parser.pos(); | ||||
| 
 | ||||
|         if let Some(_) = parser.expect_static("let").get() { | ||||
|         if parser.expect_static("let").get().is_some() { | ||||
|             let ident = parser | ||||
|                 .expect_ident() | ||||
|                 .get_or(SyntaxError::ExpectedIdent(pos))?; | ||||
| @ -57,7 +57,7 @@ impl Expression { | ||||
|     pub fn parse(parser: &mut Parser) -> Result<Expression, SyntaxError> { | ||||
|         let begin_pos = parser.pos(); | ||||
| 
 | ||||
|         if let Some(_) = parser.expect_static("{").get() { | ||||
|         if parser.expect_static("{").get().is_some() { | ||||
|             let mut statement_list = Vec::new(); | ||||
|             while { | ||||
|                 match Statement::parse(parser) { | ||||
| @ -68,7 +68,7 @@ impl Expression { | ||||
|                     Err(_) => false, | ||||
|                 } | ||||
|             } {} | ||||
|             if let Some(_) = parser.expect_static("}").get() { | ||||
|             if parser.expect_static("}").get().is_some() { | ||||
|                 Ok(Expression::BlockExpr(begin_pos, statement_list)) | ||||
|             } else { | ||||
|                 Err(SyntaxError::ExpectedToken(parser.pos(), '}')) | ||||
| @ -81,11 +81,7 @@ impl Expression { | ||||
|                 match Expression::parse(parser) { | ||||
|                     Ok(exp) => { | ||||
|                         arg_list.push(exp); | ||||
|                         if let Some(_) = parser.expect_static(",").get() { | ||||
|                             true | ||||
|                         } else { | ||||
|                             false | ||||
|                         } | ||||
|                         parser.expect_static(",").get().is_some() | ||||
|                     } | ||||
|                     Err(err) => { | ||||
|                         if arg_list.is_empty() { | ||||
|  | ||||
| @ -43,7 +43,7 @@ impl VirtualMachine { | ||||
|     pub fn run(&mut self) -> Result<(), RuntimePanic> { | ||||
|         let mut error = None; | ||||
|         while error.is_none() { | ||||
|             if let Some(command) = self.compiled.list.get(self.position).map(|v| v.clone()) { | ||||
|             if let Some(command) = self.compiled.list.get(self.position).cloned() { | ||||
|                 self.position += 1; | ||||
|                 if let Err(err) = self.execute(command.clone()) { | ||||
|                     error = Some(err); | ||||
| @ -140,7 +140,7 @@ impl VirtualMachine { | ||||
|             } | ||||
|             Command::StringLit(string) => { | ||||
|                 if self.stack.len() < usize::MAX { | ||||
|                     self.stack.push(Value::StringVal(string.clone())); | ||||
|                     self.stack.push(Value::StringVal(string)); | ||||
|                     //dbg!("String literal added to stack", string, &self.stack);
 | ||||
|                     Ok(()) | ||||
|                 } else { | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user