muParser API -  1.35
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
muParserError.h
Go to the documentation of this file.
1 /*
2  __________
3  _____ __ __\______ \_____ _______ ______ ____ _______
4  / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5  | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6  |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7  \/ \/ \/ \/
8  Copyright (C) 2004-2011 Ingo Berg
9 
10  Permission is hereby granted, free of charge, to any person obtaining a copy of this
11  software and associated documentation files (the "Software"), to deal in the Software
12  without restriction, including without limitation the rights to use, copy, modify,
13  merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
14  permit persons to whom the Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in all copies or
17  substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
20  NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 
26 #ifndef MU_PARSER_ERROR_H
27 #define MU_PARSER_ERROR_H
28 
29 #include <cassert>
30 #include <stdexcept>
31 #include <string>
32 #include <sstream>
33 #include <vector>
34 #include <memory>
35 
36 #include "muParserDef.h"
37 
38 /** \file
39  \brief This file defines the error class used by the parser.
40 */
41 
42 namespace mu
43 {
44 
45 /** \brief Error codes. */
47 {
48  // Formula syntax errors
49  ecUNEXPECTED_OPERATOR = 0, ///< Unexpected binary operator found
50  ecUNASSIGNABLE_TOKEN = 1, ///< Token cant be identified.
51  ecUNEXPECTED_EOF = 2, ///< Unexpected end of formula. (Example: "2+sin(")
52  ecUNEXPECTED_ARG_SEP = 3, ///< An unexpected comma has been found. (Example: "1,23")
53  ecUNEXPECTED_ARG = 4, ///< An unexpected argument has been found
54  ecUNEXPECTED_VAL = 5, ///< An unexpected value token has been found
55  ecUNEXPECTED_VAR = 6, ///< An unexpected variable token has been found
56  ecUNEXPECTED_PARENS = 7, ///< Unexpected Parenthesis, opening or closing
57  ecUNEXPECTED_STR = 8, ///< A string has been found at an inapropriate position
58  ecSTRING_EXPECTED = 9, ///< A string function has been called with a different type of argument
59  ecVAL_EXPECTED = 10, ///< A numerical function has been called with a non value type of argument
60  ecMISSING_PARENS = 11, ///< Missing parens. (Example: "3*sin(3")
61  ecUNEXPECTED_FUN = 12, ///< Unexpected function found. (Example: "sin(8)cos(9)")
62  ecUNTERMINATED_STRING = 13, ///< unterminated string constant. (Example: "3*valueof("hello)")
63  ecTOO_MANY_PARAMS = 14, ///< Too many function parameters
64  ecTOO_FEW_PARAMS = 15, ///< Too few function parameters. (Example: "ite(1<2,2)")
65  ecOPRT_TYPE_CONFLICT = 16, ///< binary operators may only be applied to value items of the same type
66  ecSTR_RESULT = 17, ///< result is a string
67 
68  // Invalid Parser input Parameters
69  ecINVALID_NAME = 18, ///< Invalid function, variable or constant name.
70  ecINVALID_BINOP_IDENT = 19, ///< Invalid binary operator identifier
71  ecINVALID_INFIX_IDENT = 20, ///< Invalid function, variable or constant name.
72  ecINVALID_POSTFIX_IDENT = 21, ///< Invalid function, variable or constant name.
73 
74  ecBUILTIN_OVERLOAD = 22, ///< Trying to overload builtin operator
75  ecINVALID_FUN_PTR = 23, ///< Invalid callback function pointer
76  ecINVALID_VAR_PTR = 24, ///< Invalid variable pointer
77  ecEMPTY_EXPRESSION = 25, ///< The Expression is empty
78  ecNAME_CONFLICT = 26, ///< Name conflict
79  ecOPT_PRI = 27, ///< Invalid operator priority
80  //
81  ecDOMAIN_ERROR = 28, ///< catch division by zero, sqrt(-1), log(0) (currently unused)
82  ecDIV_BY_ZERO = 29, ///< Division by zero (currently unused)
83  ecGENERIC = 30, ///< Generic error
84  ecLOCALE = 31, ///< Conflict with current locale
85 
86  ecUNEXPECTED_CONDITIONAL = 32,
87  ecMISSING_ELSE_CLAUSE = 33,
88  ecMISPLACED_COLON = 34,
89 
90  ecUNREASONABLE_NUMBER_OF_COMPUTATIONS = 35,
91 
92  // internal errors
93  ecINTERNAL_ERROR = 36, ///< Internal error of any kind.
94 
95  // The last two are special entries
96  ecCOUNT, ///< This is no error code, It just stores just the total number of error codes
97  ecUNDEFINED = -1 ///< Undefined message, placeholder to detect unassigned error messages
98 };
99 
100 //---------------------------------------------------------------------------
101 /** \brief A class that handles the error messages.
102 */
104 {
105 public:
106  typedef ParserErrorMsg self_type;
107 
110  ParserErrorMsg();
111 
112  ~ParserErrorMsg();
113 
114  static const ParserErrorMsg& Instance();
115  string_type operator[](unsigned a_iIdx) const;
116 
117 private:
118  std::vector<string_type> m_vErrMsg; ///< A vector with the predefined error messages
119  static const self_type m_Instance; ///< The instance pointer
120 };
121 
122 //---------------------------------------------------------------------------
123 /** \brief Error class of the parser.
124  \author Ingo Berg
125 
126  Part of the math parser package.
127 */
129 {
130 private:
131 
132  /** \brief Replace all ocuurences of a substring with another string. */
133  void ReplaceSubString( string_type &strSource,
134  const string_type &strFind,
135  const string_type &strReplaceWith);
136  void Reset();
137 
138 public:
139 
140  ParserError();
141  explicit ParserError(EErrorCodes a_iErrc);
142  explicit ParserError(const string_type &sMsg);
143  ParserError( EErrorCodes a_iErrc,
144  const string_type &sTok,
145  const string_type &sFormula = string_type(),
146  int a_iPos = -1);
147  ParserError( EErrorCodes a_iErrc,
148  int a_iPos,
149  const string_type &sTok);
150  ParserError( const char_type *a_szMsg,
151  int a_iPos = -1,
152  const string_type &sTok = string_type());
153  ParserError(const ParserError &a_Obj);
154  ParserError& operator=(const ParserError &a_Obj);
155  ~ParserError();
156 
157  void SetFormula(const string_type &a_strFormula);
158  const string_type& GetExpr() const;
159  const string_type& GetMsg() const;
160  int GetPos() const;
161  const string_type& GetToken() const;
162  EErrorCodes GetCode() const;
163 
164 private:
165  string_type m_strMsg; ///< The message string
166  string_type m_strFormula; ///< Formula string
167  string_type m_strTok; ///< Token related with the error
168  int m_iPos; ///< Formula position related to the error
169  EErrorCodes m_iErrc; ///< Error code
170  const ParserErrorMsg &m_ErrMsg;
171 };
172 
173 } // namespace mu
174 
175 #endif
176 
A class that handles the error messages.
const string_type & GetExpr() const
gets the expression related tp this error.
binary operators may only be applied to value items of the same type
Definition: muParserError.h:65
An unexpected comma has been found. (Example: "1,23")
Definition: muParserError.h:52
Token cant be identified.
Definition: muParserError.h:50
result is a string
Definition: muParserError.h:66
An unexpected argument has been found.
Definition: muParserError.h:53
Division by zero (currently unused)
Definition: muParserError.h:82
Name conflict.
Definition: muParserError.h:78
Internal error of any kind.
Definition: muParserError.h:93
unterminated string constant. (Example: "3*valueof("hello)")
Definition: muParserError.h:62
Trying to overload builtin operator.
Definition: muParserError.h:74
Undefined message, placeholder to detect unassigned error messages.
Definition: muParserError.h:97
ParserErrorMsg & operator=(const ParserErrorMsg &)
Assignement operator is deactivated.
Unexpected function found. (Example: "sin(8)cos(9)")
Definition: muParserError.h:61
This is no error code, It just stores just the total number of error codes.
Definition: muParserError.h:96
An unexpected value token has been found.
Definition: muParserError.h:54
Conflict with current locale.
Definition: muParserError.h:84
catch division by zero, sqrt(-1), log(0) (currently unused)
Definition: muParserError.h:81
An unexpected variable token has been found.
Definition: muParserError.h:55
Invalid variable pointer.
Definition: muParserError.h:76
Invalid function, variable or constant name.
Definition: muParserError.h:69
void SetFormula(const string_type &a_strFormula)
Set the expression related to this error.
Error class of the parser.
The Expression is empty.
Definition: muParserError.h:77
Too many function parameters.
Definition: muParserError.h:63
A numerical function has been called with a non value type of argument.
Definition: muParserError.h:59
Namespace for mathematical applications.
Definition: muParser.cpp:49
Unexpected end of formula. (Example: "2+sin(")
Definition: muParserError.h:51
Too few function parameters. (Example: "ite(1<2,2)")
Definition: muParserError.h:64
A string function has been called with a different type of argument.
Definition: muParserError.h:58
EErrorCodes GetCode() const
Return the error code.
ParserError()
Default constructor.
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:259
int GetPos() const
Return the formula position related to the error.
Unexpected binary operator found.
Definition: muParserError.h:49
MUP_STRING_TYPE string_type
The stringtype used by the parser.
Definition: muParserDef.h:253
Invalid operator priority.
Definition: muParserError.h:79
Unexpected Parenthesis, opening or closing.
Definition: muParserError.h:56
Invalid function, variable or constant name.
Definition: muParserError.h:72
Invalid callback function pointer.
Definition: muParserError.h:75
EErrorCodes
Error codes.
Definition: muParserError.h:46
Generic error.
Definition: muParserError.h:83
const string_type & GetToken() const
Return string related with this token (if available).
Missing parens. (Example: "3*sin(3")
Definition: muParserError.h:60
const string_type & GetMsg() const
Returns the message string for this error.
A string has been found at an inapropriate position.
Definition: muParserError.h:57
Invalid function, variable or constant name.
Definition: muParserError.h:71
ParserError & operator=(const ParserError &a_Obj)
Assignment operator.
Invalid binary operator identifier.
Definition: muParserError.h:70
This file contains standard definitions used by the parser.