34 #pragma warning(disable : 26812) // MSVC wants to force me te use enum classes or bother me with pointless warnings
40 const ParserErrorMsg& ParserErrorMsg::Instance()
42 static const ParserErrorMsg instance;
47 string_type ParserErrorMsg::operator[](
unsigned a_iIdx)
const
49 return (a_iIdx < m_vErrMsg.size()) ? m_vErrMsg[a_iIdx] :
string_type();
53 ParserErrorMsg::ParserErrorMsg()
60 m_vErrMsg[
ecINVALID_NAME] =
_T(
"Invalid function-, variable- or constant name: \"$TOK$\".");
72 m_vErrMsg[
ecUNEXPECTED_VAL] =
_T(
"Unexpected value \"$TOK$\" found at position $POS$");
73 m_vErrMsg[
ecUNEXPECTED_VAR] =
_T(
"Unexpected variable \"$TOK$\" found at position $POS$");
74 m_vErrMsg[
ecUNEXPECTED_ARG] =
_T(
"Function arguments used without a function (position: $POS$)");
76 m_vErrMsg[
ecTOO_MANY_PARAMS] =
_T(
"Too many parameters for function \"$TOK$\" at expression position $POS$");
77 m_vErrMsg[
ecTOO_FEW_PARAMS] =
_T(
"Too few parameters for function \"$TOK$\" at expression position $POS$");
81 m_vErrMsg[
ecOPT_PRI] =
_T(
"Invalid value for operator priority (must be greater or equal to zero).");
82 m_vErrMsg[
ecBUILTIN_OVERLOAD] =
_T(
"user defined binary operator \"$TOK$\" conflicts with a built in operator.");
85 m_vErrMsg[
ecSTRING_EXPECTED] =
_T(
"String function called with a non string type of argument.");
86 m_vErrMsg[
ecVAL_EXPECTED] =
_T(
"String value used where a numerical argument is expected.");
88 m_vErrMsg[
ecSTR_RESULT] =
_T(
"Strings must only be used as function arguments!");
90 m_vErrMsg[
ecLOCALE] =
_T(
"Decimal separator is identic to function argument separator.");
91 m_vErrMsg[ecUNEXPECTED_CONDITIONAL] =
_T(
"The \"$TOK$\" operator must be preceded by a closing bracket.");
92 m_vErrMsg[ecMISSING_ELSE_CLAUSE] =
_T(
"If-then-else operator is missing an else clause");
93 m_vErrMsg[ecMISPLACED_COLON] =
_T(
"Misplaced colon at position $POS$");
94 m_vErrMsg[ecUNREASONABLE_NUMBER_OF_COMPUTATIONS] =
_T(
"Number of computations to small for bulk mode. (Vectorisation overhead too costly)");
100 for (
int i = 0; i <
ecCOUNT; ++i)
102 if (!m_vErrMsg[i].length())
103 throw std::runtime_error(
"Error definitions are incomplete!");
114 ParserError::ParserError()
137 m_strMsg = m_ErrMsg[m_iErrc];
139 stream << (int)m_iPos;
140 ReplaceSubString(m_strMsg,
_T(
"$POS$"), stream.str());
141 ReplaceSubString(m_strMsg,
_T(
"$TOK$"), m_strTok);
165 , m_strFormula(sExpr)
171 m_strMsg = m_ErrMsg[m_iErrc];
173 stream << (int)m_iPos;
174 ReplaceSubString(m_strMsg,
_T(
"$POS$"), stream.str());
175 ReplaceSubString(m_strMsg,
_T(
"$TOK$"), m_strTok);
192 m_strMsg = m_ErrMsg[m_iErrc];
194 stream << (int)m_iPos;
195 ReplaceSubString(m_strMsg,
_T(
"$POS$"), stream.str());
196 ReplaceSubString(m_strMsg,
_T(
"$TOK$"), m_strTok);
214 stream << (int)m_iPos;
215 ReplaceSubString(m_strMsg,
_T(
"$POS$"), stream.str());
216 ReplaceSubString(m_strMsg,
_T(
"$TOK$"), m_strTok);
222 :m_strMsg(a_Obj.m_strMsg)
223 , m_strFormula(a_Obj.m_strFormula)
224 , m_strTok(a_Obj.m_strTok)
225 , m_iPos(a_Obj.m_iPos)
226 , m_iErrc(a_Obj.m_iErrc)
238 m_strMsg = a_Obj.m_strMsg;
239 m_strFormula = a_Obj.m_strFormula;
240 m_strTok = a_Obj.m_strTok;
241 m_iPos = a_Obj.m_iPos;
242 m_iErrc = a_Obj.m_iErrc;
247 ParserError::~ParserError()
255 void ParserError::ReplaceSubString(
string_type& strSource,
260 string_type::size_type iPos(0), iNext(0);
264 iNext = strSource.find(strFind, iPos);
265 strResult.append(strSource, iPos, iNext - iPos);
267 if (iNext == string_type::npos)
270 strResult.append(strReplaceWith);
271 iPos = iNext + strFind.length();
274 strSource.swap(strResult);
279 void ParserError::Reset()
282 m_strFormula =
_T(
"");
292 m_strFormula = a_strFormula;
334 #if defined(_MSC_VER)
A class that handles the error messages.
#define _T(x)
Activate this option in order to compile with OpenMP support.
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
An unexpected comma has been found. (Example: "1,23")
Token can't be identified.
An unexpected argument has been found.
Division by zero (currently unused)
Throw an exception if the expression has more than 10000 characters. (an arbitrary limit) ...
Internal error of any kind.
unterminated string constant. (Example: "3*valueof("hello)")
Trying to overload builtin operator.
Undefined message, placeholder to detect unassigned error messages.
Unexpected function found. (Example: "sin(8)cos(9)")
std::basic_stringstream< char_type, std::char_traits< char_type >, std::allocator< char_type > > stringstream_type
Typedef for easily using stringstream that respect the parser stringtype.
This is no error code, It just stores just the total number of error codes.
An unexpected value token has been found.
Conflict with current locale.
catch division by zero, sqrt(-1), log(0) (currently unused)
An unexpected variable token has been found.
Invalid variable pointer.
Invalid function, variable or constant name.
void SetFormula(const string_type &a_strFormula)
Set the expression related to this error.
Error class of the parser.
Too many function parameters.
A numerical function has been called with a non value type of argument.
Namespace for mathematical applications.
Unexpected end of formula. (Example: "2+sin(")
Too few function parameters. (Example: "ite(1<2,2)")
A string function has been called with a different type of argument.
EErrorCodes GetCode() const
Return the error code.
ParserError()
Default constructor.
string_type::value_type char_type
The character type used by the parser.
Thrown when an identifier with more then 255 characters is used.
Bytecode cannot be exported.
int GetPos() const
Return the formula position related to the error.
Unexpected binary operator found.
MUP_STRING_TYPE string_type
The stringtype used by the parser.
Invalid operator priority.
Unexpected Parenthesis, opening or closing.
Invalid function, variable or constant name.
Invalid callback function pointer.
The expression or identifier contains invalid non printable characters.
const string_type & GetToken() const
Return string related with this token (if available).
Missing parens. (Example: "3*sin(3")
const string_type & GetMsg() const
Returns the message string for this error.
A string has been found at an inapropriate position.
Invalid function, variable or constant name.
ParserError & operator=(const ParserError &a_Obj)
Assignment operator.
Invalid binary operator identifier.
This file defines the error class used by the parser.