[muparser] Remove muParserError.h

To help remove exception handling, we will need to have a type that
has visibility into both ParserError and value_type. We're going to
put this type in muParserDef.h. Remove the error header and fold its
contents into muParserDef.h.
This commit is contained in:
ridiculousfish 2017-11-18 16:42:51 -08:00
parent 5f7f1102db
commit 38a2e0218d
10 changed files with 111 additions and 163 deletions

View File

@ -61,7 +61,6 @@ MUPARSER_LIB_HEADERS = \
include/muParserCallback.h \
include/muParserDLL.h \
include/muParserDef.h \
include/muParserError.h \
include/muParserFixes.h \
include/muParserInt.h \
include/muParserTemplateMagic.h \
@ -87,7 +86,6 @@ MUPARSER_DLL_HEADERS = \
include/muParserCallback.h \
include/muParserDLL.h \
include/muParserDef.h \
include/muParserError.h \
include/muParserFixes.h \
include/muParserInt.h \
include/muParserTemplateMagic.h \

View File

@ -37,7 +37,6 @@
//--- Parser includes --------------------------------------------------------------------------
#include "muParserBytecode.h"
#include "muParserDef.h"
#include "muParserError.h"
#include "muParserTokenReader.h"
namespace mu {

View File

@ -31,7 +31,6 @@
#include <vector>
#include "muParserDef.h"
#include "muParserError.h"
#include "muParserToken.h"
/** \file

View File

@ -100,10 +100,10 @@ namespace mu {
//------------------------------------------------------------------------------
/** \brief Encapsulate wcout. */
inline std::wostream& console() { return std::wcout; }
inline std::wostream &console() { return std::wcout; }
/** \brief Encapsulate cin. */
inline std::wistream& console_in() { return std::wcin; }
inline std::wistream &console_in() { return std::wcin; }
#else
@ -111,13 +111,13 @@ inline std::wistream& console_in() { return std::wcin; }
Used for supporting UNICODE more easily.
*/
inline std::ostream& console() { return std::cout; }
inline std::ostream &console() { return std::cout; }
/** \brief Encapsulate cin.
Used for supporting UNICODE more easily.
*/
inline std::istream& console_in() { return std::cin; }
inline std::istream &console_in() { return std::cin; }
#endif
@ -132,7 +132,7 @@ class ParserStack : public std::vector<T> {
return val;
}
T& top() { return this->back(); }
T &top() { return this->back(); }
void push(T val) { this->push_back(std::move(val)); }
};
@ -250,7 +250,7 @@ typedef std::basic_stringstream<char_type, std::char_traits<char_type>, std::all
// Data container types
/** \brief Type used for storing variables. */
typedef std::map<string_type, value_type*> varmap_type;
typedef std::map<string_type, value_type *> varmap_type;
/** \brief Type used for storing constants. */
typedef std::map<string_type, value_type> valmap_type;
@ -258,6 +258,102 @@ typedef std::map<string_type, value_type> valmap_type;
/** \brief Type for assigning a string name to an index in the internal string table. */
typedef std::map<string_type, std::size_t> strmap_type;
/** \brief Error codes. */
enum EErrorCodes {
// Formula syntax errors
ecUNEXPECTED_OPERATOR = 0, ///< Unexpected binary operator found
ecUNASSIGNABLE_TOKEN = 1, ///< Token cant be identified.
ecUNEXPECTED_EOF = 2, ///< Unexpected end of formula. (Example: "2+sin(")
ecUNEXPECTED_ARG_SEP = 3, ///< An unexpected comma has been found. (Example: "1,23")
ecUNEXPECTED_ARG = 4, ///< An unexpected argument has been found
ecUNEXPECTED_VAL = 5, ///< An unexpected value token has been found
ecUNEXPECTED_VAR = 6, ///< An unexpected variable token has been found
ecUNEXPECTED_PARENS = 7, ///< Unexpected Parenthesis, opening or closing
ecUNEXPECTED_STR = 8, ///< A string has been found at an inapropriate position
ecSTRING_EXPECTED = 9, ///< A string function has been called with a different type of argument
ecVAL_EXPECTED =
10, ///< A numerical function has been called with a non value type of argument
ecMISSING_PARENS = 11, ///< Missing parens. (Example: "3*sin(3")
ecUNEXPECTED_FUN = 12, ///< Unexpected function found. (Example: "sin(8)cos(9)")
ecUNTERMINATED_STRING = 13, ///< unterminated string constant. (Example: "3*valueof("hello)")
ecTOO_MANY_PARAMS = 14, ///< Too many function parameters
ecTOO_FEW_PARAMS = 15, ///< Too few function parameters. (Example: "ite(1<2,2)")
ecOPRT_TYPE_CONFLICT =
16, ///< binary operators may only be applied to value items of the same type
ecSTR_RESULT = 17, ///< result is a string
// Invalid Parser input Parameters
ecINVALID_NAME = 18, ///< Invalid function, variable or constant name.
ecINVALID_BINOP_IDENT = 19, ///< Invalid binary operator identifier
ecINVALID_INFIX_IDENT = 20, ///< Invalid function, variable or constant name.
ecINVALID_POSTFIX_IDENT = 21, ///< Invalid function, variable or constant name.
ecBUILTIN_OVERLOAD = 22, ///< Trying to overload builtin operator
ecINVALID_FUN_PTR = 23, ///< Invalid callback function pointer
ecINVALID_VAR_PTR = 24, ///< Invalid variable pointer
ecEMPTY_EXPRESSION = 25, ///< The Expression is empty
ecNAME_CONFLICT = 26, ///< Name conflict
ecOPT_PRI = 27, ///< Invalid operator priority
//
ecDOMAIN_ERROR = 28, ///< catch division by zero, sqrt(-1), log(0) (currently unused)
ecDIV_BY_ZERO = 29, ///< Division by zero (currently unused)
ecGENERIC = 30, ///< Generic error
ecLOCALE = 31, ///< Conflict with current locale
ecUNEXPECTED_CONDITIONAL = 32,
ecMISSING_ELSE_CLAUSE = 33,
ecMISPLACED_COLON = 34,
ecUNREASONABLE_NUMBER_OF_COMPUTATIONS = 35,
// The last two are special entries
ecCOUNT, ///< This is no error code, It just stores just the total number of error codes
ecUNDEFINED = -1 ///< Undefined message, placeholder to detect unassigned error messages
};
/// \return an error message for the given code.
string_type parser_error_for_code(EErrorCodes code);
//---------------------------------------------------------------------------
/** \brief Error class of the parser.
\author Ingo Berg
Part of the math parser package.
*/
class ParserError {
private:
/** \brief Replace all ocuurences of a substring with another string. */
void ReplaceSubString(string_type &strSource, const string_type &strFind,
const string_type &strReplaceWith);
void Reset();
public:
ParserError();
explicit ParserError(EErrorCodes a_iErrc);
explicit ParserError(const string_type &sMsg);
ParserError(EErrorCodes a_iErrc, const string_type &sTok,
const string_type &sFormula = string_type(), int a_iPos = -1);
ParserError(EErrorCodes a_iErrc, int a_iPos, const string_type &sTok);
ParserError(const char_type *a_szMsg, int a_iPos = -1, const string_type &sTok = string_type());
ParserError(const ParserError &a_Obj);
ParserError &operator=(const ParserError &a_Obj);
~ParserError();
void SetFormula(const string_type &a_strFormula);
const string_type &GetExpr() const;
const string_type &GetMsg() const;
int GetPos() const;
const string_type &GetToken() const;
EErrorCodes GetCode() const;
private:
string_type m_strMsg; ///< The message string
string_type m_strFormula; ///< Formula string
string_type m_strTok; ///< Token related with the error
int m_iPos; ///< Formula position related to the error
EErrorCodes m_iErrc; ///< Error code
};
// Parser callbacks
/** \brief Callback type used for functions without arguments. */
@ -342,22 +438,22 @@ typedef value_type (*bulkfun_type10)(int, int, value_type, value_type, value_typ
value_type);
/** \brief Callback type used for functions with a variable argument list. */
typedef value_type (*multfun_type)(const value_type*, int);
typedef value_type (*multfun_type)(const value_type *, int);
/** \brief Callback type used for functions taking a string as an argument. */
typedef value_type (*strfun_type1)(const char_type*);
typedef value_type (*strfun_type1)(const char_type *);
/** \brief Callback type used for functions taking a string and a value as arguments. */
typedef value_type (*strfun_type2)(const char_type*, value_type);
typedef value_type (*strfun_type2)(const char_type *, value_type);
/** \brief Callback type used for functions taking a string and two values as arguments. */
typedef value_type (*strfun_type3)(const char_type*, value_type, value_type);
typedef value_type (*strfun_type3)(const char_type *, value_type, value_type);
/** \brief Callback used for functions that identify values in a string. */
typedef int (*identfun_type)(const char_type* sExpr, int* nPos, value_type* fVal);
typedef int (*identfun_type)(const char_type *sExpr, int *nPos, value_type *fVal);
/** \brief Callback used for variable creation factory functions. */
typedef value_type* (*facfun_type)(const char_type*, void*);
typedef value_type *(*facfun_type)(const char_type *, void *);
} // end of namespace
#endif

