NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
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 "../ui/language.hpp"
37#include "muParserDef.h"
38
39extern Language _lang;
40
45namespace mu
46{
47
50{
51 // Formula syntax errors
70
71 // Invalid Parser input Parameters
76
82 ecOPT_PRI = 27,
83 //
86 ecGENERIC = 30,
87 ecLOCALE = 31,
88
92
93 // internal errors
95
96 // The last two are special entries
98 ecUNDEFINED = -1
99};
100
101//---------------------------------------------------------------------------
105{
106public:
108
112
114
115 static const ParserErrorMsg& Instance();
116 string_type operator[](unsigned a_iIdx) const;
117
118private:
119 std::vector<string_type> m_vErrMsg;
120 static const self_type m_Instance;
121};
122
123//---------------------------------------------------------------------------
130{
131private:
132
134 void ReplaceSubString( string_type &strSource,
135 const string_type &strFind,
136 const string_type &strReplaceWith);
137 void Reset();
138
139public:
140
141 ParserError();
142 explicit ParserError(EErrorCodes a_iErrc);
143 explicit ParserError(const string_type &sMsg);
144 ParserError( EErrorCodes a_iErrc,
145 const string_type &sTok,
146 const string_type &sFormula = string_type(_nrT("(formula is not available)")),
147 int a_iPos = -1);
148 ParserError( EErrorCodes a_iErrc,
149 int a_iPos,
150 const string_type &sTok);
151 ParserError( const char_type *a_szMsg,
152 int a_iPos = -1,
153 const string_type &sTok = string_type());
154 ParserError(const ParserError &a_Obj);
155 ParserError& operator=(const ParserError &a_Obj);
156 ~ParserError();
157
158 void SetFormula(const string_type &a_strFormula);
159 const string_type& GetExpr() const;
160 const string_type& GetMsg() const;
161 std::size_t GetPos() const;
162 const string_type& GetToken() const;
163 EErrorCodes GetCode() const;
164
165private:
169 int m_iPos;
172};
173
174} // namespace mu
175
176#endif
177
This class handles the internal language system and returns the language strings of the selected lang...
Definition: language.hpp:38
Error class of the parser.
EErrorCodes GetCode() const
Return the error code.
void SetFormula(const string_type &a_strFormula)
Set the expression related to this error.
std::size_t GetPos() const
Return the formula position related to the error.
string_type m_strMsg
The message string.
void ReplaceSubString(string_type &strSource, const string_type &strFind, const string_type &strReplaceWith)
Replace all ocuurences of a substring with another string.
const ParserErrorMsg & m_ErrMsg
string_type m_strTok
Token related with the error.
int m_iPos
Formula position related to the error.
string_type m_strFormula
Formula string.
EErrorCodes m_iErrc
Error code.
const string_type & GetMsg() const
Returns the message string for this error.
const string_type & GetExpr() const
gets the expression related tp this error.
const string_type & GetToken() const
Return string related with this token (if available).
ParserError()
Default constructor.
void Reset()
Reset the erro object.
ParserError & operator=(const ParserError &a_Obj)
Assignment operator.
A class that handles the error messages.
ParserErrorMsg self_type
ParserErrorMsg & operator=(const ParserErrorMsg &)
Assignement operator is deactivated.
static const self_type m_Instance
The instance pointer.
string_type operator[](unsigned a_iIdx) const
static const ParserErrorMsg & Instance()
std::vector< string_type > m_vErrMsg
A vector with the predefined error messages.
This file contains standard definitions used by the parser.
#define _nrT(x)
Activate this option in order to compile with OpenMP support.
Definition: muParserDef.h:62
Language _lang
Definition: kernel.cpp:39
Namespace for mathematical applications.
Definition: muParser.cpp:53
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:263
EErrorCodes
Error codes.
Definition: muParserError.h:50
@ ecINVALID_NAME
Invalid function, variable or constant name.
Definition: muParserError.h:72
@ ecINVALID_BINOP_IDENT
Invalid binary operator identifier.
Definition: muParserError.h:73
@ ecMISPLACED_COLON
Definition: muParserError.h:91
@ ecUNASSIGNABLE_TOKEN
Token cant be identified.
Definition: muParserError.h:53
@ ecMISSING_PARENS
Missing parens. (Example: "3*sin(3")
Definition: muParserError.h:63
@ ecBUILTIN_OVERLOAD
Trying to overload builtin operator.
Definition: muParserError.h:77
@ ecUNEXPECTED_EOF
Unexpected end of formula. (Example: "2+sin(")
Definition: muParserError.h:54
@ ecUNEXPECTED_VAR
An unexpected variable token has been found.
Definition: muParserError.h:58
@ ecNAME_CONFLICT
Name conflict.
Definition: muParserError.h:81
@ ecSTRING_EXPECTED
A string function has been called with a different type of argument.
Definition: muParserError.h:61
@ ecTOO_MANY_PARAMS
Too many function parameters.
Definition: muParserError.h:66
@ ecUNDEFINED
Undefined message, placeholder to detect unassigned error messages.
Definition: muParserError.h:98
@ ecVAL_EXPECTED
A numerical function has been called with a non value type of argument.
Definition: muParserError.h:62
@ ecUNEXPECTED_FUN
Unexpected function found. (Example: "sin(8)cos(9)")
Definition: muParserError.h:64
@ ecSTR_RESULT
result is a string
Definition: muParserError.h:69
@ ecUNEXPECTED_ARG
An unexpected argument has been found.
Definition: muParserError.h:56
@ ecUNEXPECTED_OPERATOR
Unexpected binary operator found.
Definition: muParserError.h:52
@ ecINVALID_INFIX_IDENT
Invalid function, variable or constant name.
Definition: muParserError.h:74
@ ecOPRT_TYPE_CONFLICT
binary operators may only be applied to value items of the same type
Definition: muParserError.h:68
@ ecLOCALE
Conflict with current locale.
Definition: muParserError.h:87
@ ecUNEXPECTED_STR
A string has been found at an inapropriate position.
Definition: muParserError.h:60
@ ecUNEXPECTED_PARENS
Unexpected Parenthesis, opening or closing.
Definition: muParserError.h:59
@ ecINTERNAL_ERROR
Internal error of any kind.
Definition: muParserError.h:94
@ ecDOMAIN_ERROR
catch division by zero, sqrt(-1), log(0) (currently unused)
Definition: muParserError.h:84
@ ecINVALID_VAR_PTR
Invalid variable pointer.
Definition: muParserError.h:79
@ ecUNEXPECTED_ARG_SEP
An unexpected comma has been found. (Example: "1,23")
Definition: muParserError.h:55
@ ecMISSING_ELSE_CLAUSE
Definition: muParserError.h:90
@ ecOPT_PRI
Invalid operator priority.
Definition: muParserError.h:82
@ ecUNTERMINATED_STRING
unterminated string constant. (Example: "3*valueof("hello)")
Definition: muParserError.h:65
@ ecUNEXPECTED_CONDITIONAL
Definition: muParserError.h:89
@ ecINVALID_FUN_PTR
Invalid callback function pointer.
Definition: muParserError.h:78
@ ecTOO_FEW_PARAMS
Too few function parameters. (Example: "ite(1<2,2)")
Definition: muParserError.h:67
@ ecCOUNT
This is no error code, It just stores just the total number of error codes.
Definition: muParserError.h:97
@ ecINVALID_POSTFIX_IDENT
Invalid function, variable or constant name.
Definition: muParserError.h:75
@ ecEMPTY_EXPRESSION
The Expression is empty.
Definition: muParserError.h:80
@ ecGENERIC
Generic error.
Definition: muParserError.h:86
@ ecUNEXPECTED_VAL
An unexpected value token has been found.
Definition: muParserError.h:57
@ ecDIV_BY_ZERO
Division by zero (currently unused)
Definition: muParserError.h:85
std::string string_type
The stringtype used by the parser.
Definition: muParserDef.h:257