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 #ifndef MU_PARSER_ERROR_H
00027 #define MU_PARSER_ERROR_H
00028
00029 #include <cassert>
00030 #include <stdexcept>
00031 #include <string>
00032 #include <sstream>
00033 #include <vector>
00034 #include <memory>
00035
00036 #include "muParserDef.h"
00037
00042 namespace mu
00043 {
00044
00046 enum EErrorCodes
00047 {
00048
00049 ecUNEXPECTED_OPERATOR = 0,
00050 ecUNASSIGNABLE_TOKEN = 1,
00051 ecUNEXPECTED_EOF = 2,
00052 ecUNEXPECTED_ARG_SEP = 3,
00053 ecUNEXPECTED_ARG = 4,
00054 ecUNEXPECTED_VAL = 5,
00055 ecUNEXPECTED_VAR = 6,
00056 ecUNEXPECTED_PARENS = 7,
00057 ecUNEXPECTED_STR = 8,
00058 ecSTRING_EXPECTED = 9,
00059 ecVAL_EXPECTED = 10,
00060 ecMISSING_PARENS = 11,
00061 ecUNEXPECTED_FUN = 12,
00062 ecUNTERMINATED_STRING = 13,
00063 ecTOO_MANY_PARAMS = 14,
00064 ecTOO_FEW_PARAMS = 15,
00065 ecOPRT_TYPE_CONFLICT = 16,
00066 ecSTR_RESULT = 17,
00067
00068
00069 ecINVALID_NAME = 18,
00070 ecBUILTIN_OVERLOAD = 19,
00071 ecINVALID_FUN_PTR = 20,
00072 ecINVALID_VAR_PTR = 21,
00073 ecEMPTY_EXPRESSION = 22,
00074 ecNAME_CONFLICT = 23,
00075 ecOPT_PRI = 24,
00076
00077 ecDOMAIN_ERROR = 25,
00078 ecDIV_BY_ZERO = 26,
00079 ecGENERIC = 27,
00080 ecLOCALE = 28,
00081
00082
00083 ecINTERNAL_ERROR = 29,
00084
00085
00086 ecCOUNT,
00087 ecUNDEFINED = -1
00088 };
00089
00090
00093 class ParserErrorMsg
00094 {
00095 public:
00096 typedef ParserErrorMsg self_type;
00097
00098 ParserErrorMsg& operator=(const ParserErrorMsg &);
00099 ParserErrorMsg(const ParserErrorMsg&);
00100 ParserErrorMsg();
00101
00102 ~ParserErrorMsg();
00103
00104 static const ParserErrorMsg& Instance();
00105 string_type operator[](unsigned a_iIdx) const;
00106
00107 private:
00108 std::vector<string_type> m_vErrMsg;
00109 static const self_type m_Instance;
00110 };
00111
00112
00119 class ParserError
00120 {
00121 private:
00122
00124 void ReplaceSubString( string_type &strSource,
00125 const string_type &strFind,
00126 const string_type &strReplaceWith);
00127 void Reset();
00128
00129 public:
00130 ParserError();
00131 explicit ParserError(EErrorCodes a_iErrc);
00132 explicit ParserError(const string_type &sMsg);
00133 ParserError( EErrorCodes a_iErrc,
00134 const string_type &sTok,
00135 const string_type &sFormula = string_type(_T("(formula is not available)")),
00136 int a_iPos = -1);
00137 ParserError( EErrorCodes a_iErrc,
00138 int a_iPos,
00139 const string_type &sTok);
00140 ParserError( const char_type *a_szMsg,
00141 int a_iPos = -1,
00142 const string_type &sTok = string_type());
00143 ParserError(const ParserError &a_Obj);
00144 ParserError& operator=(const ParserError &a_Obj);
00145 ~ParserError();
00146
00147 void SetFormula(const string_type &a_strFormula);
00148 const string_type& GetExpr() const;
00149 const string_type& GetMsg() const;
00150 std::size_t GetPos() const;
00151 const string_type& GetToken() const;
00152 EErrorCodes GetCode() const;
00153
00154 private:
00155 string_type m_strMsg;
00156 string_type m_strFormula;
00157 string_type m_strTok;
00158 int m_iPos;
00159 EErrorCodes m_iErrc;
00160 const ParserErrorMsg &m_ErrMsg;
00161 };
00162
00163 }
00164
00165 #endif
00166