clippy lints and moved the operator matchbox to it's own function

This commit is contained in:
2026-05-26 11:54:53 +01:00
parent 4f7abb5f19
commit 59f32e975b
5 changed files with 30 additions and 43 deletions
+12 -14
View File
@@ -18,20 +18,18 @@ pub fn identifier_parse
) -> Result<(usize,bool),(String,usize)>
{
let mut sum_index: usize = index;
if ! variables.contains_key(identifier)
{
variables.insert(identifier.to_string(), tokenise::Value::Null);
}
let current = variables.get(identifier).unwrap().clone();
let current = variables
.entry(identifier.clone())
.or_insert(tokenise::Value::Null)
.clone();
let operator = tokenise::get_operator_token(tokens, sum_index)
.map_err(|err| (err, sum_index))?;
sum_index += 1;
let mut result = true;
match tokenise::get_value_token(tokens, sum_index)
let result: bool = match tokenise::get_value_token(tokens, sum_index)
{
Ok(value) => result = operator_match(&current,value,operator,identifier,variables),
Ok(value) => operator_match(&current,value,operator,identifier,variables),
Err(_) => todo!(),
}
};
sum_index += 1;
@@ -54,7 +52,7 @@ fn operator_match
// Changing a value
tokenise::Operator::Assignment =>
{
variables.insert(identifier.to_string(), value);
variables.insert(identifier.to_owned(), value);
} ,
tokenise::Operator::Add =>
{
@@ -62,20 +60,20 @@ fn operator_match
{
(tokenise::Value::Integer(int1),tokenise::Value::Integer(int2)) => tokenise::Value::Integer(int1 + int2),
(tokenise::Value::String(str1),tokenise::Value::String(str2)) => tokenise::Value::String(format!("{str1}{str2}")),
_ => value.clone(), // otherwise invalid
_ => value, // otherwise invalid
};
variables.insert(identifier.to_string(), result);
variables.insert(identifier.to_owned(), result);
},
tokenise::Operator::Sub =>
{
let result: tokenise::Value = match (value.clone(), current)
{
(tokenise::Value::Integer(int1),tokenise::Value::Integer(int2)) => tokenise::Value::Integer(int2 - int1),
_ => value.clone(), // otherwise invalid
_ => value, // otherwise invalid
};
variables.insert(identifier.to_string(), result);
variables.insert(identifier.to_owned(), result);
},
// TODO choice assignment
// TODO input assignment