diff --git a/src/ast.rs b/src/ast.rs index 65a3bf3..4935873 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -178,12 +178,12 @@ impl BinaryOperation pub struct Function { pub declaration: std::rc::Rc, - pub arguments: Vec>, + pub arguments: Terms, } impl Function { - pub fn new(declaration: std::rc::Rc, arguments: Vec>) -> Self + pub fn new(declaration: std::rc::Rc, arguments: Terms) -> Self { assert_eq!(declaration.arity, arguments.len(), "function has a different number of arguments then declared"); @@ -307,12 +307,12 @@ impl Implies pub struct Predicate { pub declaration: std::rc::Rc, - pub arguments: Vec>, + pub arguments: Terms, } impl Predicate { - pub fn new(declaration: std::rc::Rc, arguments: Vec>) -> Self + pub fn new(declaration: std::rc::Rc, arguments: Terms) -> Self { assert_eq!(declaration.arity, arguments.len(), "predicate has a different number of arguments then declared"); @@ -340,7 +340,7 @@ pub enum Term Variable(Variable), } -pub type Terms = Vec>; +pub type Terms = Vec; impl Term { @@ -379,8 +379,7 @@ impl Term Self::boolean(false) } - pub fn function(declaration: std::rc::Rc, arguments: Vec>) - -> Self + pub fn function(declaration: std::rc::Rc, arguments: Terms) -> Self { Self::Function(Function::new(declaration, arguments)) } @@ -546,8 +545,7 @@ impl Formula Self::Or(arguments) } - pub fn predicate(declaration: std::rc::Rc, arguments: Vec>) - -> Self + pub fn predicate(declaration: std::rc::Rc, arguments: Terms) -> Self { Self::Predicate(Predicate::new(declaration, arguments)) } diff --git a/src/format/formulas.rs b/src/format/formulas.rs index 194a8e2..98f928d 100644 --- a/src/format/formulas.rs +++ b/src/format/formulas.rs @@ -483,9 +483,10 @@ mod tests Box::new(Formula::or(arguments.into_iter().map(|x| *x).collect())) } - fn predicate(name: &str, arguments: Terms) -> Box + fn predicate(name: &str, arguments: Vec>) -> Box { - Box::new(Formula::predicate(predicate_declaration(name, arguments.len()), arguments)) + Box::new(Formula::predicate(predicate_declaration(name, arguments.len()), + arguments.into_iter().map(|x| *x).collect())) } fn predicate_declaration(name: &str, arity: usize) -> std::rc::Rc diff --git a/src/format/terms.rs b/src/format/terms.rs index 6212b13..406ef23 100644 --- a/src/format/terms.rs +++ b/src/format/terms.rs @@ -316,7 +316,8 @@ pub(crate) mod tests pub(crate) fn function(name: &str, arguments: Vec>) -> Box { - Box::new(Term::function(function_declaration(name, arguments.len()), arguments)) + Box::new(Term::function(function_declaration(name, arguments.len()), + arguments.into_iter().map(|x| *x).collect())) } pub(crate) fn function_declaration(name: &str, arity: usize) -> std::rc::Rc @@ -404,17 +405,17 @@ pub(crate) mod tests constant("e") } - pub(crate) fn abc() -> Terms + pub(crate) fn abc() -> Vec> { vec![a(), b(), c()] } - pub(crate) fn a1b1c1() -> Terms + pub(crate) fn a1b1c1() -> Vec> { vec![constant("a1"), constant("b1"), constant("c1")] } - pub(crate) fn a2b2c2() -> Terms + pub(crate) fn a2b2c2() -> Vec> { vec![constant("a2"), constant("b2"), constant("c2")] } @@ -434,7 +435,7 @@ pub(crate) mod tests variable("Z") } - pub(crate) fn xyz() -> Terms + pub(crate) fn xyz() -> Vec> { vec![x(), y(), z()] } diff --git a/src/parse/formulas.rs b/src/parse/formulas.rs index 0d71675..979275f 100644 --- a/src/parse/formulas.rs +++ b/src/parse/formulas.rs @@ -642,9 +642,9 @@ mod tests assert_eq!(predicate_remainder("s ( )"), ""); assert_eq!(predicate("s ( 1 , 2 , 3 )").declaration.name, "s"); assert_eq!(predicate("s ( 1 , 2 , 3 )").declaration.arity, 3); - assert_eq!(*predicate("s ( 1 , 2 , 3 )").arguments.remove(0), Term::integer(1)); - assert_eq!(*predicate("s ( 1 , 2 , 3 )").arguments.remove(1), Term::integer(2)); - assert_eq!(*predicate("s ( 1 , 2 , 3 )").arguments.remove(2), Term::integer(3)); + assert_eq!(predicate("s ( 1 , 2 , 3 )").arguments.remove(0), Term::integer(1)); + assert_eq!(predicate("s ( 1 , 2 , 3 )").arguments.remove(1), Term::integer(2)); + assert_eq!(predicate("s ( 1 , 2 , 3 )").arguments.remove(2), Term::integer(3)); assert_eq!(predicate_remainder("s ( 1 , 2 , 3 )"), ""); assert_eq!(predicate_remainder("s ( 1 , 2 , 3 )"), ""); assert_eq!(predicate("s ( ), rest").declaration.name, "s"); diff --git a/src/parse/terms.rs b/src/parse/terms.rs index df0eaa5..b329ad8 100644 --- a/src/parse/terms.rs +++ b/src/parse/terms.rs @@ -59,7 +59,7 @@ fn absolute_value<'i>(i: &'i str, d: &Declarations) -> IResult<&'i str, crate::T } pub(crate) fn function_or_predicate<'i>(i: &'i str, d: &Declarations) - -> IResult<&'i str, (&'i str, Option>>)> + -> IResult<&'i str, (&'i str, Option)> { pair ( @@ -82,11 +82,7 @@ pub(crate) fn function_or_predicate<'i>(i: &'i str, d: &Declarations) tag(","), multispace0, ), - map - ( - |i| term(i, d), - Box::new, - ), + |i| term(i, d), ), preceded ( @@ -485,8 +481,8 @@ mod tests assert_eq!(term_as_function("s").declaration.arity, 0); assert_eq!(term_as_function("s(1, 2, 3)").declaration.name, "s"); assert_eq!(term_as_function("s(1, 2, 3)").declaration.arity, 3); - assert_eq!(*term_as_function("s(1, 2, 3)").arguments.remove(0), Term::integer(1)); - assert_eq!(*term_as_function("s(1, 2, 3)").arguments.remove(2), Term::integer(3)); + assert_eq!(term_as_function("s(1, 2, 3)").arguments.remove(0), Term::integer(1)); + assert_eq!(term_as_function("s(1, 2, 3)").arguments.remove(2), Term::integer(3)); } #[test] @@ -715,9 +711,9 @@ mod tests assert_eq!(function_remainder("s ( )"), ""); assert_eq!(function("s ( 1 , 2 , 3 )").declaration.name, "s"); assert_eq!(function("s ( 1 , 2 , 3 )").declaration.arity, 3); - assert_eq!(*function("s ( 1 , 2 , 3 )").arguments.remove(0), Term::integer(1)); - assert_eq!(*function("s ( 1 , 2 , 3 )").arguments.remove(1), Term::integer(2)); - assert_eq!(*function("s ( 1 , 2 , 3 )").arguments.remove(2), Term::integer(3)); + assert_eq!(function("s ( 1 , 2 , 3 )").arguments.remove(0), Term::integer(1)); + assert_eq!(function("s ( 1 , 2 , 3 )").arguments.remove(1), Term::integer(2)); + assert_eq!(function("s ( 1 , 2 , 3 )").arguments.remove(2), Term::integer(3)); assert_eq!(function_remainder("s ( 1 , 2 , 3 )"), ""); assert_eq!(function("s ( ), rest").declaration.name, "s"); assert_eq!(function("s ( ), rest").declaration.arity, 0);