2020-01-31 17:24:13 +01:00
|
|
|
mod context;
|
2020-02-01 17:20:43 +01:00
|
|
|
mod head_type;
|
2020-01-31 17:24:13 +01:00
|
|
|
mod translate_body;
|
2020-01-31 17:19:44 +01:00
|
|
|
|
2020-01-31 17:24:13 +01:00
|
|
|
pub use context::Context;
|
2020-02-01 15:32:41 +01:00
|
|
|
|
2020-02-01 17:20:43 +01:00
|
|
|
use head_type::*;
|
|
|
|
use translate_body::*;
|
2020-01-25 12:55:23 +01:00
|
|
|
|
2020-02-01 15:32:41 +01:00
|
|
|
pub fn read(rule: &clingo::ast::Rule, context: &mut Context) -> Result<(), crate::Error>
|
2020-01-31 17:19:44 +01:00
|
|
|
{
|
2020-02-01 17:13:43 +01:00
|
|
|
let translated_body = translate_body(rule.body(), context)?;
|
2020-02-01 15:32:41 +01:00
|
|
|
|
2020-02-01 17:13:43 +01:00
|
|
|
let head_type = determine_head_type(rule.head(),
|
2020-02-01 15:32:41 +01:00
|
|
|
|name, arity| context.find_or_create_predicate_declaration(name, arity))?;
|
|
|
|
|
2020-02-01 17:13:43 +01:00
|
|
|
match head_type
|
2020-02-01 15:32:41 +01:00
|
|
|
{
|
2020-02-01 17:20:43 +01:00
|
|
|
HeadType::ChoiceWithSingleAtom(test) =>
|
2020-02-01 17:13:43 +01:00
|
|
|
log::debug!("translating choice rule with single atom"),
|
2020-02-01 17:20:43 +01:00
|
|
|
HeadType::IntegrityConstraint =>
|
2020-02-01 17:13:43 +01:00
|
|
|
log::debug!("translating integrity constraint"),
|
2020-02-01 17:20:43 +01:00
|
|
|
HeadType::Trivial =>
|
2020-02-01 17:13:43 +01:00
|
|
|
{
|
|
|
|
log::debug!("skipping trivial rule");
|
|
|
|
return Ok(());
|
|
|
|
},
|
2020-02-01 15:32:41 +01:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
2020-01-24 13:32:43 +01:00
|
|
|
}
|