Restructure project

This commit is contained in:
Patrick Lühne 2020-02-04 16:48:33 +01:00
parent 3dbe11be61
commit f5b84eaf63
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
3 changed files with 46 additions and 46 deletions

View File

@ -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<foliage::VariableDeclaration>;
}
pub(crate) fn translate_binary_operator(binary_operator: clingo::ast::BinaryOperator)
-> Result<foliage::BinaryOperator, crate::Error>
{
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,
}
}

View File

@ -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
{

View File

@ -0,0 +1,43 @@
pub(crate) fn translate_binary_operator(binary_operator: clingo::ast::BinaryOperator)
-> Result<foliage::BinaryOperator, crate::Error>
{
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,
}
}