From f5b84eaf63150ae139491c908ed9a44b54763047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 4 Feb 2020 16:48:33 +0100 Subject: [PATCH] Restructure project --- src/translate/common.rs | 46 +------------------- src/translate/common/choose_value_in_term.rs | 3 +- src/translate/common/operators.rs | 43 ++++++++++++++++++ 3 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 src/translate/common/operators.rs diff --git a/src/translate/common.rs b/src/translate/common.rs index fbdaea2..4bffe8e 100644 --- a/src/translate/common.rs +++ b/src/translate/common.rs @@ -1,6 +1,8 @@ mod choose_value_in_term; +mod operators; pub(crate) use choose_value_in_term::*; +pub(crate) use operators::*; pub(crate) trait AssignVariableDeclarationDomain { @@ -37,47 +39,3 @@ pub(crate) trait GetOrCreateVariableDeclaration fn get_or_create_variable_declaration(&self, name: &str) -> std::rc::Rc; } - -pub(crate) fn translate_binary_operator(binary_operator: clingo::ast::BinaryOperator) - -> Result -{ - match binary_operator - { - clingo::ast::BinaryOperator::And - | clingo::ast::BinaryOperator::Or - | clingo::ast::BinaryOperator::Xor - => return Err(crate::Error::new_unsupported_language_feature("binary logical operators")), - clingo::ast::BinaryOperator::Plus - => Ok(foliage::BinaryOperator::Add), - clingo::ast::BinaryOperator::Minus - => Ok(foliage::BinaryOperator::Subtract), - clingo::ast::BinaryOperator::Multiplication - => Ok(foliage::BinaryOperator::Multiply), - clingo::ast::BinaryOperator::Division - => Ok(foliage::BinaryOperator::Divide), - clingo::ast::BinaryOperator::Modulo - => Ok(foliage::BinaryOperator::Modulo), - clingo::ast::BinaryOperator::Power - => Ok(foliage::BinaryOperator::Exponentiate), - } -} - -pub(crate) fn translate_comparison_operator(comparison_operator: clingo::ast::ComparisonOperator) - -> foliage::ComparisonOperator -{ - match comparison_operator - { - clingo::ast::ComparisonOperator::GreaterThan - => foliage::ComparisonOperator::Greater, - clingo::ast::ComparisonOperator::LessThan - => foliage::ComparisonOperator::Less, - clingo::ast::ComparisonOperator::LessEqual - => foliage::ComparisonOperator::LessOrEqual, - clingo::ast::ComparisonOperator::GreaterEqual - => foliage::ComparisonOperator::GreaterOrEqual, - clingo::ast::ComparisonOperator::NotEqual - => foliage::ComparisonOperator::NotEqual, - clingo::ast::ComparisonOperator::Equal - => foliage::ComparisonOperator::Equal, - } -} diff --git a/src/translate/common/choose_value_in_term.rs b/src/translate/common/choose_value_in_term.rs index 8c7a0f2..0edd621 100644 --- a/src/translate/common/choose_value_in_term.rs +++ b/src/translate/common/choose_value_in_term.rs @@ -66,8 +66,7 @@ where }, clingo::ast::TermType::BinaryOperation(binary_operation) => { - let operator = crate::translate::common::translate_binary_operator( - binary_operation.binary_operator())?; + let operator = super::translate_binary_operator(binary_operation.binary_operator())?; match operator { diff --git a/src/translate/common/operators.rs b/src/translate/common/operators.rs new file mode 100644 index 0000000..6787dbf --- /dev/null +++ b/src/translate/common/operators.rs @@ -0,0 +1,43 @@ +pub(crate) fn translate_binary_operator(binary_operator: clingo::ast::BinaryOperator) + -> Result +{ + match binary_operator + { + clingo::ast::BinaryOperator::And + | clingo::ast::BinaryOperator::Or + | clingo::ast::BinaryOperator::Xor + => return Err(crate::Error::new_unsupported_language_feature("binary logical operators")), + clingo::ast::BinaryOperator::Plus + => Ok(foliage::BinaryOperator::Add), + clingo::ast::BinaryOperator::Minus + => Ok(foliage::BinaryOperator::Subtract), + clingo::ast::BinaryOperator::Multiplication + => Ok(foliage::BinaryOperator::Multiply), + clingo::ast::BinaryOperator::Division + => Ok(foliage::BinaryOperator::Divide), + clingo::ast::BinaryOperator::Modulo + => Ok(foliage::BinaryOperator::Modulo), + clingo::ast::BinaryOperator::Power + => Ok(foliage::BinaryOperator::Exponentiate), + } +} + +pub(crate) fn translate_comparison_operator(comparison_operator: clingo::ast::ComparisonOperator) + -> foliage::ComparisonOperator +{ + match comparison_operator + { + clingo::ast::ComparisonOperator::GreaterThan + => foliage::ComparisonOperator::Greater, + clingo::ast::ComparisonOperator::LessThan + => foliage::ComparisonOperator::Less, + clingo::ast::ComparisonOperator::LessEqual + => foliage::ComparisonOperator::LessOrEqual, + clingo::ast::ComparisonOperator::GreaterEqual + => foliage::ComparisonOperator::GreaterOrEqual, + clingo::ast::ComparisonOperator::NotEqual + => foliage::ComparisonOperator::NotEqual, + clingo::ast::ComparisonOperator::Equal + => foliage::ComparisonOperator::Equal, + } +}