Commit 95626e54 authored by Jeff Smits's avatar Jeff Smits

Fixed all/some/one

parent 948a2b42
......@@ -239,9 +239,9 @@ impl<'d, 'f : 'd> Eval<'d, 'f> for preprocess::Strategy {
.collect::<Result<_>>()?;
context.call_primitive(name, sargs, targs, current)
}
Some(ref strat) => eval_some(strat, context, current),
One(ref strat) => eval_one(strat, context, current),
All(ref strat) => eval_all(strat, context, current),
Some(ref strat) => eval_(strat, context, current, some_rec, |_| Err(Error::StrategyFailed)),
One(ref strat) => eval_(strat, context, current, one_rec, |_| Err(Error::StrategyFailed)),
All(ref strat) => eval_(strat, context, current, all_rec, Ok),
ImportTerm(ref modname) => {
// This primitive really is interwoven with SSL :(
use primitives::ssl;
......@@ -379,67 +379,48 @@ fn eval_match<'d, 'f : 'd>(
}
}
fn eval_<'d, 'f : 'd, F>(
fn eval_<'d, 'f : 'd, F1, F2>(
strat: &'d preprocess::Strategy,
context: &MutContext<'d, 'f>,
current: ATermRef<'f>,
fun: F,
children_fun: F1,
self_fun: F2,
) -> Result<ATermRef<'f>>
where
F: Fn(&Box<[ATermRef<'f>]>, &'d preprocess::Strategy, &MutContext<'d, 'f>) -> Result<Box<[ATermRef<'f>]>>
F1: Fn(&Box<[ATermRef<'f>]>, &'d preprocess::Strategy, &MutContext<'d, 'f>) -> Result<Box<[ATermRef<'f>]>>,
F2: Fn(ATermRef<'f>) -> Result<ATermRef<'f>>
{
use factory::Term::*;
let annos = current.get_annotations();
match current.term {
Application(ref name, ref r) => {
fun(r, strat, context)
.map(|r| context.factory.application(name.clone(), r.iter().cloned()))
.map(|t| {
context.factory.with_annos(t, annos.into_iter().cloned())
})
}
List(ref r) => {
fun(&r.iter().collect::<Vec<_>>().into_boxed_slice(), strat, context).map(|r| context.factory.list(r.iter().cloned())).map(|t| {
context.factory.with_annos(t, annos.into_iter().cloned())
})
}
Placeholder(_, ref r) => {
fun(&vec![r.clone()].into_boxed_slice(), strat, context)
.map(|p| {
debug_assert!(p.len() == 1);
context.factory.stratego_placeholder(p[0].clone())
})
.map(|t| {
context.factory.with_annos(t, annos.into_iter().cloned())
})
{
let annos = current.get_annotations();
match current.term {
Application(ref name, ref r) => {
return children_fun(r, strat, context)
.map(|r| context.factory.application(name.clone(), r.iter().cloned()))
.map(|t| {
context.factory.with_annos(t, annos.into_iter().cloned())
})
}
List(ref r) => {
return children_fun(&r.iter().collect::<Vec<_>>().into_boxed_slice(), strat, context)
.map(|r| context.factory.list(r.iter().cloned()))
.map(|t| context.factory.with_annos(t, annos.into_iter().cloned()))
}
Placeholder(_, ref r) => {
return children_fun(&vec![r.clone()].into_boxed_slice(), strat, context)
.map(|p| {
debug_assert!(p.len() == 1);
context.factory.stratego_placeholder(p[0].clone())
})
.map(|t| {
context.factory.with_annos(t, annos.into_iter().cloned())
})
}
Int(_) | Long(_) | Real(_) | String(_) | Blob(_) => {},
}
Int(_) | Long(_) | Real(_) | String(_) | Blob(_) => Err(Error::StrategyFailed),
}
}
fn eval_one<'d, 'f : 'd>(
strat: &'d preprocess::Strategy,
context: &MutContext<'d, 'f>,
current: ATermRef<'f>,
) -> Result<ATermRef<'f>> {
eval_(strat, context, current, one_rec)
}
fn eval_some<'d, 'f : 'd>(
strat: &'d preprocess::Strategy,
context: &MutContext<'d, 'f>,
current: ATermRef<'f>,
) -> Result<ATermRef<'f>> {
eval_(strat, context, current, some_rec)
}
fn eval_all<'d, 'f : 'd>(
strat: &'d preprocess::Strategy,
context: &MutContext<'d, 'f>,
current: ATermRef<'f>,
) -> Result<ATermRef<'f>> {
eval_(strat, context, current, all_rec)
self_fun(current)
}
fn one_rec<'d, 'f : 'd>(
......
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