Commit c128b076 authored by Jeff Smits's avatar Jeff Smits

Fixed another bug: building things may have a variable instead of a literal list

parent cd3d8b7c
......@@ -387,13 +387,13 @@ impl BuildTerm {
// NOTE: `str '!((1{2}){3})'` gives `1{2}`, so the innermost `annos` list in a build is
// used!
Anno(ref term, ref annos) => {
let annos: &BuildTerm = &(**annos).clone().into();
let term = &(**term).clone();
if let Some(annos) = annos.build_list(context)? {
term.build_with_annos(context, annos)
use interpreter::from_cons_nil_list;
// TODO: specialise annos case of list literal again, but note that's not the only case!
let annos: ATermRef = (**annos).build(context)?;
if let Ok(annos_vec) = from_cons_nil_list(annos.clone()) {
term.build_with_annos(context, annos_vec)
} else {
let anno = annos.build(context)?;
term.build_with_annos(context, iter::once(anno))
term.build_with_annos(context, iter::once(annos))
}
}
}
......@@ -404,25 +404,6 @@ impl BuildTerm {
vec.into_iter().map(|t| t.build(context)).collect()
}
/// Takes a `BuildTerm` and tries to find `Op("Cons", ...)` and `Op("Nil",[])` to build
/// a `Term::List`. Fails if it's something else.
fn build_list<'a>(&self, context: &MutContext<'a>) -> Result<Option<Vec<ATermRef>>> {
let mut term = self;
use self::BuildTerm::Op;
let mut result = Vec::new();
while let Op(ref c, ref r) = *term {
if c == "Nil" && r.is_empty() {
return Ok(Some(result));
} else if c == "Cons" && r.len() == 2 {
result.push(r[0].build(context)?);
term = &r[1];
} else {
break;
}
}
Ok(None)
}
#[allow(dead_code)]
pub fn build_static(&self, f: &ATermFactory) -> Result<ATermRef> {
use context::StackTracer;
......
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