2
Copyright (C) 2004, 2005 Ingo Berg
4
Permission is hereby granted, free of charge, to any person obtaining a copy of this
5
software and associated documentation files (the "Software"), to deal in the Software
6
without restriction, including without limitation the rights to use, copy, modify,
7
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
8
permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
The above copyright notice and this permission notice shall be included in all copies or
11
substantial portions of the Software.
13
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
#ifndef MU_PARSER_ERROR_H
20
#define MU_PARSER_ERROR_H
29
#include "muParserDef.h"
35
/** \brief Error codes. */
38
// Formula syntax errors
39
ecUNEXPECTED_OPERATOR = 0, ///< Unexpected binary operator found
40
ecUNASSIGNABLE_TOKEN, ///< Token cant be identified.
41
ecUNEXPECTED_EOF, ///< Unexpected end of formula. (Example: "2+sin(")
42
ecUNEXPECTED_COMMA, ///< An unexpected comma has been found. (Example: "1,23")
43
ecUNEXPECTED_ARG, ///< An unexpected argument has been found
44
ecUNEXPECTED_VAL, ///< An unexpected value token has been found
45
ecUNEXPECTED_VAR, ///< An unexpected variable token has been found
46
ecUNEXPECTED_PARENS, ///< Unexpected Parenthesis, opening or closing
47
ecUNEXPECTED_STR, ///< A string has been found at an inapropriate position
48
ecSTRING_EXPECTED, ///< A string function has been called with a different type of argument
49
ecVAL_EXPECTED, ///< A numerical function has been called with a non value type of argument
50
ecMISSING_PARENS, ///< Missing parens. (Example: "3*sin(3")
51
ecUNEXPECTED_FUN, ///< Unexpected function found. (Example: "sin(8)cos(9)")
52
ecUNTERMINATED_STRING, ///< unterminated string constant. (Example: "3*valueof("hello)")
53
ecTOO_MANY_PARAMS, ///< Too many function parameters
54
ecTOO_FEW_PARAMS, ///< Too few function parameters. (Example: "ite(1<2,2)")
55
ecOPRT_TYPE_CONFLICT, ///< binary operators may only be applied to value items of the same type
56
ecSTR_RESULT, ///< result is a string
58
// Invalid Parser input Parameters
59
ecINVALID_NAME, ///< Invalid function, variable or constant name.
60
ecBUILTIN_OVERLOAD, ///< Trying to overload builtin operator
61
ecINVALID_FUN_PTR, ///< Invalid callback function pointer
62
ecINVALID_VAR_PTR, ///< Invalid variable pointer
64
ecNAME_CONFLICT, ///< Name conflict
65
ecOPT_PRI, ///< Invalid operator priority
67
ecDOMAIN_ERROR, ///< catch division by zero, sqrt(-1), log(0) (currently unused)
68
ecDIV_BY_ZERO, ///< Division by zero (currently unused)
69
ecGENERIC, ///< Generic error
72
ecINTERNAL_ERROR, ///< Internal error of any kind.
74
// The last two are special entries
75
ecCOUNT, ///< This is no error code, It just stores just the total number of error codes
76
ecUNDEFINED = -1, ///< Undefined message, placeholder to detect unassigned error messages
79
//---------------------------------------------------------------------------
83
typedef ParserErrorMsg self_type;
87
static const ParserErrorMsg& Instance();
88
string_type operator[](unsigned a_iIdx) const;
91
std::vector<string_type> m_vErrMsg;
92
static const self_type m_Instance;
94
ParserErrorMsg& operator=(const ParserErrorMsg &);
95
ParserErrorMsg(const ParserErrorMsg&);
99
//---------------------------------------------------------------------------
100
/** \brief Error class of the parser.
102
Part of the math parser package.
106
/* final */ class ParserError
109
//------------------------------------------------------------------------------
110
/** \brief Replace all ocuurences of a substring with another string. */
111
void ReplaceSubString( string_type &strSource,
112
const string_type &strFind,
113
const string_type &strReplaceWith);
118
explicit ParserError(EErrorCodes a_iErrc);
119
explicit ParserError(const string_type &sMsg);
120
ParserError( EErrorCodes a_iErrc,
121
const string_type &sTok,
122
const string_type &sFormula = string_type("(formula is not available)"),
124
ParserError( EErrorCodes a_iErrc,
126
const string_type &sTok);
127
ParserError( const char_type *a_szMsg,
129
const string_type &sTok = string_type());
130
ParserError(const ParserError &a_Obj);
131
ParserError& operator=(const ParserError &a_Obj);
134
void SetFormula(const string_type &a_strFormula);
135
const string_type& GetExpr() const;
136
const string_type& GetMsg() const;
137
std::size_t GetPos() const;
138
const string_type& GetToken() const;
139
EErrorCodes GetCode() const;
142
string_type m_strMsg; ///< The message string
143
string_type m_strFormula; ///< Formula string
144
string_type m_strTok; ///< Token related with the error
145
int m_iPos; ///< Formula position related to the error
146
EErrorCodes m_iErrc; ///< Error code
147
const ParserErrorMsg &m_ErrMsg;