Commit 8418db1e authored by Jeff Smits's avatar Jeff Smits

cargo fmt

parent 39f8cb86
......@@ -13,7 +13,7 @@ use std::cell::RefCell;
/// This context is internally mutable in `RefCell` fields. This is just for convenience as we don't
/// want to pass around the mutable fields separately. But the internal mutability is not a hidden
/// thing, there is observable effect, so the name of the context includes `Mut`.
pub struct MutContext<'d, 'f : 'd> {
pub struct MutContext<'d, 'f: 'd> {
pub stack_tracer: RefCell<StackTracer<'f>>,
pub scopes: RefCell<Vec<Scope<'d, 'f, ATermRef<'f>>>>,
pub factory: &'f ATermFactory,
......@@ -21,7 +21,7 @@ pub struct MutContext<'d, 'f : 'd> {
pub ssl_state: RefCell<State<'f>>,
}
impl<'d, 'f : 'd> MutContext<'d, 'f> {
impl<'d, 'f: 'd> MutContext<'d, 'f> {
pub fn new(
factory: &'f ATermFactory,
scopes: Vec<Scope<'d, 'f, ATermRef<'f>>>,
......@@ -72,9 +72,8 @@ impl<'d, 'f : 'd> MutContext<'d, 'f> {
}
pub fn get_term(&self, term_name: &str) -> Result<ATermRef<'f>> {
Scopes::get_term_option(&self.scopes.borrow(), term_name).and_then(|(_, o)| {
o.ok_or(Error::StrategyFailed)
})
Scopes::get_term_option(&self.scopes.borrow(), term_name)
.and_then(|(_, o)| o.ok_or(Error::StrategyFailed))
}
pub fn match_term(&self, term_name: &'f str, current: &ATermRef<'f>) -> Result<()> {
......@@ -144,8 +143,8 @@ impl<'d, 'f : 'd> MutContext<'d, 'f> {
"clear_overlay: Interpreter bug, unexpected end of stack",
);
debug_assert!(
last_scope.is_overlay,
"clear_overlay: Interpreter bug, unexpected normal scope"
last_scope.is_overlay,
"clear_overlay: Interpreter bug, unexpected normal scope"
);
last_scope.term.clear();
}
......@@ -236,12 +235,14 @@ impl<'d, 'f: 'd, ATerm> Scope<'d, 'f, ATerm> {
pub fn from_let_defs<I>(no_of_scopes: usize, defs: I) -> Self
where
I: IntoIterator<Item=&'d Def<'f>>,
I: IntoIterator<Item = &'d Def<'f>>,
{
Scope {
term: FnvHashMap::default(),
strategy: defs.into_iter()
.map(|def| (def.name, StrategyDef::from_let_def(def, no_of_scopes)))
.map(|def| {
(def.name, StrategyDef::from_let_def(def, no_of_scopes))
})
.collect(),
is_overlay: false,
}
......@@ -252,7 +253,10 @@ impl<'d, 'f: 'd, ATerm> Scope<'d, 'f, ATerm> {
I: IntoIterator<Item = &'f str>,
{
Scope {
term: fresh_vars.into_iter().map(|fresh_var| (fresh_var, None)).collect(),
term: fresh_vars
.into_iter()
.map(|fresh_var| (fresh_var, None))
.collect(),
strategy: FnvHashMap::default(),
is_overlay: false,
}
......@@ -268,13 +272,13 @@ pub mod Scopes {
term_name: &str,
) -> Result<(usize, Option<ATermRef<'f>>)> {
let mut offset = None;
for (n,scope) in scopes.iter().enumerate().rev() {
for (n, scope) in scopes.iter().enumerate().rev() {
if offset == None && scope.is_overlay {
offset = Some(n);
}
if let Some(binding) = scope.term.get(term_name) {
let n = offset.unwrap_or(n);
return Ok((n, binding.clone()))
return Ok((n, binding.clone()));
}
}
Err(Error::UndefinedVariable(term_name.to_owned()))
......@@ -297,11 +301,11 @@ pub mod Scopes {
(n, None) => {
if let Some(Some(t)) = scopes[n].term.insert(term_name, Some(current.clone())) {
unreachable!(format!(
"match_term: No scope had {}, but we just \
"match_term: No scope had {}, but we just \
replaced {} when we added it?!",
term_name,
t
))
term_name,
t
))
} else {
return Ok(());
}
......
......@@ -49,8 +49,7 @@ impl<'s> fmt::Display for Module<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Module<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Module<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -112,8 +111,7 @@ impl<'s> fmt::Display for Decl<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Decl<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Decl<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -157,8 +155,7 @@ impl<'s> fmt::Display for ImportModName<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for ImportModName<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for ImportModName<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -210,8 +207,7 @@ impl<'s> fmt::Display for SDecl<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for SDecl<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for SDecl<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -245,12 +241,8 @@ impl<'s> fmt::Display for Sort<'s> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Sort::*;
match *self {
SortVar(ref lcid) => {
lcid.fmt(f)
}
SortNoArgs(ref ucid) => {
ucid.fmt(f)
}
SortVar(ref lcid) => lcid.fmt(f),
SortNoArgs(ref ucid) => ucid.fmt(f),
Sort(ref id, ref sorts) => {
write!(f, "{}(", id)?;
for sort in sorts.iter() {
......@@ -262,8 +254,7 @@ impl<'s> fmt::Display for Sort<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Sort<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Sort<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -307,25 +298,16 @@ impl<'s> fmt::Display for OpDecl<'s> {
use self::OpDecl::*;
match *self {
OpDecl(ref s, ref ty) |
OpDeclQ(ref s, ref ty) => {
writeln!(f, "{}: {}", s, ty)
}
OpDeclInj(ref ty) => {
writeln!(f, ": {}", ty)
}
OpDeclQ(ref s, ref ty) => writeln!(f, "{}: {}", s, ty),
OpDeclInj(ref ty) => writeln!(f, ": {}", ty),
ExtOpDecl(ref s, ref ty) |
ExtOpDeclQ(ref s, ref ty) => {
writeln!(f, "external {}: {}", s, ty)
}
ExtOpDeclInj(ref ty) => {
writeln!(f, "external : {}", ty)
}
ExtOpDeclQ(ref s, ref ty) => writeln!(f, "external {}: {}", s, ty),
ExtOpDeclInj(ref ty) => writeln!(f, "external : {}", ty),
}
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for OpDecl<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for OpDecl<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -382,8 +364,7 @@ impl<'s> fmt::Display for ConstType<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for ConstType<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for ConstType<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -417,15 +398,12 @@ impl<'s> fmt::Display for Type<'s> {
}
write!(f, "-> {}", rettype)
}
ConstType(ref sort) => {
sort.fmt(f)
}
ConstType(ref sort) => sort.fmt(f),
}
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Type<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Type<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -471,7 +449,7 @@ impl<'s> fmt::Display for Def<'s> {
write!(f, "{}, ", vardec)?;
}
write!(f, ") =\n {}", strategy)
},
}
ExtSDefInl(ref id, ref vardecs1, ref vardecs2, ref strategy) => {
write!(f, "external {}(", id)?;
for vardec in vardecs1 {
......@@ -508,8 +486,7 @@ impl<'s> fmt::Display for Def<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Def<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Def<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -569,8 +546,7 @@ impl<'s> fmt::Display for SVar<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for SVar<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for SVar<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -607,7 +583,7 @@ impl<'s> fmt::Display for StrategyDef<'s> {
write!(f, "{}, ", vardec)?;
}
write!(f, ") =\n {}", strategy)
},
}
ExtSDefInl(ref id, ref vardecs1, ref vardecs2, ref strategy) => {
write!(f, "external {}(", id)?;
for vardec in vardecs1 {
......@@ -638,8 +614,7 @@ impl<'s> fmt::Display for StrategyDef<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for StrategyDef<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for StrategyDef<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -716,8 +691,7 @@ impl fmt::Display for Anno {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Anno
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Anno {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -755,8 +729,7 @@ impl<'s> fmt::Display for VarDec<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for VarDec<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for VarDec<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -851,7 +824,9 @@ impl<'s> fmt::Display for Strategy<'s> {
write!(f, " : {} }}", strategy)
}
Seq(ref first, ref second) => write!(f, "{}; {}", first, second),
GuardedLChoice(ref s_if, ref s_then, ref s_else) => write!(f, "{} < {} + {}", s_if, s_then, s_else),
GuardedLChoice(ref s_if, ref s_then, ref s_else) => {
write!(f, "{} < {} + {}", s_if, s_then, s_else)
}
PrimT(ref string, ref strategies, ref terms) => {
write!(f, "prim({},", string)?;
for strategy in strategies.iter() {
......@@ -871,8 +846,7 @@ impl<'s> fmt::Display for Strategy<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Strategy<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Strategy<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -1006,8 +980,7 @@ impl<'s> fmt::Display for Var<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Var<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Var<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -1043,8 +1016,7 @@ impl<'s> fmt::Display for Term<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Term<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Term<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -1116,8 +1088,7 @@ impl<'s> fmt::Display for PreTerm<'s> {
}
}
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for PreTerm<'s>
{
impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for PreTerm<'s> {
type Err = Error;
fn try_from(value: &'a ATermRef<'s>) -> Result<Self, Self::Err> {
......@@ -1188,7 +1159,7 @@ impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for PreTerm<'s>
fn match_string<'s>(r: &ATermRef<'s>) -> Result<&'s str, Error> {
if let FTerm::String(str) = r.term {
return Ok(str)
return Ok(str);
}
Err(Error::CTreeParse("string"))
}
......
......@@ -22,7 +22,10 @@ pub struct IndexedSet<'s>(FnvHashMap<ATermRef<'s>, u16>, u16);
impl<'s> IndexedSet<'s> {
pub fn with_capacity(capacity: usize) -> Self {
IndexedSet(FnvHashMap::with_capacity_and_hasher(capacity, ::fnv::FnvBuildHasher::default()), 0)
IndexedSet(
FnvHashMap::with_capacity_and_hasher(capacity, ::fnv::FnvBuildHasher::default()),
0,
)
}
pub fn clear(&mut self) {
......@@ -144,10 +147,12 @@ impl<'s> TermList<'s> {
fn from_iter<T>(iter: T) -> Self
where
T: IntoIterator<Item=ATermRef<'s>>,
T: IntoIterator<Item = ATermRef<'s>>,
<T as IntoIterator>::IntoIter: DoubleEndedIterator,
{
iter.into_iter().rev().fold(TermList::Nil, |list, item| TermList::Cons(item, Rc::new(list)))
iter.into_iter().rev().fold(TermList::Nil, |list, item| {
TermList::Cons(item, Rc::new(list))
})
}
}
......@@ -156,9 +161,7 @@ impl<'s> IntoIterator for TermList<'s> {
type IntoIter = TermListIterator<'s>;
fn into_iter(self) -> Self::IntoIter {
TermListIterator {
listterm: Rc::new(self),
}
TermListIterator { listterm: Rc::new(self) }
}
}
......@@ -182,7 +185,7 @@ impl<'s> Iterator for TermListIterator<'s> {
let (h, t) = if let Cons(ref h, ref t) = *self.listterm {
(h.clone(), t.clone())
} else {
return None
return None;
};
self.listterm = t;
......@@ -213,12 +216,8 @@ impl<'s, B: PartialEq> PartialEq for Term<'s, B> {
(&Int(l), &Int(r)) => l == r,
(&Long(l), &Long(r)) => l == r,
(&Real(l), &Real(r)) => l == r,
(&Application(lc, ref lch), &Application(rc, ref rch)) => {
ptr::eq(lc, rc) && lch == rch
}
(&String(lc), &String(rc)) => {
ptr::eq(lc, rc)
}
(&Application(lc, ref lch), &Application(rc, ref rch)) => ptr::eq(lc, rc) && lch == rch,
(&String(lc), &String(rc)) => ptr::eq(lc, rc),
(&List(ref l), &List(ref r)) => l == r,
(&Placeholder(_, ref l), &Placeholder(_, ref r)) => l == r,
(&Blob(ref l), &Blob(ref r)) => l == r,
......@@ -239,7 +238,7 @@ where
Long(l) => write!(writer, "{}", l),
Real(BrokenF32(r)) => write!(writer, "{}", r),
Application(cons, ref children) => {
// write!(writer, "{:p}#{}", cons, cons)?;
// write!(writer, "{:p}#{}", cons, cons)?;
writer.write_str(cons)?;
if !children.is_empty() {
write!(writer, "(")?;
......@@ -249,7 +248,7 @@ where
Ok(())
}
String(string) => {
// write!(writer, "{:p}#{:?}", string, string)
// write!(writer, "{:p}#{:?}", string, string)
write!(writer, "{:?}", string)
}
List(ref l) => {
......@@ -261,7 +260,7 @@ where
write!(writer, "<")?;
tp.to_ascii(writer)?;
write!(writer, ">")
},
}
Blob(ref b) => b.to_ascii(writer),
}
}
......@@ -297,8 +296,7 @@ impl<'s> Hash for ATerm<'s> {
}
}
impl<'s> ATermWrite for ATerm<'s>
{
impl<'s> ATermWrite for ATerm<'s> {
fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result {
let annotations = &self.annotations;
self.term.to_ascii(writer)?;
......@@ -322,7 +320,7 @@ impl<'s> ATerm<'s> {
ATerm {
term: term,
annotations: Box::new([]),
attachments: RefCell::new(Vec::new())
attachments: RefCell::new(Vec::new()),
}
}
......@@ -340,7 +338,7 @@ impl<'s> ATerm<'s> {
pub fn with_annos_attachments<A, I>(term: Term<'s, Blob<'s>>, annos: A, attachments: I) -> Self
where
A: IntoIterator<Item = ATermRef<'s>>,
I: IntoIterator<Item=Attachment>,
I: IntoIterator<Item = Attachment>,
{
ATerm {
term: term,
......@@ -363,8 +361,8 @@ impl<'s> ATerm<'s> {
#[allow(dead_code)]
pub fn set_attachments<I>(&self, attachments: I)
where
I: IntoIterator<Item=Attachment>,
where
I: IntoIterator<Item = Attachment>,
{
*self.attachments.borrow_mut() = attachments.into_iter().collect();
}
......@@ -452,15 +450,15 @@ pub struct ATermFactory {
impl ATermFactory {
pub fn new() -> Self {
ATermFactory {
string_cache: RefCell::new(StringShare::new()),
}
ATermFactory { string_cache: RefCell::new(StringShare::new()) }
}
}
impl<'s> ATermFactory {
pub fn cons(&'s self, head: ATermRef<'s>, tail: Rc<TermList<'s>>) -> ATermRef<'s> {
Rc::new(ATerm::no_annos(Term::List(Rc::new(TermList::Cons(head, tail)))))
Rc::new(ATerm::no_annos(
Term::List(Rc::new(TermList::Cons(head, tail))),
))
}
pub fn nil(&'s self) -> ATermRef<'s> {
......@@ -471,16 +469,27 @@ impl<'s> ATermFactory {
Rc::new(ATerm::no_annos(Term::List(list)))
}
pub fn with_annos_attachments<I, A>(&'s self, aterm: ATermRef<'s>, annos: A, attachments: I) -> ATermRef<'s>
pub fn with_annos_attachments<I, A>(
&'s self,
aterm: ATermRef<'s>,
annos: A,
attachments: I,
) -> ATermRef<'s>
where
A: IntoIterator<Item=ATermRef<'s>>,
I: IntoIterator<Item=Attachment>,
A: IntoIterator<Item = ATermRef<'s>>,
I: IntoIterator<Item = Attachment>,
{
Rc::new(ATerm::with_annos_attachments(aterm.term.clone(), annos, attachments))
Rc::new(ATerm::with_annos_attachments(
aterm.term.clone(),
annos,
attachments,
))
}
pub fn stratego_placeholder(&'s self, term: ATermRef<'s>) -> ATermRef<'s> {
Rc::new(ATerm::no_annos(Term::Placeholder(aterm::TermPlaceholder::Term, term)))
Rc::new(ATerm::no_annos(
Term::Placeholder(aterm::TermPlaceholder::Term, term),
))
}
pub fn intern_string<S>(&'s self, string: S) -> &'s str
......@@ -505,9 +514,9 @@ impl<'s> aterm::ATermFactory<'s> for ATermFactory {
type ATermRef = ATermRef<'s>;
fn application<I, S>(&'s self, constructor: S, children: I) -> Self::ATermRef
where
I: IntoIterator<Item = Self::ATermRef>,
S: Into<Cow<'s, str>>,
where
I: IntoIterator<Item = Self::ATermRef>,
S: Into<Cow<'s, str>>,
{
use self::Term::Application;
......@@ -519,8 +528,8 @@ impl<'s> aterm::ATermFactory<'s> for ATermFactory {
}
fn with_annos<A>(&'s self, term: Self::ATermRef, annos: A) -> Self::ATermRef
where
A: IntoIterator<Item = Self::ATermRef>,
where
A: IntoIterator<Item = Self::ATermRef>,
{
Rc::new(ATerm::with_annos(term.term.clone(), annos))
}
......@@ -530,16 +539,16 @@ impl<'s> aterm::ATermFactory<'s> for ATermFactory {
}
fn string<S>(&'s self, value: S) -> Self::ATermRef
where
S: Into<Cow<'s, str>>,
where
S: Into<Cow<'s, str>>,
{
let string = self.intern_string(value);
Rc::new(ATerm::no_annos(Term::String(string)))
}
fn tuple<I>(&'s self, children: I) -> Self::ATermRef
where
I: IntoIterator<Item = Self::ATermRef>,
where
I: IntoIterator<Item = Self::ATermRef>,
{
self.application(String::new(), children)
}
......@@ -549,17 +558,20 @@ impl<'s> aterm::ATermFactory<'s> for ATermFactory {
}
fn list<I>(&'s self, value: I) -> Self::ATermRef
where
I: IntoIterator<Item = Self::ATermRef>,
where
I: IntoIterator<Item = Self::ATermRef>,
{
let vec: Vec<_> = value.into_iter().collect();
Rc::new(ATerm::no_annos(Term::List(
Rc::new(TermList::from_iter(vec.into_iter())),
)))
Rc::new(ATerm::no_annos(
Term::List(Rc::new(TermList::from_iter(vec.into_iter()))),
))
}
fn placeholder(&'s self, value: aterm::TermPlaceholder<Self::ATermRef>) -> Self::ATermRef {
Rc::new(ATerm::no_annos(Term::Placeholder(aterm::TermPlaceholder::Term, value.to_template(self))))
Rc::new(ATerm::no_annos(Term::Placeholder(
aterm::TermPlaceholder::Term,
value.to_template(self),
)))
}
fn blob(&'s self, value: <Self::ATerm as aterm::ATerm<'s>>::Blob) -> Self::ATermRef {
......
......@@ -108,12 +108,20 @@ pub fn interpret<'f>(
context.push_scope(Scope::from_defs(&program));
let main = match context.get_strategy(strategy) {
Ok(v) => v,
Err(e) => return Err(TracedError(e, context.stack_tracer.into_inner().to_string())),
Err(e) => {
return Err(TracedError(
e,
context.stack_tracer.into_inner().to_string(),
))
}
};
let result = eval_sdef(&main, &context, Vec::new(), Vec::new(), input);
match result {
Ok(v) => Ok(v),
Err(e) => Err(TracedError(e, context.stack_tracer.into_inner().to_string())),
Err(e) => Err(TracedError(
e,
context.stack_tracer.into_inner().to_string(),
)),
}
}
......@@ -121,7 +129,7 @@ pub trait Eval<'d, 'f> {
fn eval(&'d self, context: &MutContext<'d, 'f>, current: ATermRef<'f>) -> Result<ATermRef<'f>>;
}
impl<'d, 'f : 'd> Eval<'d, 'f> for preprocess::Strategy<'f> {
impl<'d, 'f: 'd> Eval<'d, 'f> for preprocess::Strategy<'f> {
fn eval(&'d self, context: &MutContext<'d, 'f>, current: ATermRef<'f>) -> Result<ATermRef<'f>> {
use preprocess::Strategy::*;
use context;
......@@ -187,7 +195,9 @@ impl<'d, 'f : 'd> Eval<'d, 'f> for preprocess::Strategy<'f> {
}
Build(ref term) => term.build(context),
Scope(ref fresh_names, ref body) => {
context.push_scope(context::Scope::from_fresh_variables(fresh_names.iter().cloned()));
context.push_scope(context::Scope::from_fresh_variables(
fresh_names.iter().cloned(),
));
let result = body.eval(context, current);
context.pop_scope();
result
......@@ -220,7 +230,9 @@ impl<'d, 'f : 'd> Eval<'d, 'f> for preprocess::Strategy<'f> {
s_else.eval(context, current)
}
ConsMatch(ref map, ref s_else) => {
let matching_arm = current.get_application().and_then(|(cons, _)| map.get(cons));
let matching_arm = current.get_application().and_then(
|(cons, _)| map.get(cons),
);
if let Option::Some(s_match) = matching_arm {
s_match.eval(context, current.clone())
} else {
......@@ -239,8 +251,24 @@ impl<'d, 'f : 'd> Eval<'d, 'f> for preprocess::Strategy<'f> {
.collect::<Result<_>>()?;
context.call_primitive(name, sargs, targs, 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)),
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 :(
......@@ -260,7 +288,7 @@ impl<'d, 'f : 'd> Eval<'d, 'f> for preprocess::Strategy<'f> {
}
}
fn eval_match<'d, 'f : 'd>(
fn eval_match<'d, 'f: 'd>(
context: &MutContext<'d, 'f>,
match_term: &'d preprocess::MatchTerm<'f>,
current: &ATermRef<'f>,
......@@ -356,11 +384,7 @@ fn eval_match<'d, 'f : 'd>(
}
List(ref list) => {
eval_match(context, cons, &context.factory.nil())?;
eval_match(
context,
children,
&context.factory.list_term(list.clone()),
)?;
eval_match(context, children, &context.factory.list_term(list.clone()))?;
}
Blob(_) => return Err(Error::StrategyFailed),
Placeholder(_, ref t) => {
......@@ -383,7 +407,7 @@ fn eval_match<'d, 'f : 'd>(
}
}
fn eval_<'d, 'f : 'd, F1, F2>(
fn eval_<'d, 'f: 'd, F1, F2>(
strat: &'d preprocess::Strategy<'f>,
context: &MutContext<'d, 'f>,
current: ATermRef<'f>,
......@@ -391,8 +415,11 @@ fn eval_<'d, 'f : 'd, F1, F2>(
self_fun: F2,
) -> Result<ATermRef<'f>>
where
F1: Fn(&Box<[ATermRef<'f>]>, &'d preprocess::Strategy<'f>, &MutContext<'d, 'f>) -> Result<Box<[ATermRef<'f>]>>,
F2: Fn(ATermRef<'f>) -> Result<ATermRef<'f>>
F1: Fn(&Box<[ATermRef<'f>]>,
&'d preprocess::Strategy<'f>,
&MutContext<'d, 'f>)
-> Result<Box<[ATermRef<'f>]>>,
F2: Fn(ATermRef<'f>) -> Result<ATermRef<'f>>,
{
use factory::Term::*;
......@@ -401,15 +428,22 @@ where
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(|r| {
context.factory.application(name.clone(), r.iter().cloned())
})
.map(|t| {
context.factory.with_annos(t, annos.into_iter().cloned())
})
}