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