patrick
/
plasp
Archived
1
0
Fork 0
This repository has been archived on 2023-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
plasp/src/plasp/sas/Predicate.cpp

103 lines
2.0 KiB
C++
Raw Normal View History

#include <plasp/sas/Predicate.h>
#include <iostream>
2016-05-22 16:00:58 +02:00
#include <limits>
#include <sstream>
2016-05-27 03:58:59 +02:00
#include <plasp/utils/IO.h>
#include <plasp/utils/ParserException.h>
namespace plasp
{
namespace sas
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Predicate
//
////////////////////////////////////////////////////////////////////////////////////////////////////
2016-05-27 03:58:59 +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-28 14:21:05 +02:00
parser.parseUntil(predicate.m_arguments, [](const auto character)
{
return character == '\n';
});
2016-05-22 16:00:58 +02:00
}
catch (const std::exception &e)
{
2016-05-27 03:58:59 +02:00
throw utils::ParserException(parser.row(), parser.column(), "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;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Predicate::printAsSAS(std::ostream &ostream) const
{
if (m_arguments.empty())
{
ostream << m_name;
return;
}
for (size_t i = 0; i < m_arguments.size(); i++)
{
if (i > 0)
ostream << " ";
ostream << m_arguments[i];
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Predicate::printAsASP(std::ostream &ostream) const
{
2016-05-22 16:00:58 +02:00
if (m_arguments.empty())
{
ostream << utils::escapeASP(m_name);
2016-05-22 16:00:58 +02:00
return;
}
2016-05-21 02:31:47 +02:00
ostream << utils::escapeASP(m_name) << "(";
2016-05-22 16:00:58 +02:00
for (size_t i = 0; i < m_arguments.size(); i++)
{
if (i > 0)
ostream << ", ";
ostream << utils::escapeASP(m_arguments[i]);
}
2016-05-22 16:00:58 +02:00
ostream << ")";
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}