Review comments: downgrade to error-chain 0.8.1 for Send + Sync bound; use combine::primitive::Error.

This commit is contained in:
Nick Alexander 2017-04-18 13:01:26 -07:00 committed by Richard Newman
parent 60c082b61e
commit ff0147e89c
8 changed files with 38 additions and 11 deletions

View file

@ -18,7 +18,7 @@ rustc_version = "0.1.7"
[dependencies] [dependencies]
clap = "2.19.3" clap = "2.19.3"
error-chain = "0.9.0" error-chain = "0.8.1"
nickel = "0.9.0" nickel = "0.9.0"
slog = "1.4.0" slog = "1.4.0"
slog-scope = "0.2.2" slog-scope = "0.2.2"

View file

@ -4,7 +4,7 @@ version = "0.0.1"
workspace = ".." workspace = ".."
[dependencies] [dependencies]
error-chain = "0.9.0" error-chain = "0.8.1"
itertools = "0.5.9" itertools = "0.5.9"
lazy_static = "0.2.2" lazy_static = "0.2.2"
ordered-float = "0.4.0" ordered-float = "0.4.0"

View file

@ -4,7 +4,7 @@ version = "0.0.1"
workspace = ".." workspace = ".."
[dependencies] [dependencies]
error-chain = "0.9.0" error-chain = "0.8.1"
[dependencies.mentat_core] [dependencies.mentat_core]
path = "../core" path = "../core"

View file

@ -5,7 +5,7 @@ workspace = ".."
[dependencies] [dependencies]
combine = "2.2.2" combine = "2.2.2"
error-chain = "0.9.0" error-chain = "0.8.1"
matches = "0.1" matches = "0.1"
[dependencies.edn] [dependencies.edn]

View file

@ -353,15 +353,15 @@ enum FindQueryPart {
} }
def_parser!(Find, vars, BTreeSet<Variable>, { def_parser!(Find, vars, BTreeSet<Variable>, {
vector().of_exactly(many(Query::variable()).map(|vars: Vec<Variable>| { vector().of_exactly(many(Query::variable()).and_then(|vars: Vec<Variable>| {
let given = vars.len(); let given = vars.len();
let set: BTreeSet<Variable> = vars.into_iter().collect(); let set: BTreeSet<Variable> = vars.into_iter().collect();
if given != set.len() { if given != set.len() {
// TODO: find out what the variable is! // TODO: find out what the variable is!
// TODO: figure out how to use `and_then` to return an error here. let e = Box::new(Error::from_kind(ErrorKind::DuplicateVariableError));
panic!(Error::from_kind(ErrorKind::DuplicateVariableError)); Err(combine::primitives::Error::Other(e))
} else { } else {
set Ok(set)
} }
})) }))
}); });
@ -549,6 +549,33 @@ mod test {
vec![variable(e.clone())]); vec![variable(e.clone())]);
} }
#[test]
fn test_repeated_vars() {
let e = edn::PlainSymbol::new("?e");
let f = edn::PlainSymbol::new("?f");
let input = edn::Value::Vector(vec![edn::Value::PlainSymbol(e.clone()),
edn::Value::PlainSymbol(f.clone()),]);
assert_parses_to!(Find::vars, input,
vec![variable(e.clone()), variable(f.clone())].into_iter().collect());
let g = edn::PlainSymbol::new("?g");
let input = edn::Value::Vector(vec![edn::Value::PlainSymbol(g.clone()),
edn::Value::PlainSymbol(g.clone()),]);
let mut par = Find::vars();
let result = par.parse(input.with_spans().into_atom_stream())
.map(|x| x.0)
.map_err(|e| if let Some(combine::primitives::Error::Other(x)) = e.errors.into_iter().next() {
// Pattern matching on boxes is rocket science until Rust Nightly features hit
// stable. ErrorKind isn't Clone, so convert to strings. We could pattern match
// for exact comparison here.
x.downcast::<Error>().ok().map(|e| e.to_string())
} else {
None
});
assert_eq!(result, Err(Some("duplicates in variable list".to_string())));
}
#[test] #[test]
fn test_or() { fn test_or() {
let oj = edn::PlainSymbol::new("or"); let oj = edn::PlainSymbol::new("or");

View file

@ -4,7 +4,7 @@ version = "0.0.1"
workspace = ".." workspace = ".."
[dependencies] [dependencies]
error-chain = "0.9.0" error-chain = "0.8.1"
[dependencies.rusqlite] [dependencies.rusqlite]
version = "0.10.1" version = "0.10.1"

View file

@ -4,7 +4,7 @@ version = "0.0.1"
workspace = ".." workspace = ".."
[dependencies] [dependencies]
error-chain = "0.9.0" error-chain = "0.8.1"
ordered-float = "0.4.0" ordered-float = "0.4.0"
[dependencies.mentat_core] [dependencies.mentat_core]

View file

@ -5,7 +5,7 @@ workspace = ".."
[dependencies] [dependencies]
combine = "2.2.2" combine = "2.2.2"
error-chain = "0.9.0" error-chain = "0.8.1"
[dependencies.edn] [dependencies.edn]
path = "../edn" path = "../edn"