Compare commits
5 Commits
v0.1.7-rc.
...
v0.1.7-rc.
Author | SHA1 | Date | |
---|---|---|---|
b8bfa7db7a
|
|||
3e096e39aa
|
|||
2a2fec0eac
|
|||
09e56c3bce
|
|||
e2c0d6b705
|
32
CHANGELOG.md
32
CHANGELOG.md
@@ -1,10 +1,18 @@
|
||||
# Change Log
|
||||
|
||||
## (unreleased)
|
||||
## 0.1.7 RC 2 (2018-04-06)
|
||||
|
||||
### Features
|
||||
|
||||
* support for declaring placeholders with the `#external` directive
|
||||
|
||||
### Internal
|
||||
|
||||
* drops Boost dependency in favor of the header-only command-line option library [cxxopts](https://github.com/jarro2783/cxxopts)
|
||||
|
||||
## 0.1.6 (2017-06-12)
|
||||
|
||||
Features:
|
||||
### Features
|
||||
|
||||
* unique IDs for all variables (user-defined variables are renamed)
|
||||
* support for hiding predicates from completed output by using `#show` statements
|
||||
@@ -12,7 +20,7 @@ Features:
|
||||
* command-line option `--parentheses` to fully parenthesize the output
|
||||
* adds multiple example instances for experimenting
|
||||
|
||||
Bug Fixes:
|
||||
### Bug Fixes
|
||||
|
||||
* adds missing error message when attempting to read inaccessible file
|
||||
* removes unnecessary parentheses after simplification
|
||||
@@ -20,52 +28,52 @@ Bug Fixes:
|
||||
|
||||
## 0.1.5 (2017-05-04)
|
||||
|
||||
Bug Fixes:
|
||||
### Bug Fixes
|
||||
|
||||
* fixes lost signs with negated 0-ary predicates
|
||||
|
||||
## 0.1.4 (2017-04-12)
|
||||
|
||||
Features:
|
||||
### Features
|
||||
|
||||
* completion of input programs (optional)
|
||||
* command-line option `--complete` to turn on completion
|
||||
|
||||
## 0.1.3 (2017-03-30)
|
||||
|
||||
Features:
|
||||
### Features
|
||||
|
||||
* support for anonymous variables
|
||||
|
||||
Bug Fixes:
|
||||
### Bug Fixes
|
||||
|
||||
* fixes incorrectly simplified rules with comparisons
|
||||
* fixes misleading error message concerning negated, unsupported body literals
|
||||
|
||||
## 0.1.2 (2017-03-23)
|
||||
|
||||
Features:
|
||||
### Features
|
||||
|
||||
* simplification of output formulas (optional)
|
||||
* command-line option `--simplify` to turn on simplification
|
||||
|
||||
Bug Fixes:
|
||||
### Bug Fixes
|
||||
|
||||
* fixes incorrectly translated choice rules with multiple elements in the head aggregate
|
||||
|
||||
Internal:
|
||||
### Internal
|
||||
|
||||
* explicit syntax tree representation for first-order formulas
|
||||
|
||||
## 0.1.1 (2017-03-06)
|
||||
|
||||
Features:
|
||||
### Features
|
||||
|
||||
* support for choice rules (without guards)
|
||||
|
||||
## 0.1.0 (2016-11-24)
|
||||
|
||||
Features:
|
||||
### Features
|
||||
|
||||
* initial support for translating rules in *Essential Gringo* (excluding aggregates) to first-order logic formulas
|
||||
* command-line option `--color` to autodetect, enable, or disable color output
|
||||
|
@@ -70,7 +70,7 @@ int main(int argc, char **argv)
|
||||
|
||||
if (version)
|
||||
{
|
||||
std::cout << "anthem version 0.1.7-git" << std::endl;
|
||||
std::cout << "anthem version 0.1.7-rc.2" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@@ -31,6 +31,7 @@ struct Context
|
||||
bool performCompletion = false;
|
||||
|
||||
std::optional<std::vector<ast::PredicateSignature>> visiblePredicateSignatures;
|
||||
std::optional<std::vector<ast::PredicateSignature>> externalPredicateSignatures;
|
||||
|
||||
ast::ParenthesisStyle parenthesisStyle = ast::ParenthesisStyle::Normal;
|
||||
};
|
||||
|
@@ -184,6 +184,43 @@ struct StatementVisitor
|
||||
throw LogicException(statement.location, "only #show statements for atoms (not terms) are supported currently");
|
||||
}
|
||||
|
||||
void visit(const Clingo::AST::External &external, const Clingo::AST::Statement &statement, std::vector<ast::ScopedFormula> &, Context &context)
|
||||
{
|
||||
const auto fail =
|
||||
[&]()
|
||||
{
|
||||
throw LogicException(statement.location, "only #external declarations of the form “#external <predicate name>(<arity>).” supported");
|
||||
};
|
||||
|
||||
if (!external.body.empty())
|
||||
fail();
|
||||
|
||||
if (!external.atom.data.is<Clingo::AST::Function>())
|
||||
fail();
|
||||
|
||||
const auto &predicate = external.atom.data.get<Clingo::AST::Function>();
|
||||
|
||||
if (predicate.arguments.size() != 1)
|
||||
fail();
|
||||
|
||||
const auto &arityArgument = predicate.arguments.front();
|
||||
|
||||
if (!arityArgument.data.is<Clingo::Symbol>())
|
||||
fail();
|
||||
|
||||
const auto &aritySymbol = arityArgument.data.get<Clingo::Symbol>();
|
||||
|
||||
if (aritySymbol.type() != Clingo::SymbolType::Number)
|
||||
fail();
|
||||
|
||||
const auto &arity = arityArgument.data.get<Clingo::Symbol>().number();
|
||||
|
||||
if (!context.externalPredicateSignatures)
|
||||
context.externalPredicateSignatures.emplace();
|
||||
|
||||
context.externalPredicateSignatures->emplace_back(std::string(predicate.name), arity);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void visit(const T &, const Clingo::AST::Statement &statement, std::vector<ast::ScopedFormula> &, Context &)
|
||||
{
|
||||
|
Submodule lib/cxxopts updated: 8893afe13c...abe9ebd6b4
@@ -180,9 +180,47 @@ std::vector<ast::Formula> complete(std::vector<ast::ScopedFormula> &&scopedFormu
|
||||
|
||||
std::vector<ast::Formula> completedFormulas;
|
||||
|
||||
// Warn about incorrect #external declarations
|
||||
if (context.externalPredicateSignatures)
|
||||
for (const auto &externalPredicateSignature : *context.externalPredicateSignatures)
|
||||
{
|
||||
// TODO: avoid code duplication
|
||||
const auto matchesPredicateSignature =
|
||||
[&](const auto &otherPredicateSignature)
|
||||
{
|
||||
return ast::matches(externalPredicateSignature, otherPredicateSignature);
|
||||
};
|
||||
|
||||
const auto matchingPredicateSignature =
|
||||
std::find_if(predicateSignatures.cbegin(), predicateSignatures.cend(), matchesPredicateSignature);
|
||||
|
||||
if (matchingPredicateSignature == predicateSignatures.cend())
|
||||
context.logger.log(output::Priority::Warning) << "#external declaration of “" << externalPredicateSignature.name << "/" << externalPredicateSignature.arity <<"” does not match any known predicate";
|
||||
}
|
||||
|
||||
// Complete predicates
|
||||
for (const auto &predicateSignature : predicateSignatures)
|
||||
{
|
||||
// Don’t complete predicates that are declared #external
|
||||
if (context.externalPredicateSignatures)
|
||||
{
|
||||
const auto matchesPredicateSignature =
|
||||
[&](const auto &otherPredicateSignature)
|
||||
{
|
||||
return ast::matches(predicateSignature, otherPredicateSignature);
|
||||
};
|
||||
|
||||
const auto &externalPredicateSignatures = context.externalPredicateSignatures.value();
|
||||
|
||||
const auto matchingExternalPredicateSignature =
|
||||
std::find_if(externalPredicateSignatures.cbegin(), externalPredicateSignatures.cend(), matchesPredicateSignature);
|
||||
|
||||
if (matchingExternalPredicateSignature != externalPredicateSignatures.cend())
|
||||
continue;
|
||||
}
|
||||
|
||||
completedFormulas.emplace_back(completePredicate(predicateSignature, scopedFormulas));
|
||||
}
|
||||
|
||||
// Complete integrity constraints
|
||||
for (auto &scopedFormula : scopedFormulas)
|
||||
|
@@ -217,19 +217,31 @@ void eliminateHiddenPredicates(const std::vector<ast::PredicateSignature> &predi
|
||||
{
|
||||
auto &predicateSignature = predicateSignatures[i];
|
||||
|
||||
const auto matchesVisiblePredicateSignature =
|
||||
[&](const auto &visiblePredicateSignature)
|
||||
const auto matchesPredicateSignature =
|
||||
[&](const auto &otherPredicateSignature)
|
||||
{
|
||||
return ast::matches(predicateSignature, visiblePredicateSignature);
|
||||
return ast::matches(predicateSignature, otherPredicateSignature);
|
||||
};
|
||||
|
||||
const auto matchingPredicateSignature =
|
||||
std::find_if(visiblePredicateSignatures.cbegin(), visiblePredicateSignatures.cend(), matchesVisiblePredicateSignature);
|
||||
const auto matchingVisiblePredicateSignature =
|
||||
std::find_if(visiblePredicateSignatures.cbegin(), visiblePredicateSignatures.cend(), matchesPredicateSignature);
|
||||
|
||||
// If the predicate ought to be visible, don’t eliminate it
|
||||
if (matchingPredicateSignature != visiblePredicateSignatures.cend())
|
||||
if (matchingVisiblePredicateSignature != visiblePredicateSignatures.cend())
|
||||
continue;
|
||||
|
||||
// Check that the predicate is not declared #external
|
||||
if (context.externalPredicateSignatures)
|
||||
{
|
||||
const auto &externalPredicateSignatures = context.externalPredicateSignatures.value();
|
||||
|
||||
const auto matchingExternalPredicateSignature =
|
||||
std::find_if(externalPredicateSignatures.cbegin(), externalPredicateSignatures.cend(), matchesPredicateSignature);
|
||||
|
||||
if (matchingExternalPredicateSignature != externalPredicateSignatures.cend())
|
||||
continue;
|
||||
}
|
||||
|
||||
context.logger.log(output::Priority::Debug) << "eliminating “" << predicateSignature.name << "/" << predicateSignature.arity << "”";
|
||||
|
||||
const auto &completedPredicateDefinition = completedFormulas[i];
|
||||
|
@@ -70,6 +70,9 @@ void translate(const char *fileName, std::istream &stream, Context &context)
|
||||
if (context.visiblePredicateSignatures)
|
||||
context.logger.log(output::Priority::Warning) << "#show statements are ignored because completion is not enabled";
|
||||
|
||||
if (context.externalPredicateSignatures)
|
||||
context.logger.log(output::Priority::Warning) << "#external statements are ignored because completion is not enabled";
|
||||
|
||||
for (const auto &scopedFormula : scopedFormulas)
|
||||
{
|
||||
ast::print(context.logger.outputStream(), scopedFormula.formula, printContext);
|
||||
|
Reference in New Issue
Block a user