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)");
99 for (
int i = 0; i <
ecCOUNT; ++i)
101 if (!m_vErrMsg[i].length())
102 throw std::runtime_error(
"Error definitions are incomplete!");
113 ParserError::ParserError()
136 m_strMsg = m_ErrMsg[m_iErrc];
138 stream << (int)m_iPos;
139 ReplaceSubString(m_strMsg,
_T(
"$POS$"), stream.str());
140 ReplaceSubString(m_strMsg,
_T(
"$TOK$"), m_strTok);
164 , m_strFormula(sExpr)
170 m_strMsg = m_ErrMsg[m_iErrc];
172 stream << (int)m_iPos;
173 ReplaceSubString(m_strMsg,
_T(
"$POS$"), stream.str());
174 ReplaceSubString(m_strMsg,
_T(
"$TOK$"), m_strTok);
191 m_strMsg = m_ErrMsg[m_iErrc];
193 stream << (int)m_iPos;
194 ReplaceSubString(m_strMsg,
_T(
"$POS$"), stream.str());
195 ReplaceSubString(m_strMsg,
_T(
"$TOK$"), m_strTok);
213 stream << (int)m_iPos;
214 ReplaceSubString(m_strMsg,
_T(
"$POS$"), stream.str());
215 ReplaceSubString(m_strMsg,
_T(
"$TOK$"), m_strTok);
221 :m_strMsg(a_Obj.m_strMsg)
222 , m_strFormula(a_Obj.m_strFormula)
223 , m_strTok(a_Obj.m_strTok)
224 , m_iPos(a_Obj.m_iPos)
225 , m_iErrc(a_Obj.m_iErrc)
237 m_strMsg = a_Obj.m_strMsg;
238 m_strFormula = a_Obj.m_strFormula;
239 m_strTok = a_Obj.m_strTok;
240 m_iPos = a_Obj.m_iPos;
241 m_iErrc = a_Obj.m_iErrc;
246 ParserError::~ParserError()
254 void ParserError::ReplaceSubString(
string_type& strSource,
259 string_type::size_type iPos(0), iNext(0);
263 iNext = strSource.find(strFind, iPos);
264 strResult.append(strSource, iPos, iNext - iPos);
266 if (iNext == string_type::npos)
269 strResult.append(strReplaceWith);
270 iPos = iNext + strFind.length();
273 strSource.swap(strResult);
278 void ParserError::Reset()
281 m_strFormula =
_T(
"");
291 m_strFormula = a_strFormula;
333 #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.
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.