Commit 5877382e authored by Jeff Smits's avatar Jeff Smits

Pattern matching would give an exhausiveness check, but this way we can easily...

Pattern matching would give an exhausiveness check, but this way we can easily match against strings
parent 2e3fa303
......@@ -412,8 +412,7 @@ impl BuildTerm {
annos.unwrap_or_default()))
}
Explode(ref cons, ref children) => {
use aterm::Term::*;
use interpreter::{b, from_cons_nil_list};
use interpreter::from_cons_nil_list;
let cons = cons.build(context)?;
let children = children.build(context)?;
......@@ -421,27 +420,25 @@ impl BuildTerm {
from_cons_nil_list(children)
.map_err(|_| Error::UnknownBehaviour(
"Non-list in build of explode pattern (#) second argument"))?;
match b(&cons).as_inner().term {
Application(ref c, ref r) if r.is_empty() => {
let application =
context
.factory
.t_application(ctree::string_unescape(c), children.iter().cloned());
return Ok(context.factory.with_annos(application, annos.unwrap_or_default()));
}
Application(_, _) => {
return Err(Error::StrategyFailed);
}
List(_) => {
return Ok(to_cons_nil_list(context.factory, children.iter().cloned()));
}
Blob(_) | Placeholder(_) => {
return Err(Error::UnknownBehaviour("Blob or ATerm placeholder in build of \
explode pattern (#) first argument"));
}
Int(_) | Long(_) | Real(_) => {}
if let Some(string) = cons.get_string() {
let application = context.factory.t_application(string, children.iter().cloned());
Ok(context.factory.with_annos(application, annos.unwrap_or_default()))
} else if let Some(_) = cons.get_application() {
Err(Error::StrategyFailed)
} else if let Some(_) = cons.get_list() {
Ok(to_cons_nil_list(context.factory, children.iter().cloned()))
} else if let Some(_) = cons.get_blob() {
Err(Error::UnknownBehaviour("Blob in build of explode pattern (#) first \
argument"))
} else if let Some(_) = cons.get_placeholder() {
Err(Error::UnknownBehaviour("ATerm placeholder in build of explode pattern (#) \
first argument"))
} else {
// Int, Long or Real
Ok(cons)
}
Ok(cons)
}
// NOTE: `str '!((1{2}){3})'` gives `1{2}`, so the innermost `annos` list in a build is
// used! Therefore we just shadow the input `annos` with the annotations in this `Anno`
......
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