Commit 8924d73b authored by Jeff Smits's avatar Jeff Smits

Put final MatchCons branch in hashmap

parent 928f5069
......@@ -205,7 +205,7 @@ impl Strategy {
As(_, ref t) => Self::matches_cons_preterm(&**t),
Op(ref c, ref r) if c == "Cons" && r.len() == 2 => None,
Op(ref c, ref r) if c == "Nil" && r.is_empty() => None,
Op(ref s, _) => Some(s.clone()),
OpQ(ref s, _) | Op(ref s, _) => Some(s.clone()),
Explode(Anno(ref pt,_), _) => match **pt {
Str(ref s) => Some(s.clone()),
_ => None,
......@@ -229,10 +229,15 @@ impl Strategy {
break;
}
}
let s_else: Rc<Strategy> = Rc::new(value.try_into()?);
if let Some(cons) = Self::matches_cons(&value) {
map.entry(cons).or_insert_with(Vec::new).push((value.try_into()?, Strategy::Id));
value = ctree::Strategy::Fail;
}
if map.len() == 1 {
let s_else: Rc<Strategy> = Rc::new(value.try_into()?);
Ok(map.into_iter().map(|(_,v)| O::GuardedLChoice(v.into_boxed_slice(), s_else.clone())).next().expect("build_cons_match: Map should have had at least one item"))
} else {
let s_else: Rc<Strategy> = Rc::new(value.try_into()?);
let map: FnvHashMap<String, Strategy> = map.into_iter().map(|(k, v)| (k, O::GuardedLChoice(v.into_boxed_slice(), s_else.clone()))).collect();
Ok(O::ConsMatch(map, s_else))
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment