2020-01-24 13:32:43 +01:00
|
|
|
struct StatementHandler<'context>
|
|
|
|
{
|
2020-01-25 12:55:23 +01:00
|
|
|
context: &'context mut anthem::translate::verify_properties::Context,
|
2020-01-24 13:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl clingo::StatementHandler for StatementHandler<'_>
|
|
|
|
{
|
|
|
|
fn on_statement(&mut self, statement: &clingo::ast::Statement) -> bool
|
|
|
|
{
|
|
|
|
match statement.statement_type()
|
|
|
|
{
|
|
|
|
clingo::ast::StatementType::Rule(ref rule) =>
|
|
|
|
{
|
2020-02-01 15:32:41 +01:00
|
|
|
if let Err(error) = anthem::translate::verify_properties::read(rule, self.context)
|
|
|
|
{
|
|
|
|
log::error!("could not translate input program: {}", error);
|
2020-02-01 17:13:43 +01:00
|
|
|
return false;
|
2020-02-01 15:32:41 +01:00
|
|
|
}
|
2020-01-24 13:32:43 +01:00
|
|
|
},
|
2020-01-31 17:19:44 +01:00
|
|
|
_ => log::debug!("read statement (other kind)"),
|
2020-01-24 13:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Logger;
|
|
|
|
|
|
|
|
impl clingo::Logger for Logger
|
|
|
|
{
|
|
|
|
fn log(&mut self, code: clingo::Warning, message: &str)
|
|
|
|
{
|
2020-01-31 17:19:44 +01:00
|
|
|
log::warn!("clingo warning ({:?}): {}", code, message);
|
2020-01-24 13:32:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 17:13:43 +01:00
|
|
|
fn main()
|
2020-01-24 13:32:43 +01:00
|
|
|
{
|
2020-01-31 17:19:44 +01:00
|
|
|
pretty_env_logger::init();
|
|
|
|
|
2020-02-01 17:13:43 +01:00
|
|
|
let program = match std::fs::read_to_string("test.lp")
|
|
|
|
{
|
|
|
|
Ok(value) => value,
|
|
|
|
Err(error) =>
|
|
|
|
{
|
|
|
|
log::error!("could not read input program: {}", error);
|
|
|
|
std::process::exit(1);
|
|
|
|
},
|
|
|
|
};
|
2020-01-25 12:55:23 +01:00
|
|
|
let mut context = anthem::translate::verify_properties::Context::new();
|
|
|
|
let mut statement_handler = StatementHandler
|
|
|
|
{
|
|
|
|
context: &mut context
|
|
|
|
};
|
2020-01-24 13:32:43 +01:00
|
|
|
|
2020-02-01 17:13:43 +01:00
|
|
|
match clingo::parse_program_with_logger(&program, &mut statement_handler, &mut Logger, std::u32::MAX)
|
|
|
|
{
|
|
|
|
Ok(()) => (),
|
|
|
|
Err(error) =>
|
|
|
|
{
|
|
|
|
log::error!("could not translate input program: {}", error);
|
|
|
|
std::process::exit(1);
|
|
|
|
},
|
|
|
|
}
|
2020-01-24 13:32:43 +01:00
|
|
|
}
|