View File

@ -1,142 +0,0 @@
/*
__________
_____ __ __\______ \_____ _______ ______ ____ _______
/ \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
| Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
|__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
\/ \/ \/ \/
Copyright (C) 2004-2011 Ingo Berg
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef MU_PARSER_ERROR_H
#define MU_PARSER_ERROR_H
#include <cassert>
#include <memory>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
#include "muParserDef.h"
/** \file
\brief This file defines the error class used by the parser.
*/
namespace mu {
/** \brief Error codes. */
enum EErrorCodes {
// Formula syntax errors
ecUNEXPECTED_OPERATOR = 0, ///< Unexpected binary operator found
ecUNASSIGNABLE_TOKEN = 1, ///< Token cant be identified.
ecUNEXPECTED_EOF = 2, ///< Unexpected end of formula. (Example: "2+sin(")
ecUNEXPECTED_ARG_SEP = 3, ///< An unexpected comma has been found. (Example: "1,23")
ecUNEXPECTED_ARG = 4, ///< An unexpected argument has been found
ecUNEXPECTED_VAL = 5, ///< An unexpected value token has been found
ecUNEXPECTED_VAR = 6, ///< An unexpected variable token has been found
ecUNEXPECTED_PARENS = 7, ///< Unexpected Parenthesis, opening or closing
ecUNEXPECTED_STR = 8, ///< A string has been found at an inapropriate position
ecSTRING_EXPECTED = 9, ///< A string function has been called with a different type of argument
ecVAL_EXPECTED =
10, ///< A numerical function has been called with a non value type of argument
ecMISSING_PARENS = 11, ///< Missing parens. (Example: "3*sin(3")
ecUNEXPECTED_FUN = 12, ///< Unexpected function found. (Example: "sin(8)cos(9)")
ecUNTERMINATED_STRING = 13, ///< unterminated string constant. (Example: "3*valueof("hello)")
ecTOO_MANY_PARAMS = 14, ///< Too many function parameters
ecTOO_FEW_PARAMS = 15, ///< Too few function parameters. (Example: "ite(1<2,2)")
ecOPRT_TYPE_CONFLICT =
16, ///< binary operators may only be applied to value items of the same type
ecSTR_RESULT = 17, ///< result is a string
// Invalid Parser input Parameters
ecINVALID_NAME = 18, ///< Invalid function, variable or constant name.
ecINVALID_BINOP_IDENT = 19, ///< Invalid binary operator identifier
ecINVALID_INFIX_IDENT = 20, ///< Invalid function, variable or constant name.
ecINVALID_POSTFIX_IDENT = 21, ///< Invalid function, variable or constant name.
ecBUILTIN_OVERLOAD = 22, ///< Trying to overload builtin operator
ecINVALID_FUN_PTR = 23, ///< Invalid callback function pointer
ecINVALID_VAR_PTR = 24, ///< Invalid variable pointer
ecEMPTY_EXPRESSION = 25, ///< The Expression is empty
ecNAME_CONFLICT = 26, ///< Name conflict
ecOPT_PRI = 27, ///< Invalid operator priority
//
ecDOMAIN_ERROR = 28, ///< catch division by zero, sqrt(-1), log(0) (currently unused)
ecDIV_BY_ZERO = 29, ///< Division by zero (currently unused)
ecGENERIC = 30, ///< Generic error
ecLOCALE = 31, ///< Conflict with current locale
ecUNEXPECTED_CONDITIONAL = 32,
ecMISSING_ELSE_CLAUSE = 33,
ecMISPLACED_COLON = 34,
ecUNREASONABLE_NUMBER_OF_COMPUTATIONS = 35,
// The last two are special entries
ecCOUNT, ///< This is no error code, It just stores just the total number of error codes
ecUNDEFINED = -1 ///< Undefined message, placeholder to detect unassigned error messages
};
/// \return an error message for the given code.
string_type parser_error_for_code(EErrorCodes code);
//---------------------------------------------------------------------------
/** \brief Error class of the parser.
\author Ingo Berg
Part of the math parser package.
*/
class ParserError {
private:
/** \brief Replace all ocuurences of a substring with another string. */
void ReplaceSubString(string_type &strSource, const string_type &strFind,
const string_type &strReplaceWith);
void Reset();
public:
ParserError();
explicit ParserError(EErrorCodes a_iErrc);
explicit ParserError(const string_type &sMsg);
ParserError(EErrorCodes a_iErrc, const string_type &sTok,
const string_type &sFormula = string_type(), int a_iPos = -1);
ParserError(EErrorCodes a_iErrc, int a_iPos, const string_type &sTok);
ParserError(const char_type *a_szMsg, int a_iPos = -1, const string_type &sTok = string_type());
ParserError(const ParserError &a_Obj);
ParserError &operator=(const ParserError &a_Obj);
~ParserError();
void SetFormula(const string_type &a_strFormula);
const string_type &GetExpr() const;
const string_type &GetMsg() const;
int GetPos() const;
const string_type &GetToken() const;
EErrorCodes GetCode() const;
private:
string_type m_strMsg; ///< The message string
string_type m_strFormula; ///< Formula string
string_type m_strTok; ///< Token related with the error
int m_iPos; ///< Formula position related to the error
EErrorCodes m_iErrc; ///< Error code
};
} // namespace mu
#endif

View File

@ -2,7 +2,6 @@
#define MU_PARSER_TEMPLATE_MAGIC_H
#include <cmath>
#include "muParserError.h"
namespace mu {
//-----------------------------------------------------------------------------------------------

View File

@ -33,7 +33,6 @@
#include <vector>
#include "muParserCallback.h"
#include "muParserError.h"
/** \file
\brief This file contains the parser token definition.

View File

@ -33,7 +33,6 @@
#include <vector>
#include "muParserDef.h"
#include "muParserError.h"
#include "muParserTemplateMagic.h"
#include "muParserToken.h"

View File

@ -40,7 +40,6 @@
#include "muParser.h"
#include "muParserDLL.h"
#include "muParserError.h"
#include "muParserInt.h"
#define MU_TRY try {

View File

@ -22,7 +22,9 @@
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "muParserError.h"
#include "muParserDef.h"
#include <assert.h>
namespace mu {
//---------------------------------------------------------------------------