Fix some things, add debugging information etc.

This commit is contained in:
abbie 2024-08-14 23:58:22 +01:00
parent 3c5a01b558
commit 3386eb6a10
Signed by: threeoh6000
GPG key ID: 801FE4AD456E922C
3 changed files with 9 additions and 10 deletions

2
Cargo.lock generated
View file

@ -99,7 +99,7 @@ checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
[[package]]
name = "granite"
version = "1.0.1"
version = "1.0.2"
dependencies = [
"clap",
]

View file

@ -1,6 +1,6 @@
[package]
name = "granite"
version = "1.0.1"
version = "1.0.2"
edition = "2021"
[dependencies]

View file

@ -278,8 +278,7 @@ fn execute(program: Program) {
vars.insert(statement.arguments[1].clone(), "0".to_string());
}
} else {
println!("Missing variable on int check.");
exit(1);
vars.insert(statement.arguments[1].clone(), "-1".to_string());
}
} else if statement.operator == "%" {
if vars.contains_key(&statement.arguments[0]) {
@ -321,7 +320,7 @@ fn parse(data: &str) -> Result<Program, String> {
} else if program_begun {
if operator.is_none() {
let potential_argument_length = operator_to_arglength(char.clone());
if potential_argument_length.is_none() { return Err(format!("Invalid operator {}.", char)); }
if potential_argument_length.is_none() { return Err(format!("Invalid operator {} at statement {}.", char, statements.len())); }
expected_arguments = potential_argument_length.unwrap();
operator = Some(char.to_string());
} else if expected_arguments > 0 {
@ -340,15 +339,15 @@ fn parse(data: &str) -> Result<Program, String> {
expected_arguments = expected_arguments - 1;
arguments.push(argument_builder);
argument_builder = "".to_string();
} else if char == ':' {
} else if char == ':' && !inside_string {
expected_arguments = expected_arguments - 1;
arguments.push(argument_builder);
argument_builder = "".to_string();
if expected_arguments != 0 {
return Err(format!("Invalid amount of arguments for operator {}.", operator.unwrap()));
return Err(format!("Invalid amount of arguments for operator {} at {}.", operator.unwrap(), statements.len()));
}
} else if char == '"' {
if argument_builder.len() != 0 { return Err("Cannot start string where argument already exists.".to_string()); }
if argument_builder.len() != 0 { return Err(format!("Cannot start string where argument already exists at {}.", statements.len())); }
inside_string = true;
} else if char == '\n' && !inside_string {
continue;
@ -356,7 +355,7 @@ fn parse(data: &str) -> Result<Program, String> {
argument_builder = format!("{}{}", argument_builder, char);
}
}
if operator.is_some() && char == ':' {
if operator.is_some() && char == ':' && !inside_string {
let new_statement = Statement { operator: operator.clone().unwrap(), arguments: arguments.clone() };
statements.push(new_statement);
if operator.clone().unwrap() == "@" {
@ -375,7 +374,7 @@ fn parse(data: &str) -> Result<Program, String> {
}
if expected_arguments != 0 {
return Err(format!("Invalid amount of arguments for operator {}.", operator.unwrap()));
return Err(format!("Invalid amount of arguments for operator {} at {}.", operator.unwrap(), statements.len()));
}
let new_statement = Statement { operator: operator.unwrap().clone(), arguments: arguments.clone() };
statements.push(new_statement);