From 3386eb6a1074e761cbf84bfad093a0737921269d Mon Sep 17 00:00:00 2001 From: threeoh6000 Date: Wed, 14 Aug 2024 23:58:22 +0100 Subject: [PATCH] Fix some things, add debugging information etc. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9503659..856c88f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,7 +99,7 @@ checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "granite" -version = "1.0.1" +version = "1.0.2" dependencies = [ "clap", ] diff --git a/Cargo.toml b/Cargo.toml index 9a59bdf..9aeb7e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "granite" -version = "1.0.1" +version = "1.0.2" edition = "2021" [dependencies] diff --git a/src/main.rs b/src/main.rs index 6fcd551..6bf7281 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { } 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 { 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 { 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 { } 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);