diff --git a/src/ast.rs b/src/ast.rs index e1e69e5..fb5069d 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -320,7 +320,11 @@ impl foliage::flavor::VariableDeclaration for VariableDeclaration None => unreachable!("all variable IDs should be assigned at this point"), }; - write!(formatter, "{}{}", variable_name_prefix, variable_id + 1) + match variable_id + { + 0 => write!(formatter, "{}", variable_name_prefix), + _ => write!(formatter, "{}{}", variable_name_prefix, variable_id), + } }, } } diff --git a/src/utils/autoname_variables.rs b/src/utils/autoname_variables.rs index e3ce754..9672c24 100644 --- a/src/utils/autoname_variables.rs +++ b/src/utils/autoname_variables.rs @@ -10,8 +10,8 @@ impl IDs { Self { - program_variable_id: 0, - integer_variable_id: 0, + program_variable_id: 1, + integer_variable_id: 1, } } } @@ -218,6 +218,29 @@ fn set_variable_names_in_formula(formula: &mut crate::Formula, ids: &mut IDs) pub(crate) fn autoname_variables(formula: &mut crate::Formula) { + // TODO: refactor, this is a bit hacky reset_variable_names_in_formula(formula); - set_variable_names_in_formula(formula, &mut IDs::new()); + + let mut ids = IDs::new(); + + set_variable_names_in_formula(formula, &mut ids); + + // If there only exists exactly one program variable (which incremented the ID from 1 to 2), + // give it the special ID 0 on the second run + ids.program_variable_id = match ids.program_variable_id + { + 2 => 0, + _ => 1, + }; + + // If there only exists exactly one integer variable (which incremented the ID from 1 to 2), + // give it the special ID 0 on the second run + ids.integer_variable_id = match ids.integer_variable_id + { + 2 => 0, + _ => 1, + }; + + reset_variable_names_in_formula(formula); + set_variable_names_in_formula(formula, &mut ids); }