2016-05-21 02:03:45 +02:00
|
|
|
#include <plasp/sas/Predicate.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
2016-05-22 16:00:58 +02:00
|
|
|
#include <limits>
|
|
|
|
#include <sstream>
|
|
|
|
|
2016-08-16 18:35:55 +02:00
|
|
|
#include <plasp/utils/Formatting.h>
|
2016-05-27 03:58:59 +02:00
|
|
|
#include <plasp/utils/ParserException.h>
|
2016-05-21 02:03:45 +02:00
|
|
|
|
|
|
|
namespace plasp
|
|
|
|
{
|
|
|
|
namespace sas
|
|
|
|
{
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Predicate
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-02 19:58:54 +02:00
|
|
|
Predicate Predicate::fromSAS(utils::Parser<> &parser)
|
2016-05-22 16:00:58 +02:00
|
|
|
{
|
|
|
|
Predicate predicate;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2016-05-27 03:58:59 +02:00
|
|
|
parser.skipLine();
|
2016-05-22 16:00:58 +02:00
|
|
|
|
2016-05-28 14:21:05 +02:00
|
|
|
predicate.m_name = parser.parse<std::string>();
|
2016-05-22 16:00:58 +02:00
|
|
|
|
2016-05-29 15:08:10 +02:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
// Parse arguments until reaching newline
|
2016-08-02 19:58:54 +02:00
|
|
|
// TODO: reimplement
|
|
|
|
/*parser.skipWhiteSpace(
|
2016-05-29 15:08:10 +02:00
|
|
|
[&](const auto character)
|
|
|
|
{
|
|
|
|
return character != '\n' && std::isspace(character);
|
2016-08-02 19:58:54 +02:00
|
|
|
});*/
|
2016-05-29 15:08:10 +02:00
|
|
|
|
|
|
|
if (parser.currentCharacter() == '\n')
|
|
|
|
break;
|
|
|
|
|
|
|
|
const auto value = parser.parse<std::string>();
|
|
|
|
predicate.m_arguments.emplace_back(std::move(value));
|
|
|
|
}
|
2016-05-22 16:00:58 +02:00
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
2016-08-02 19:58:54 +02:00
|
|
|
throw utils::ParserException(parser.coordinate(), "could not parse operator predicate");
|
2016-05-22 16:00:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return predicate;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const std::string &Predicate::name() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const Predicate::Arguments &Predicate::arguments() const
|
|
|
|
{
|
|
|
|
return m_arguments;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-06-14 17:35:32 +02:00
|
|
|
void Predicate::printAsSAS(utils::LogStream &outputStream) const
|
2016-05-22 16:00:58 +02:00
|
|
|
{
|
|
|
|
if (m_arguments.empty())
|
|
|
|
{
|
2016-06-14 17:35:32 +02:00
|
|
|
outputStream << m_name;
|
2016-05-22 16:00:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < m_arguments.size(); i++)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
2016-06-14 17:35:32 +02:00
|
|
|
outputStream << " ";
|
2016-05-22 16:00:58 +02:00
|
|
|
|
2016-06-14 17:35:32 +02:00
|
|
|
outputStream << m_arguments[i];
|
2016-05-22 16:00:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-06-14 17:35:32 +02:00
|
|
|
void Predicate::printAsASP(utils::LogStream &outputStream) const
|
2016-05-21 02:03:45 +02:00
|
|
|
{
|
2016-05-22 16:00:58 +02:00
|
|
|
if (m_arguments.empty())
|
|
|
|
{
|
2016-08-16 18:35:55 +02:00
|
|
|
outputStream << utils::String(m_name);
|
2016-05-22 16:00:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-05-21 02:31:47 +02:00
|
|
|
|
2016-08-16 18:35:55 +02:00
|
|
|
outputStream << "(" << utils::String(m_name);
|
2016-05-21 02:03:45 +02:00
|
|
|
|
2016-05-22 16:00:58 +02:00
|
|
|
for (size_t i = 0; i < m_arguments.size(); i++)
|
2016-08-16 18:35:55 +02:00
|
|
|
outputStream << ", " << utils::String(m_arguments[i]);
|
2016-05-21 02:03:45 +02:00
|
|
|
|
2016-06-14 17:35:32 +02:00
|
|
|
outputStream << ")";
|
2016-05-21 02:03:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|