This commit is contained in:
Simon Gardling
2022-05-04 23:43:50 -04:00
parent 5e5dd0f7a6
commit 243135b3dc
8 changed files with 47 additions and 30 deletions

View File

@@ -30,9 +30,12 @@ pub fn compile_hashmap(data: Vec<String>) -> Vec<(String, String)> {
}
seen_3.insert(key.clone());
if keys.iter().filter(|a| a == &&key).count() == 1 {
let count_keys = keys.iter().filter(|a| a == &&key).count();
if count_keys == 1 {
output.push((key.clone(), format!(r#"Hint::Single("{}")"#, value)));
} else {
} else if count_keys > 1 {
let mut multi_data = tuple_list_1
.iter()
.filter(|(a, _)| a == key)
@@ -40,6 +43,8 @@ pub fn compile_hashmap(data: Vec<String>) -> Vec<(String, String)> {
.collect::<Vec<&String>>();
multi_data.sort_unstable_by(|a, b| compare_len_reverse_alpha(a, b));
output.push((key.clone(), format!("Hint::Many(&{:?})", multi_data)));
} else {
panic!("Number of values for {key} is 0!");
}
}
output

View File

@@ -31,7 +31,9 @@ impl BackingFunction {
match &parse_result {
Err(e) => return Err(e.to_string()),
Ok(_) => {
let var_names = parse_result.as_ref().unwrap().var_names().to_vec();
let var_names = unsafe { parse_result.as_ref().unwrap_unchecked() }
.var_names()
.to_vec();
if var_names != ["x"] {
let var_names_not_x: Vec<&String> = var_names
@@ -50,7 +52,7 @@ impl BackingFunction {
}
}
}
parse_result.unwrap()
unsafe { parse_result.unwrap_unchecked() }
}
};

View File

@@ -78,9 +78,9 @@ pub fn split_function_chars(chars: &[char]) -> Vec<String> {
},
}
}
fn is_variable(&self) -> bool { self.variable && !self.masked_var }
const fn is_variable(&self) -> bool { self.variable && !self.masked_var }
fn is_number(&self) -> bool { self.number && !self.masked_num }
const fn is_number(&self) -> bool { self.number && !self.masked_num }
}
// Setup first char here
@@ -178,6 +178,10 @@ pub fn generate_hint<'a>(input: &str) -> &'a Hint<'a> {
let chars: Vec<char> = input.chars().collect::<Vec<char>>();
unsafe {
assume(!chars.is_empty());
}
let mut open_parens: usize = 0;
let mut closed_parens: usize = 0;
chars.iter().for_each(|chr| match *chr {
@@ -225,13 +229,13 @@ impl<'a> std::fmt::Debug for Hint<'a> {
}
impl<'a> Hint<'a> {
pub fn is_none(&self) -> bool { matches!(&self, &Hint::None) }
pub const fn is_none(&self) -> bool { matches!(&self, &Hint::None) }
#[allow(dead_code)]
pub fn is_some(&self) -> bool { !self.is_none() }
pub const fn is_some(&self) -> bool { !self.is_none() }
#[allow(dead_code)]
pub fn is_single(&self) -> bool { matches!(&self, &Hint::Single(_)) }
pub const fn is_single(&self) -> bool { matches!(&self, &Hint::Single(_)) }
}
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));