Implement printing of pp_err_t
Another great thing for C++: the ability to tell it how to print structures the way I want. In C it's either: 1) Write a function to print the structure out (preferably to a file pointer) 2) Write a function to return a string (allocated on the heap) which represents it Both are not fun to write, whereas it's much easier to write this.
This commit is contained in:
@@ -63,6 +63,31 @@ preprocess_use_blocks(vector<token_t *> tokens)
|
||||
return VAL(new_tokens);
|
||||
}
|
||||
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, pp_err_t &err)
|
||||
{
|
||||
os << "PREPROCESSING_";
|
||||
switch (err.type)
|
||||
{
|
||||
case OK:
|
||||
return os << "OK";
|
||||
case EXPECTED_NAME:
|
||||
return os << "EXPECTED_NAME";
|
||||
case EXPECTED_STRING:
|
||||
return os << "EXPECTED_STRING";
|
||||
case EXPECTED_END:
|
||||
return os << "EXPECTED_END";
|
||||
case FILE_NONEXISTENT:
|
||||
return os << "FILE_NONEXISTENT";
|
||||
case FILE_PARSE_ERROR:
|
||||
return os << "FILE_PARSE_ERROR -> \n\t[" << err.reference->content
|
||||
<< "]: " << lerr_as_cstr(err.lerr);
|
||||
case UNKNOWN_NAME:
|
||||
return os << "UNKNOWN_NAME";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
pp_err_t::pp_err_t(pp_err_type_t e)
|
||||
: reference{nullptr}, type{e}, lerr{lerr_t::OK}
|
||||
{}
|
||||
|
||||
Reference in New Issue
Block a user