2020-01-31 17:19:44 +01:00
|
|
|
|
pub type Source = Box<dyn std::error::Error>;
|
|
|
|
|
|
|
|
|
|
pub enum Kind
|
|
|
|
|
{
|
|
|
|
|
Logic(&'static str),
|
|
|
|
|
UnsupportedLanguageFeature(&'static str),
|
|
|
|
|
NotYetImplemented(&'static str),
|
|
|
|
|
DecodeIdentifier,
|
2020-02-02 17:57:27 +01:00
|
|
|
|
Translate,
|
2020-02-02 19:20:16 +01:00
|
|
|
|
ReadFile(std::path::PathBuf),
|
2020-05-05 19:40:57 +02:00
|
|
|
|
ExpectedStatement,
|
|
|
|
|
ExpectedColon,
|
|
|
|
|
UnknownStatement(String),
|
|
|
|
|
UnmatchedParenthesis,
|
|
|
|
|
MissingStatementTerminator,
|
|
|
|
|
ParseFormula,
|
|
|
|
|
ExpectedIdentifier,
|
2020-02-05 01:10:33 +01:00
|
|
|
|
ParsePredicateDeclaration,
|
2020-05-05 19:40:57 +02:00
|
|
|
|
//ParseConstantDeclaration,
|
|
|
|
|
UnknownProofDirection(String),
|
|
|
|
|
UnknownDomainIdentifier(String),
|
|
|
|
|
VariableNameNotAllowed(String),
|
2020-05-06 00:13:43 +02:00
|
|
|
|
WriteTPTPProgram,
|
2020-01-31 17:19:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Error
|
|
|
|
|
{
|
|
|
|
|
pub kind: Kind,
|
|
|
|
|
pub source: Option<Source>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Error
|
|
|
|
|
{
|
|
|
|
|
pub(crate) fn new(kind: Kind) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self
|
|
|
|
|
{
|
|
|
|
|
kind,
|
|
|
|
|
source: None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn with<S: Into<Source>>(mut self, source: S) -> Self
|
|
|
|
|
{
|
|
|
|
|
self.source = Some(source.into());
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn new_logic(description: &'static str) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::Logic(description))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn new_unsupported_language_feature(description: &'static str) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::UnsupportedLanguageFeature(description))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn new_not_yet_implemented(description: &'static str) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::NotYetImplemented(description))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn new_decode_identifier<S: Into<Source>>(source: S) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::DecodeIdentifier).with(source)
|
|
|
|
|
}
|
2020-02-02 17:57:27 +01:00
|
|
|
|
|
|
|
|
|
pub(crate) fn new_translate<S: Into<Source>>(source: S) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::Translate).with(source)
|
|
|
|
|
}
|
2020-02-02 19:20:16 +01:00
|
|
|
|
|
|
|
|
|
pub(crate) fn new_read_file<S: Into<Source>>(path: std::path::PathBuf, source: S) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::ReadFile(path)).with(source)
|
|
|
|
|
}
|
2020-02-05 01:10:33 +01:00
|
|
|
|
|
2020-05-05 19:40:57 +02:00
|
|
|
|
pub(crate) fn new_expected_statement() -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::ExpectedStatement)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn new_expected_colon() -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::ExpectedColon)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn new_unknown_statement(statement_name: String) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::UnknownStatement(statement_name))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn new_unmatched_parenthesis() -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::UnmatchedParenthesis)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn new_missing_statement_terminator() -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::MissingStatementTerminator)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn new_parse_formula<S: Into<Source>>(source: S) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::ParseFormula).with(source)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn new_expected_identifier() -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::ExpectedIdentifier)
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 01:10:33 +01:00
|
|
|
|
pub(crate) fn new_parse_predicate_declaration() -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::ParsePredicateDeclaration)
|
|
|
|
|
}
|
2020-02-05 19:40:21 +01:00
|
|
|
|
|
2020-05-05 19:40:57 +02:00
|
|
|
|
pub(crate) fn new_unknown_proof_direction(proof_direction: String) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::UnknownProofDirection(proof_direction))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn new_unknown_domain_identifier(domain_identifier: String) -> Self
|
2020-02-05 19:40:21 +01:00
|
|
|
|
{
|
2020-05-05 19:40:57 +02:00
|
|
|
|
Self::new(Kind::UnknownDomainIdentifier(domain_identifier))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn new_variable_name_not_allowed(variable_name: String) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::VariableNameNotAllowed(variable_name))
|
2020-02-05 19:40:21 +01:00
|
|
|
|
}
|
2020-05-06 00:13:43 +02:00
|
|
|
|
|
|
|
|
|
pub(crate) fn new_write_tptp_program<S: Into<Source>>(source: S) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::new(Kind::WriteTPTPProgram).with(source)
|
|
|
|
|
}
|
2020-01-31 17:19:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl std::fmt::Debug for Error
|
|
|
|
|
{
|
|
|
|
|
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result
|
|
|
|
|
{
|
|
|
|
|
match &self.kind
|
|
|
|
|
{
|
|
|
|
|
Kind::Logic(ref description) => write!(formatter,
|
|
|
|
|
"logic error, please report to bug tracker ({})", description),
|
|
|
|
|
Kind::UnsupportedLanguageFeature(ref description) => write!(formatter,
|
|
|
|
|
"language feature not yet supported ({})", description),
|
|
|
|
|
Kind::NotYetImplemented(ref description) => write!(formatter,
|
|
|
|
|
"not yet implemented ({})", description),
|
|
|
|
|
Kind::DecodeIdentifier => write!(formatter, "could not decode identifier"),
|
2020-02-02 17:57:27 +01:00
|
|
|
|
Kind::Translate => write!(formatter, "could not translate input program"),
|
2020-02-02 19:20:16 +01:00
|
|
|
|
Kind::ReadFile(path) => write!(formatter, "could not read file “{}”", path.display()),
|
2020-05-05 19:40:57 +02:00
|
|
|
|
Kind::ExpectedStatement => write!(formatter,
|
|
|
|
|
"expected statement (axiom, assert, assume, input, lemma)"),
|
|
|
|
|
Kind::ExpectedColon => write!(formatter, "expected ‘:’"),
|
|
|
|
|
Kind::UnknownStatement(ref statement_name) => write!(formatter,
|
|
|
|
|
"unknown statement “{}” (allowed: axiom, assert, assume, input, lemma)",
|
|
|
|
|
statement_name),
|
|
|
|
|
Kind::UnmatchedParenthesis => write!(formatter, "unmatched parenthesis"),
|
|
|
|
|
Kind::ParsePredicateDeclaration => write!(formatter,
|
|
|
|
|
"could not parse predicate declaration"),
|
|
|
|
|
Kind::ParseFormula => write!(formatter, "could not parse formula"),
|
|
|
|
|
Kind::ExpectedIdentifier => write!(formatter, "expected constant or predicate name"),
|
2020-02-05 01:10:33 +01:00
|
|
|
|
Kind::ParsePredicateDeclaration => write!(formatter,
|
|
|
|
|
"could not parse predicate declaration"),
|
2020-05-05 19:40:57 +02:00
|
|
|
|
Kind::MissingStatementTerminator => write!(formatter,
|
|
|
|
|
"statement not terminated with ‘.’ character"),
|
|
|
|
|
Kind::UnknownProofDirection(ref proof_direction) => write!(formatter,
|
|
|
|
|
"unknown proof direction “{}” (allowed: integer, program)", proof_direction),
|
|
|
|
|
Kind::UnknownDomainIdentifier(ref domain_identifier) => write!(formatter,
|
|
|
|
|
"unknown domain identifier “{}” (allowed: int, program)", domain_identifier),
|
|
|
|
|
Kind::VariableNameNotAllowed(ref variable_name) => write!(formatter,
|
|
|
|
|
"variable name “{}” not allowed (program variables must start with X, Y, or Z and integer variables with I, J, K, L, M, or N)",
|
|
|
|
|
variable_name),
|
2020-05-06 00:13:43 +02:00
|
|
|
|
Kind::WriteTPTPProgram => write!(formatter, "error writing TPTP program"),
|
2020-01-31 17:19:44 +01:00
|
|
|
|
}?;
|
|
|
|
|
|
|
|
|
|
if let Some(source) = &self.source
|
|
|
|
|
{
|
|
|
|
|
write!(formatter, "\nerror source: {}", source)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl std::fmt::Display for Error
|
|
|
|
|
{
|
|
|
|
|
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result
|
|
|
|
|
{
|
|
|
|
|
write!(formatter, "{:?}", self)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl std::error::Error for Error
|
|
|
|
|
{
|
|
|
|
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)>
|
|
|
|
|
{
|
|
|
|
|
match &self.source
|
|
|
|
|
{
|
|
|
|
|
Some(source) => Some(source.as_ref()),
|
|
|
|
|
None => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|