00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "parse_util.hh"
00038 #include <sstream>
00039
00040 string fileName = "";
00041
00042 string formatError (const Position& pos, const string &message)
00043 {
00044 ostringstream ss;
00045 if (pos.ln) {
00046 if (fileName != "") ss << " " << fileName << ":";
00047 else ss << " ";
00048 ss << pos.ln << ":";
00049 if (pos.col) ss << pos.col << ":";
00050 }
00051 ss << " " << message;
00052 return ss.str();
00053 }
00054
00055
00056 string formatError (const string &message)
00057 {
00058 return formatError(Position(), message);
00059 }
00060
00061 string formatError (const ParseException &ex)
00062 {
00063 return formatError(ex.where(), ex.what());
00064 }
00065
00066 string formatWarning (const Position& pos, const string &message)
00067 {
00068 ostringstream ss;
00069 ss << "Warning:";
00070 if (pos.ln) {
00071 if (fileName != "") ss << " " << fileName << ":";
00072 else ss << " ";
00073 ss << pos.ln << ":";
00074 if (pos.col) ss << pos.col << ":";
00075 }
00076 ss << " " << message;
00077 return ss.str();
00078 }
00079
00080
00081 string formatWarning (const string &message)
00082 {
00083 return formatWarning(Position(), message);
00084 }
00085
00086
00087 void die (const string &message)
00088 {
00089 cerr << message << endl;
00090 cerr.flush();
00091 exit(1);
00092 }