29 #ifndef DOXYGEN_SHOULD_SKIP_THIS 39 is_error(is_error), line(line), column(0), msg(msg), filename(
""), code(
"") {
42 ParseError::ParseError(
bool is_error,
43 const std::string& msg,
44 const std::string& filename,
48 line(line), column(col), msg(msg), filename(filename), code(
"") {}
50 ParseError::ParseError(
bool is_error,
51 const std::string& msg,
52 const std::string& filename,
53 const std::string& code,
57 line(line), column(col), msg(msg), filename(filename), code(code) {}
59 ParseError::ParseError(
const ParseError& err) {
60 is_error = err.is_error;
64 filename = err.filename;
68 ParseError ParseError::operator=(
const ParseError& err) {
70 is_error = err.is_error;
74 filename = err.filename;
82 std::string ParseError::toString()
const {
85 if (!filename.empty()) s << filename <<
":";
87 if (line > 0) s << line <<
": ";
89 if (column > 0) s << column <<
" : ";
91 s << (is_error ?
"error" :
"warning") <<
" : " << msg;
97 std::string ParseError::toElegantString()
const {
99 std::ifstream ifs(filename.c_str());
101 for (
Idx i = 0; i < line; i++)
102 std::getline(ifs, code);
105 std::ostringstream s;
107 s << toString() << std::endl << code << std::endl;
109 if (column > 0) s << std::string(column - 1,
' ') <<
"^";
114 ParseError ErrorsContainer::error(
Idx i)
const {
118 GUM_ERROR(OutOfBounds,
"Index out of bound.");
122 ParseError ErrorsContainer::last()
const {
124 return errors[count() - 1];
126 GUM_ERROR(OutOfBounds,
"Index out of bound.");
130 ErrorsContainer::ErrorsContainer() {
135 ErrorsContainer::ErrorsContainer(
const ErrorsContainer& cont) {
136 error_count = cont.error_count;
137 warning_count = cont.warning_count;
139 errors = cont.errors;
143 ErrorsContainer newCont;
145 newCont.error_count = this->error_count + cont.error_count;
146 newCont.warning_count = this->warning_count + cont.warning_count;
147 std::copy(this->errors.begin(), this->errors.end(), newCont.errors.begin());
148 std::copy(cont.errors.begin(), cont.errors.end(), newCont.errors.end());
153 ErrorsContainer ErrorsContainer::operator=(
const ErrorsContainer& cont) {
154 error_count = cont.error_count;
155 warning_count = cont.warning_count;
157 errors = cont.errors;
162 ErrorsContainer ErrorsContainer::operator+=(
const ErrorsContainer& cont) {
163 error_count += cont.error_count;
164 warning_count += cont.warning_count;
166 for (
Idx i = 0; i < cont.count(); i++)
167 errors.push_back(cont.error(i));
172 void ErrorsContainer::simpleErrors(std::ostream& o)
const {
173 if (count() == 0)
return;
175 for (
Idx i = 0; i < count(); i++) {
176 if (error(i).is_error) o << error(i).toString() << std::endl;
180 void ErrorsContainer::simpleErrorsAndWarnings(std::ostream& o)
const {
181 if (count() == 0)
return;
183 for (
Idx i = 0; i < count(); i++)
184 o << error(i).toString() << std::endl;
187 void ErrorsContainer::elegantErrors(std::ostream& o)
const {
188 if (count() == 0)
return;
190 for (
Idx i = 0; i < count(); i++) {
191 if (error(i).is_error) {
192 o << error(i).toElegantString();
198 void ErrorsContainer::elegantErrorsAndWarnings(std::ostream& o)
const {
199 if (count() == 0)
return;
201 for (
Idx i = 0; i < count(); i++) {
202 o << error(i).toElegantString();
209 #endif // DOXYGEN_SHOULD_SKIP_THIS Inlined implementation of the basic methods of ErrorsContainer.
Errors container (at least) for parser.
ParseError(bool is_error, const std::string &msg, Idx line)
Class constructor.
gum is the global namespace for all aGrUM entities
void clear()
Clear all data of the calling expression as if it was constructed.
LpExpr operator+(LpExpr &&lhs, const T2 &rhs)
Overload of operator + between anything ( a scalar, a variable or an expression ) and anything except...
#define GUM_ERROR(type, msg)