Commit ef2caae1 authored by Jeff Smits's avatar Jeff Smits

Fix explode pattern match/build for strings

parent ddae2cc4
......@@ -1222,6 +1222,7 @@ where
}
// This function seems more complicated than necessary... Not sure how to simplify though
// TODO: truncate string when containing unescaped double quote (")
pub fn string_unescape(string: &str) -> String {
let mut result = String::with_capacity(string.len() - 2);
// copy marks the next chunk to be copied without special handling
......
......@@ -369,7 +369,11 @@ fn eval_match<'d, 'f : 'd>(
eval_match(context, cons, current_cons)?;
eval_match(context, children, current_children)?;
}
Int(_) | Long(_) | String(_) | Real(_) => {
String(s) => {
eval_match(context, cons, &context.factory.string(format!("{:?}", s)))?;
eval_match(context, children, &context.factory.nil())?;
}
Int(_) | Long(_) | Real(_) => {
eval_match(context, cons, current)?;
eval_match(context, children, &context.factory.nil())?;
}
......
use context::{MutContext, Scope};
use ctree;
use error::{Result, Error};
use factory::{ATermFactory, ATermRef};
use factory::ATermRef;
use aterm::BrokenF32;
use aterm::{ATerm as A, ATermFactory as ATF};
......@@ -452,35 +452,37 @@ impl BuildTerm {
"Non-list in build of explode pattern (#) second argument",
))?;
if let Some(s) = cons.get_string() {
let string = context.factory.application(s.clone(), ::std::iter::empty());
if string.get_string().is_some() {
Ok(string)
} else {
let application =
context.factory.application(s, children.iter().cloned());
use factory::Term::*;
use ctree::string_unescape;
Ok(context.factory.with_annos(
application,
annos.unwrap_or_default(),
))
}
} else if cons.get_application().is_some() {
Err(Error::StrategyFailed)
} else if cons.get_list().is_some() {
Ok(context.factory.list(children.iter().cloned()))
} else if cons.get_blob().is_some() {
Err(Error::UnknownBehaviour(
"Blob in build of explode pattern (#) first argument",
))
} else if cons.get_placeholder().is_some() {
Err(Error::UnknownBehaviour(
match cons.term {
Application(_, _) => return Err(Error::StrategyFailed),
Placeholder(_,_) => return Err(Error::UnknownBehaviour(
"ATerm placeholder in build of explode pattern (#) first argument",
))
} else {
// Int, Long or Real
Ok(cons)
)),
Blob(_) => return Err(Error::UnknownBehaviour(
"Blob in build of explode pattern (#) first argument",
)),
List(_) => return Ok(context.factory.list(children.iter().cloned())),
String(s) => {
let result = if s.starts_with('"') {
Ok(context.factory.string(string_unescape(s)))
} else {
let application =
context.factory.application(s, children.iter().cloned());
Ok(context.factory.with_annos(
application,
annos.unwrap_or_default(),
))
};
return result;
}
Int(_) |
Long(_) |
Real(_) => {}
}
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