Fix some things, add debugging information etc.
This commit is contained in:
parent
3c5a01b558
commit
3386eb6a10
3 changed files with 9 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -99,7 +99,7 @@ checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "granite"
|
name = "granite"
|
||||||
version = "1.0.1"
|
version = "1.0.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "granite"
|
name = "granite"
|
||||||
version = "1.0.1"
|
version = "1.0.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -278,8 +278,7 @@ fn execute(program: Program) {
|
||||||
vars.insert(statement.arguments[1].clone(), "0".to_string());
|
vars.insert(statement.arguments[1].clone(), "0".to_string());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("Missing variable on int check.");
|
vars.insert(statement.arguments[1].clone(), "-1".to_string());
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
} else if statement.operator == "%" {
|
} else if statement.operator == "%" {
|
||||||
if vars.contains_key(&statement.arguments[0]) {
|
if vars.contains_key(&statement.arguments[0]) {
|
||||||
|
@ -321,7 +320,7 @@ fn parse(data: &str) -> Result<Program, String> {
|
||||||
} else if program_begun {
|
} else if program_begun {
|
||||||
if operator.is_none() {
|
if operator.is_none() {
|
||||||
let potential_argument_length = operator_to_arglength(char.clone());
|
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();
|
expected_arguments = potential_argument_length.unwrap();
|
||||||
operator = Some(char.to_string());
|
operator = Some(char.to_string());
|
||||||
} else if expected_arguments > 0 {
|
} else if expected_arguments > 0 {
|
||||||
|
@ -340,15 +339,15 @@ fn parse(data: &str) -> Result<Program, String> {
|
||||||
expected_arguments = expected_arguments - 1;
|
expected_arguments = expected_arguments - 1;
|
||||||
arguments.push(argument_builder);
|
arguments.push(argument_builder);
|
||||||
argument_builder = "".to_string();
|
argument_builder = "".to_string();
|
||||||
} else if char == ':' {
|
} else if char == ':' && !inside_string {
|
||||||
expected_arguments = expected_arguments - 1;
|
expected_arguments = expected_arguments - 1;
|
||||||
arguments.push(argument_builder);
|
arguments.push(argument_builder);
|
||||||
argument_builder = "".to_string();
|
argument_builder = "".to_string();
|
||||||
if expected_arguments != 0 {
|
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 == '"' {
|
} 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;
|
inside_string = true;
|
||||||
} else if char == '\n' && !inside_string {
|
} else if char == '\n' && !inside_string {
|
||||||
continue;
|
continue;
|
||||||
|
@ -356,7 +355,7 @@ fn parse(data: &str) -> Result<Program, String> {
|
||||||
argument_builder = format!("{}{}", argument_builder, char);
|
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() };
|
let new_statement = Statement { operator: operator.clone().unwrap(), arguments: arguments.clone() };
|
||||||
statements.push(new_statement);
|
statements.push(new_statement);
|
||||||
if operator.clone().unwrap() == "@" {
|
if operator.clone().unwrap() == "@" {
|
||||||
|
@ -375,7 +374,7 @@ fn parse(data: &str) -> Result<Program, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if expected_arguments != 0 {
|
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() };
|
let new_statement = Statement { operator: operator.unwrap().clone(), arguments: arguments.clone() };
|
||||||
statements.push(new_statement);
|
statements.push(new_statement);
|
||||||
|
|
Loading…
Reference in a new issue