Added back support for function symbols.

This commit is contained in:
Patrick Lühne 2017-03-15 17:01:09 +01:00
parent 2b2049171f
commit 73f67f5c17
No known key found for this signature in database
GPG Key ID: 05F3611E97A70ABF
3 changed files with 30 additions and 0 deletions

View File

@ -95,6 +95,11 @@ struct Constant
struct Function
{
Function(std::string &&name)
: name{std::move(name)}
{
}
Function(std::string &&name, std::vector<Term> &&arguments)
: name{std::move(name)},
arguments{std::move(arguments)}

View File

@ -57,6 +57,23 @@ struct TermTranslateVisitor
return std::make_unique<ast::SpecialInteger>(ast::SpecialInteger::Type::Supremum);
case Clingo::SymbolType::String:
return std::make_unique<ast::String>(std::string(symbol.string()));
case Clingo::SymbolType::Function:
{
auto function = std::make_unique<ast::Function>(symbol.name());
function->arguments.reserve(symbol.arguments().size());
for (const auto &argument : symbol.arguments())
{
auto translatedArgument = visit(argument, term, context);
if (!translatedArgument)
throwErrorAtLocation(term.location, "could not translate argument", context);
function->arguments.emplace_back(std::move(translatedArgument.value()));
}
return function;
}
default:
throwErrorAtLocation(term.location, "symbol type not supported", context);
}

View File

@ -90,6 +90,14 @@ TEST_CASE("[translation] Rules are translated correctly", "[translation]")
REQUIRE(output.str() == "(#true -> p)\n");
}
SECTION("function")
{
input << ":- not p(I), I = 1..n.";
anthem::translate("input", input, context);
REQUIRE(output.str() == "((exists X1 (X1 in I and not p(X1)) and exists X2, X3 (X2 in I and X3 in 1..n and X2 = X3)) -> #false)\n");
}
SECTION("disjunctive fact (no arguments)")
{
input << "q; p.";