Fix variable scoping issues.

This commit is contained in:
abbie 2024-08-21 21:56:44 +01:00
parent 95eeeb6ec7
commit 1a345d4693
Signed by: threeoh6000
GPG key ID: 801FE4AD456E922C

View file

@ -46,6 +46,7 @@ pub fn parse(data: &str) -> Result<Program, String> {
let mut argument_builder: String = "".to_string(); let mut argument_builder: String = "".to_string();
let mut statements: Vec<Statement> = vec![]; let mut statements: Vec<Statement> = vec![];
let mut labels: HashMap<String, usize> = HashMap::new(); let mut labels: HashMap<String, usize> = HashMap::new();
let mut potential_argument_length;
let mut inside_string = false; let mut inside_string = false;
let mut string_escape = false; let mut string_escape = false;
@ -55,7 +56,7 @@ pub fn parse(data: &str) -> Result<Program, String> {
program_begun = true; program_begun = true;
} else if program_begun { } else if program_begun {
if operator.is_none() { if operator.is_none() {
let (operator, potential_argument_length) = operator_to_arglength(char.clone()); (operator, potential_argument_length) = operator_to_arglength(char.clone());
if potential_argument_length.is_none() { return Err(format!("Invalid operator {} at statement {}.", char, statements.len())); } 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();
} else if expected_arguments > 0 { } else if expected_arguments > 0 {