Restructure project
This commit is contained in:
parent
3dbe11be61
commit
f5b84eaf63
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
43
src/translate/common/operators.rs
Normal file
43
src/translate/common/operators.rs
Normal 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,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user