Files
spark/src/lib/expression/ParserExceptions.cpp
T

78 lines
2.2 KiB
C++

#include "ParserExceptions.h"
#include <boost/lexical_cast.hpp>
#include <sstream>
namespace bts {
namespace expression {
//
// ParserException
//
ParserException::ParserException(const char *what)
: std::logic_error(""), _what(what) {}
ParserException::ParserException(const std::string &what)
: std::logic_error(""), _what(what) {}
ParserException::ParserException(const ParserException &other)
: std::logic_error(""), _what(other._what) {}
ParserException &ParserException::operator=(const ParserException &other) {
_what = other._what;
return *this;
}
const char *ParserException::what() const throw() { return _what.c_str(); }
ParserException::~ParserException() throw() {}
//
// ParseFailedException
//
ParseFailedException::ParseFailedException(
const std::string &context, size_t at)
: ParserException(
"Parse failed at position: " + boost::lexical_cast<std::string>(at) +
" in expression: " + context),
context(context) {}
//
// InvalidPropertyException
//
InvalidPropertyException::InvalidPropertyException(const std::string &prop_name)
: ParserException("Invalid property name: " + prop_name) {}
//
// InsuficientArgumentsException
//
InsuficientArgumentsException::InsuficientArgumentsException(
const std::string &op, const std::string &got, size_t expected)
: ParserException(""), expected_argument_count(expected), expression(got) {
std::ostringstream what;
what << "Bad argument count for operator " << op << std::endl
<< "expected " << expected_argument_count << " arguments. Got '"
<< expression << "'";
_what = what.str();
}
//
// RecursivePropertyGetException
//
RecursivePropertyGetException::RecursivePropertyGetException(
const std::string &property, const std::vector<std::string> &stack)
: ParserException("") {
std::ostringstream what;
what << "Error evaluating property '" << property
<< "': recursive property request at:" << std::endl;
std::vector<std::string>::const_reverse_iterator iter = stack.rbegin();
std::vector<std::string>::const_reverse_iterator end = stack.rend();
for (; iter != end; iter++) {
what << "> " << *iter << std::endl;
}
_what = what.str();
}
} // namespace expression
} // namespace bts