MADNESS  version 0.9
muParserError.h
Go to the documentation of this file.
1 /*
2  __________
3  _____ __ __\______ \_____ _______ ______ ____ _______
4  / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5  | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6  |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7  \/ \/ \/ \/
8  Copyright (C) 2004-2008 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 
42 namespace mu
43 {
44 
47 {
48  // Formula syntax errors
66  ecSTR_RESULT = 17,
67 
68  // Invalid Parser input Parameters
75  ecOPT_PRI = 24,
76  //
79  ecGENERIC = 27,
80  ecLOCALE = 28,
81 
82  // internal errors
84 
85  // The last two are special entries
88 };
89 
90 //---------------------------------------------------------------------------
94 {
95 public:
97 
100  ParserErrorMsg();
101 
102  ~ParserErrorMsg();
103 
104  static const ParserErrorMsg& Instance();
105  string_type operator[](unsigned a_iIdx) const;
106 
107 private:
108  std::vector<string_type> m_vErrMsg;
109  static const self_type m_Instance;
110 };
111 
112 //---------------------------------------------------------------------------
119 /* final */ class ParserError
120 {
121 private:
122  //------------------------------------------------------------------------------
124  void ReplaceSubString( string_type &strSource,
125  const string_type &strFind,
126  const string_type &strReplaceWith);
127  void Reset();
128 
129 public:
130  ParserError();
131  explicit ParserError(EErrorCodes a_iErrc);
132  explicit ParserError(const string_type &sMsg);
133  ParserError( EErrorCodes a_iErrc,
134  const string_type &sTok,
135  const string_type &sFormula = string_type(_T("(formula is not available)")),
136  int a_iPos = -1);
137  ParserError( EErrorCodes a_iErrc,
138  int a_iPos,
139  const string_type &sTok);
140  ParserError( const char_type *a_szMsg,
141  int a_iPos = -1,
142  const string_type &sTok = string_type());
143  ParserError(const ParserError &a_Obj);
144  ParserError& operator=(const ParserError &a_Obj);
145  ~ParserError();
146 
147  void SetFormula(const string_type &a_strFormula);
148  const string_type& GetExpr() const;
149  const string_type& GetMsg() const;
150  std::size_t GetPos() const;
151  const string_type& GetToken() const;
152  EErrorCodes GetCode() const;
153 
154 private:
155  string_type m_strMsg;
156  string_type m_strFormula;
157  string_type m_strTok;
158  int m_iPos;
159  EErrorCodes m_iErrc;
160  const ParserErrorMsg &m_ErrMsg;
161 };
162 
163 } // namespace mu
164 
165 #endif
166 
A class that handles the error messages.
Definition: muParserError.h:93
const string_type & GetExpr() const
gets the expression related tp this error.
Definition: muParserError.cpp:292
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:78
~ParserErrorMsg()
Definition: muParserError.cpp:46
Name conflict.
Definition: muParserError.h:74
Internal error of any kind.
Definition: muParserError.h:83
~ParserError()
Definition: muParserError.cpp:242
unterminated string constant. (Example: "3*valueof('hello')")
Definition: muParserError.h:62
Trying to overload builtin operator.
Definition: muParserError.h:70
Undefined message, placeholder to detect unassigned error messages.
Definition: muParserError.h:87
ParserErrorMsg & operator=(const ParserErrorMsg &)
Assignement operator is deactivated.
Definition: muParserError.cpp:52
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:86
static const ParserErrorMsg & Instance()
Definition: muParserError.cpp:33
ParserErrorMsg()
Definition: muParserError.cpp:63
An unexpected value token has been found.
Definition: muParserError.h:54
Conflict with current locale.
Definition: muParserError.h:80
catch division by zero, sqrt(-1), log(0) (currently unused)
Definition: muParserError.h:77
An unexpected variable token has been found.
Definition: muParserError.h:55
Invalid variable pointer.
Definition: muParserError.h:72
Invalid function, variable or constant name.
Definition: muParserError.h:69
void SetFormula(const string_type &a_strFormula)
Set the expression related to this error.
Definition: muParserError.cpp:285
ParserErrorMsg self_type
Definition: muParserError.h:96
Error class of the parser.
Definition: muParserError.h:119
std::size_t GetPos() const
Return the formula position related to the error.
Definition: muParserError.cpp:309
string_type operator[](unsigned a_iIdx) const
Definition: muParserError.cpp:39
The Expression is empty.
Definition: muParserError.h:73
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:47
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.
Definition: muParserError.cpp:323
ParserError()
Default constructor.
Definition: muParserError.cpp:117
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:240
Unexpected binary operator found.
Definition: muParserError.h:49
MUP_STRING_TYPE string_type
The stringtype used by the parser.
Definition: muParserDef.h:228
#define _T
Definition: muParserDef.h:62
Invalid operator priority.
Definition: muParserError.h:75
Unexpected Parenthesis, opening or closing.
Definition: muParserError.h:56
Invalid callback function pointer.
Definition: muParserError.h:71
EErrorCodes
Error codes.
Definition: muParserError.h:46
Generic error.
Definition: muParserError.h:79
const string_type & GetToken() const
Return string related with this token (if available).
Definition: muParserError.cpp:316
Missing parens. (Example: "3*sin(3")
Definition: muParserError.h:60
const string_type & GetMsg() const
Returns the message string for this error.
Definition: muParserError.cpp:299
A string has been found at an inapropriate position.
Definition: muParserError.h:57
ParserError & operator=(const ParserError &a_Obj)
Assignment operator.
Definition: muParserError.cpp:228
This file contains standard definitions used by the parser.