Added back support for function symbols.
This commit is contained in:
parent
2b2049171f
commit
73f67f5c17
@ -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)}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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.";
|
||||
|
Loading…
Reference in New Issue
Block a user