Restructure project

This commit is contained in:
Patrick Lühne 2020-02-04 16:53:52 +01:00
parent f5b84eaf63
commit d7f04da0bd
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
10 changed files with 97 additions and 97 deletions

View File

@ -2,6 +2,7 @@
pub mod error;
pub mod output;
pub(crate) mod traits;
pub mod translate;
mod utils;

View File

@ -1,7 +1,7 @@
pub(crate) struct VariableDeclarationDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
variable_declaration: &'a std::rc::Rc<foliage::VariableDeclaration>,
context: &'b C,
@ -11,8 +11,8 @@ pub(crate) fn display_variable_declaration<'a, 'b, C>(
variable_declaration: &'a std::rc::Rc<foliage::VariableDeclaration>, context: &'b C)
-> VariableDeclarationDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
VariableDeclarationDisplay
{
@ -51,8 +51,8 @@ pub(crate) fn display_formula<'a, 'b, C>(formula: &'a foliage::Formula,
parent_precedence: Option<i32>, context: &'b C)
-> FormulaDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
FormulaDisplay
{
@ -126,8 +126,8 @@ impl Precedence for foliage::Formula
impl<'a, 'b, C> std::fmt::Debug for VariableDeclarationDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{
@ -147,8 +147,8 @@ where
impl<'a, 'b, C> std::fmt::Display for VariableDeclarationDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{
@ -158,8 +158,8 @@ where
impl<'a, 'b, C> std::fmt::Debug for TermDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{
@ -245,8 +245,8 @@ where
impl<'a, 'b, C> std::fmt::Display for TermDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{
@ -256,8 +256,8 @@ where
impl<'a, 'b, C> std::fmt::Debug for FormulaDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{
@ -393,8 +393,8 @@ where
impl<'a, 'b, C> std::fmt::Display for FormulaDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{

View File

@ -35,8 +35,8 @@ impl std::fmt::Display for DomainDisplay
pub(crate) struct VariableDeclarationDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
variable_declaration: &'a std::rc::Rc<foliage::VariableDeclaration>,
context: &'b C,
@ -46,8 +46,8 @@ pub(crate) fn display_variable_declaration<'a, 'b, C>(
variable_declaration: &'a std::rc::Rc<foliage::VariableDeclaration>, context: &'b C)
-> VariableDeclarationDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
VariableDeclarationDisplay
{
@ -65,8 +65,8 @@ pub(crate) struct TermDisplay<'a, 'b, C>
pub(crate) fn display_term<'a, 'b, C>(term: &'a foliage::Term, context: &'b C)
-> TermDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
TermDisplay
{
@ -84,8 +84,8 @@ pub(crate) struct FormulaDisplay<'a, 'b, C>
pub(crate) fn display_formula<'a, 'b, C>(formula: &'a foliage::Formula, context: &'b C)
-> FormulaDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
FormulaDisplay
{
@ -96,8 +96,8 @@ where
impl<'a, 'b, C> std::fmt::Debug for VariableDeclarationDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{
@ -117,8 +117,8 @@ where
impl<'a, 'b, C> std::fmt::Display for VariableDeclarationDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{
@ -128,8 +128,8 @@ where
impl<'a, 'b, C> std::fmt::Debug for TermDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{
@ -199,8 +199,8 @@ where
impl<'a, 'b, C> std::fmt::Display for TermDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{
@ -210,8 +210,8 @@ where
impl<'a, 'b, C> std::fmt::Debug for FormulaDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{
@ -342,8 +342,8 @@ where
impl<'a, 'b, C> std::fmt::Display for FormulaDisplay<'a, 'b, C>
where
C: crate::translate::common::VariableDeclarationDomain
+ crate::translate::common::VariableDeclarationID
C: crate::traits::VariableDeclarationDomain
+ crate::traits::VariableDeclarationID
{
fn fmt(&self, format: &mut std::fmt::Formatter) -> std::fmt::Result
{

35
src/traits.rs Normal file
View File

@ -0,0 +1,35 @@
pub(crate) trait AssignVariableDeclarationDomain
{
fn assign_variable_declaration_domain(&self,
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>, domain: crate::Domain);
}
pub(crate) trait VariableDeclarationDomain
{
fn variable_declaration_domain(&self,
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>) -> Option<crate::Domain>;
}
pub(crate) trait VariableDeclarationID
{
fn variable_declaration_id(&self,
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>) -> usize;
}
pub(crate) trait GetOrCreateFunctionDeclaration
{
fn get_or_create_function_declaration(&self, name: &str, arity: usize)
-> std::rc::Rc<foliage::FunctionDeclaration>;
}
pub(crate) trait GetOrCreatePredicateDeclaration
{
fn get_or_create_predicate_declaration(&self, name: &str, arity: usize)
-> std::rc::Rc<foliage::PredicateDeclaration>;
}
pub(crate) trait GetOrCreateVariableDeclaration
{
fn get_or_create_variable_declaration(&self, name: &str)
-> std::rc::Rc<foliage::VariableDeclaration>;
}

View File

@ -3,39 +3,3 @@ mod operators;
pub(crate) use choose_value_in_term::*;
pub(crate) use operators::*;
pub(crate) trait AssignVariableDeclarationDomain
{
fn assign_variable_declaration_domain(&self,
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>, domain: crate::Domain);
}
pub(crate) trait VariableDeclarationDomain
{
fn variable_declaration_domain(&self,
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>) -> Option<crate::Domain>;
}
pub(crate) trait VariableDeclarationID
{
fn variable_declaration_id(&self,
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>) -> usize;
}
pub(crate) trait GetOrCreateFunctionDeclaration
{
fn get_or_create_function_declaration(&self, name: &str, arity: usize)
-> std::rc::Rc<foliage::FunctionDeclaration>;
}
pub(crate) trait GetOrCreatePredicateDeclaration
{
fn get_or_create_predicate_declaration(&self, name: &str, arity: usize)
-> std::rc::Rc<foliage::PredicateDeclaration>;
}
pub(crate) trait GetOrCreateVariableDeclaration
{
fn get_or_create_variable_declaration(&self, name: &str)
-> std::rc::Rc<foliage::VariableDeclaration>;
}

View File

@ -11,9 +11,9 @@ pub(crate) fn choose_value_in_term<C>(term: &clingo::ast::Term,
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>, context: &C)
-> Result<foliage::Formula, crate::Error>
where
C: crate::translate::common::GetOrCreateFunctionDeclaration
+ crate::translate::common::GetOrCreateVariableDeclaration
+ crate::translate::common::AssignVariableDeclarationDomain
C: crate::traits::GetOrCreateFunctionDeclaration
+ crate::traits::GetOrCreateVariableDeclaration
+ crate::traits::AssignVariableDeclarationDomain
{
match term.term_type()
{

View File

@ -5,7 +5,7 @@ mod translate_body;
use context::*;
use head_type::*;
use translate_body::*;
use crate::translate::common::AssignVariableDeclarationDomain as _;
use crate::traits::AssignVariableDeclarationDomain as _;
struct StatementHandler
{

View File

@ -41,7 +41,7 @@ impl Context
}
}
impl crate::translate::common::GetOrCreateFunctionDeclaration for Context
impl crate::traits::GetOrCreateFunctionDeclaration for Context
{
fn get_or_create_function_declaration(&self, name: &str, arity: usize)
-> std::rc::Rc<foliage::FunctionDeclaration>
@ -67,7 +67,7 @@ impl crate::translate::common::GetOrCreateFunctionDeclaration for Context
}
}
impl crate::translate::common::GetOrCreatePredicateDeclaration for Context
impl crate::traits::GetOrCreatePredicateDeclaration for Context
{
fn get_or_create_predicate_declaration(&self, name: &str, arity: usize)
-> std::rc::Rc<foliage::PredicateDeclaration>
@ -93,7 +93,7 @@ impl crate::translate::common::GetOrCreatePredicateDeclaration for Context
}
}
impl crate::translate::common::GetOrCreateVariableDeclaration for Context
impl crate::traits::GetOrCreateVariableDeclaration for Context
{
fn get_or_create_variable_declaration(&self, name: &str)
-> std::rc::Rc<foliage::VariableDeclaration>
@ -116,7 +116,7 @@ impl crate::translate::common::GetOrCreateVariableDeclaration for Context
}
}
impl crate::translate::common::AssignVariableDeclarationDomain for Context
impl crate::traits::AssignVariableDeclarationDomain for Context
{
fn assign_variable_declaration_domain(&self,
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>, domain: crate::Domain)
@ -136,7 +136,7 @@ impl crate::translate::common::AssignVariableDeclarationDomain for Context
}
}
impl crate::translate::common::VariableDeclarationDomain for Context
impl crate::traits::VariableDeclarationDomain for Context
{
fn variable_declaration_domain(&self,
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>)
@ -149,7 +149,7 @@ impl crate::translate::common::VariableDeclarationDomain for Context
}
}
impl crate::translate::common::VariableDeclarationID for Context
impl crate::traits::VariableDeclarationID for Context
{
fn variable_declaration_id(&self,
variable_declaration: &std::rc::Rc<foliage::VariableDeclaration>)

View File

@ -15,7 +15,7 @@ pub(crate) enum HeadType<'a>
pub(crate) fn determine_head_type<'a, C>(head_literal: &'a clingo::ast::HeadLiteral, context: &C)
-> Result<HeadType<'a>, crate::Error>
where
C: crate::translate::common::GetOrCreatePredicateDeclaration
C: crate::traits::GetOrCreatePredicateDeclaration
{
let create_head_atom = |function: &'a clingo::ast::Function| -> Result<_, crate::Error>
{

View File

@ -2,10 +2,10 @@ pub(crate) fn translate_body_term<C>(body_term: &clingo::ast::Term, sign: clingo
context: &C)
-> Result<foliage::Formula, crate::Error>
where
C: crate::translate::common::GetOrCreateVariableDeclaration
+ crate::translate::common::GetOrCreateFunctionDeclaration
+ crate::translate::common::GetOrCreatePredicateDeclaration
+ crate::translate::common::AssignVariableDeclarationDomain
C: crate::traits::GetOrCreateVariableDeclaration
+ crate::traits::GetOrCreateFunctionDeclaration
+ crate::traits::GetOrCreatePredicateDeclaration
+ crate::traits::AssignVariableDeclarationDomain
{
let function = match body_term.term_type()
{
@ -69,10 +69,10 @@ pub(crate) fn translate_body_literal<C>(body_literal: &clingo::ast::BodyLiteral,
context: &C)
-> Result<foliage::Formula, crate::Error>
where
C: crate::translate::common::GetOrCreateVariableDeclaration
+ crate::translate::common::GetOrCreateFunctionDeclaration
+ crate::translate::common::GetOrCreatePredicateDeclaration
+ crate::translate::common::AssignVariableDeclarationDomain
C: crate::traits::GetOrCreateVariableDeclaration
+ crate::traits::GetOrCreateFunctionDeclaration
+ crate::traits::GetOrCreatePredicateDeclaration
+ crate::traits::AssignVariableDeclarationDomain
{
match body_literal.sign()
{
@ -147,10 +147,10 @@ pub(crate) fn translate_body<C>(body_literals: &[clingo::ast::BodyLiteral],
context: &C)
-> Result<foliage::Formulas, crate::Error>
where
C: crate::translate::common::GetOrCreateVariableDeclaration
+ crate::translate::common::GetOrCreateFunctionDeclaration
+ crate::translate::common::GetOrCreatePredicateDeclaration
+ crate::translate::common::AssignVariableDeclarationDomain
C: crate::traits::GetOrCreateVariableDeclaration
+ crate::traits::GetOrCreateFunctionDeclaration
+ crate::traits::GetOrCreatePredicateDeclaration
+ crate::traits::AssignVariableDeclarationDomain
{
body_literals.iter()
.map(|body_literal| translate_body_literal(body_literal, context)