Token reader for the ParserBase class. More...
#include <qmuparsertokenreader.h>
Public Member Functions | |
QmuParserTokenReader (QmuParserBase *a_pParent) | |
Constructor. More... | |
QmuParserTokenReader * | Clone (QmuParserBase *a_pParent) const |
Create instance of a QParserTokenReader identical with this and return its pointer. More... | |
void | AddValIdent (identfun_type a_pCallback) |
void | SetVarCreator (facfun_type a_pFactory, void *pUserData) |
void | SetFormula (const QString &a_strFormula) |
Initialize the token Reader. More... | |
void | SetArgSep (char_type cArgSep) |
int | GetPos () const |
Return the current position of the token reader in the formula string. More... | |
const QString & | GetExpr () const |
Return a reference to the formula. More... | |
varmap_type & | GetUsedVar () |
Return a map containing the used variables only. More... | |
QChar | GetArgSep () const |
void | IgnoreUndefVar (bool bIgnore) |
Set Flag that contronls behaviour in case of undefined variables beeing found. More... | |
void | ReInit () |
Reset the token reader to the start of the formula. More... | |
token_type | ReadNextToken (const QLocale &locale, const QChar &decimal, const QChar &thousand) |
Read the next token from the string. More... | |
Private Types | |
enum | ESynCodes { noBO = 1 << 0 , noBC = 1 << 1 , noVAL = 1 << 2 , noVAR = 1 << 3 , noARG_SEP = 1 << 4 , noFUN = 1 << 5 , noOPT = 1 << 6 , noPOSTOP = 1 << 7 , noINFIXOP = 1 << 8 , noEND = 1 << 9 , noSTR = 1 << 10 , noASSIGN = 1 << 11 , noIF = 1 << 12 , noELSE = 1 << 13 , sfSTART_OF_LINE = noOPT | noBC | noPOSTOP | noASSIGN | noIF | noELSE | noARG_SEP , noANY = ~0 } |
Syntax codes. More... | |
typedef QmuParserToken< qreal, QString > | token_type |
Private Member Functions | |
QmuParserTokenReader (const QmuParserTokenReader &a_Reader) | |
Copy constructor. More... | |
QmuParserTokenReader & | operator= (const QmuParserTokenReader &a_Reader) |
Assignement operator. More... | |
void | Assign (const QmuParserTokenReader &a_Reader) |
Assign state of a token reader to this token reader. More... | |
void | SetParent (QmuParserBase *a_pParent) |
int | ExtractToken (const QString &a_szCharSet, QString &a_strTok, int a_iPos) const |
Extract all characters that belong to a certain charset. More... | |
int | ExtractOperatorToken (QString &a_sTok, int a_iPos) const |
Check Expression for the presence of a binary operator token. More... | |
bool | IsBuiltIn (token_type &a_Tok) |
Check if a built in operator or other token can be found. More... | |
bool | IsArgSep (token_type &a_Tok) |
bool | IsEOF (token_type &a_Tok) |
Check for End of Formula. More... | |
bool | IsInfixOpTok (token_type &a_Tok) |
Check if a string position contains a unary infix operator. More... | |
bool | IsFunTok (token_type &a_Tok) |
Check whether the token at a given position is a function token. More... | |
bool | IsPostOpTok (token_type &a_Tok) |
Check if a string position contains a unary post value operator. More... | |
bool | IsOprt (token_type &a_Tok) |
Check if a string position contains a binary operator. More... | |
bool | IsValTok (token_type &a_Tok, const QLocale &locale, const QChar &decimal, const QChar &thousand) |
Check whether the token at a given position is a value token. More... | |
bool | IsVarTok (token_type &a_Tok) |
Check wheter a token at a given position is a variable token. More... | |
bool | IsStrVarTok (token_type &a_Tok) |
bool | IsUndefVarTok (token_type &a_Tok) |
Check wheter a token at a given position is an undefined variable. More... | |
bool | IsString (token_type &a_Tok) |
Check wheter a token at a given position is a string. More... | |
void Q_NORETURN | Error (EErrorCodes a_iErrc, int a_iPos=-1, const QString &a_sTok=QString()) const |
Create an error containing the parse error position. More... | |
token_type & | SaveBeforeReturn (const token_type &tok) |
Private Attributes | |
QmuParserBase * | m_pParser |
QString | m_strFormula |
int | m_iPos |
int | m_iSynFlags |
bool | m_bIgnoreUndefVar |
const funmap_type * | m_pFunDef |
const funmap_type * | m_pPostOprtDef |
const funmap_type * | m_pInfixOprtDef |
const funmap_type * | m_pOprtDef |
const valmap_type * | m_pConstDef |
const strmap_type * | m_pStrVarDef |
varmap_type * | m_pVarDef |
The only non const pointer to parser internals. More... | |
facfun_type | m_pFactory |
void * | m_pFactoryData |
std::list< identfun_type > | m_vIdentFun |
Value token identification function. More... | |
varmap_type | m_UsedVar |
qreal | m_fZero |
Dummy value of zero, referenced by undefined variables. More... | |
int | m_iBrackets |
Keep count open brackets. More... | |
token_type | m_lastTok |
QChar | m_cArgSep |
The character used for separating function arguments. More... | |
Token reader for the ParserBase class.
Definition at line 51 of file qmuparsertokenreader.h.
|
private |
Definition at line 54 of file qmuparsertokenreader.h.
|
private |
Syntax codes.
The syntax codes control the syntax check done during the first time parsing of the expression string. They are flags that indicate which tokens are allowed next if certain tokens are identified.
Definition at line 79 of file qmuparsertokenreader.h.
|
explicit |
Constructor.
Create a Token reader and bind it to a parser object.
a_pParent | Parent parser object of the token reader. |
Definition at line 128 of file qmuparsertokenreader.cpp.
References m_pParser, and SetParent().
|
private |
Copy constructor.
nothrow |
Definition at line 55 of file qmuparsertokenreader.cpp.
void qmu::QmuParserTokenReader::AddValIdent | ( | identfun_type | a_pCallback | ) |
Definition at line 163 of file qmuparsertokenreader.cpp.
References m_vIdentFun.
|
private |
Assign state of a token reader to this token reader.
a_Reader | Object from which the state should be copied. |
nothrow |
Definition at line 92 of file qmuparsertokenreader.cpp.
References m_bIgnoreUndefVar, m_cArgSep, m_fZero, m_iBrackets, m_iPos, m_iSynFlags, m_lastTok, m_pConstDef, m_pFactory, m_pFactoryData, m_pFunDef, m_pInfixOprtDef, m_pOprtDef, m_pParser, m_pPostOprtDef, m_pStrVarDef, m_pVarDef, m_strFormula, m_UsedVar, and m_vIdentFun.
Referenced by operator=().
QmuParserTokenReader * qmu::QmuParserTokenReader::Clone | ( | QmuParserBase * | a_pParent | ) | const |
Create instance of a QParserTokenReader identical with this and return its pointer.
This is a factory method the calling function must take care of the object destruction.
nothrow |
Definition at line 148 of file qmuparsertokenreader.cpp.
|
private |
Create an error containing the parse error position.
This function will create an Parser Exception object containing the error text and its position.
a_iErrc | [in] The error code of type EErrorCodes. |
a_iPos | [in] The position where the error was detected. |
a_sTok | [in] The token string representation associated with the error. |
ParserException | always throws thats the only purpose of this function. |
Definition at line 1021 of file qmuparsertokenreader.cpp.
References qmu::QmuParserBase::Error(), and m_pParser.
Referenced by IsArgSep(), IsBuiltIn(), IsEOF(), IsFunTok(), IsInfixOpTok(), IsString(), IsStrVarTok(), IsUndefVarTok(), IsValTok(), IsVarTok(), and ReadNextToken().
|
private |
Check Expression for the presence of a binary operator token.
Userdefined binary operator "++" gives inconsistent parsing result for the equations "a++b" and "a ++ b" if alphabetic characters are allowed in operator tokens. To avoid this this function checks specifically for operator tokens.
Definition at line 356 of file qmuparsertokenreader.cpp.
References ExtractToken(), m_pParser, m_strFormula, QMUP_CHARS, and qmu::QmuParserBase::ValidOprtChars().
Referenced by IsOprt().
|
private |
Extract all characters that belong to a certain charset.
a_szCharSet | [in] Const char array of the characters allowed in the token. |
a_sTok | [out] The string that consists entirely of characters listed in a_szCharSet. |
a_iPos | [in] Position in the string from where to start reading. |
nothrow |
Definition at line 326 of file qmuparsertokenreader.cpp.
Referenced by ExtractOperatorToken(), IsFunTok(), IsInfixOpTok(), IsPostOpTok(), IsStrVarTok(), IsUndefVarTok(), IsValTok(), IsVarTok(), and ReadNextToken().
|
inline |
Definition at line 200 of file qmuparsertokenreader.h.
References m_cArgSep.
|
inline |
Return a reference to the formula.
nothrow |
Definition at line 165 of file qmuparsertokenreader.h.
References m_strFormula.
|
inline |
Return the current position of the token reader in the formula string.
nothrow |
Definition at line 153 of file qmuparsertokenreader.h.
References m_iPos.
|
inline |
Return a map containing the used variables only.
Definition at line 174 of file qmuparsertokenreader.h.
References m_UsedVar.
|
inline |
Set Flag that contronls behaviour in case of undefined variables beeing found.
If true, the parser does not throw an exception if an undefined variable is found. Otherwise it does. This variable is used internally only! It supresses a "undefined variable" exception in GetUsedVar(). Those function should return a complete list of variables including those the are not defined by the time of it's call.
Definition at line 188 of file qmuparsertokenreader.h.
References m_bIgnoreUndefVar.
|
private |
Definition at line 497 of file qmuparsertokenreader.cpp.
References qmu::cmARG_SEP, qmu::ecUNEXPECTED_ARG_SEP, Error(), m_cArgSep, m_iPos, m_iSynFlags, m_strFormula, noARG_SEP, noASSIGN, noBC, noEND, noOPT, noPOSTOP, and qmu::QmuParserToken< TBase, TString >::Set().
Referenced by ReadNextToken().
|
private |
Check if a built in operator or other token can be found.
a_Tok | [out] Operator token if one is found. This can either be a binary operator or an infix operator token. |
Definition at line 390 of file qmuparsertokenreader.cpp.
References qmu::cmASSIGN, qmu::cmBC, qmu::cmBO, qmu::cmELSE, qmu::cmFUNC, qmu::cmIF, qmu::cmLE, qmu::ecINTERNAL_ERROR, qmu::ecUNEXPECTED_CONDITIONAL, qmu::ecUNEXPECTED_OPERATOR, qmu::ecUNEXPECTED_PARENS, Error(), qmu::QmuParserToken< TBase, TString >::GetCode(), qmu::QmuParserBase::GetOprtDef(), qmu::QmuParserBase::HasBuiltInOprt(), IsInfixOpTok(), m_iBrackets, m_iPos, m_iSynFlags, m_lastTok, m_pParser, m_strFormula, noARG_SEP, noASSIGN, noBC, noBO, noELSE, noEND, noFUN, noIF, noINFIXOP, noOPT, noPOSTOP, noSTR, noVAL, noVAR, and qmu::QmuParserToken< TBase, TString >::Set().
Referenced by ReadNextToken().
|
private |
Check for End of Formula.
a_Tok | [out] If an eof is found the corresponding token will be stored there. |
Definition at line 528 of file qmuparsertokenreader.cpp.
References qmu::cmEND, qmu::ecMISSING_PARENS, qmu::ecUNEXPECTED_EOF, Error(), qmu::QmuParserError::GetCode(), qmu::QmuParserError::GetMsg(), m_iBrackets, m_iPos, m_iSynFlags, m_strFormula, noEND, and qmu::QmuParserToken< TBase, TString >::Set().
Referenced by ReadNextToken().
|
private |
Check whether the token at a given position is a function token.
a_Tok | [out] If a value token is found it will be placed here. |
ParserException | if Syntaxflags do not allow a function at a_iPos |
Definition at line 603 of file qmuparsertokenreader.cpp.
References qmu::ecUNEXPECTED_FUN, Error(), ExtractToken(), qmu::QmuParserToken< TBase, TString >::GetAsString(), m_iPos, m_iSynFlags, m_pFunDef, m_pParser, m_strFormula, noANY, noBO, noFUN, qmu::QmuParserToken< TBase, TString >::Set(), and qmu::QmuParserBase::ValidNameChars().
Referenced by ReadNextToken().
|
private |
Check if a string position contains a unary infix operator.
Definition at line 564 of file qmuparsertokenreader.cpp.
References qmu::ecUNEXPECTED_OPERATOR, Error(), ExtractToken(), qmu::QmuParserToken< TBase, TString >::GetAsString(), m_iPos, m_iSynFlags, m_pInfixOprtDef, m_pParser, noASSIGN, noBC, noINFIXOP, noOPT, noPOSTOP, noSTR, qmu::QmuParserToken< TBase, TString >::Set(), and qmu::QmuParserBase::ValidInfixOprtChars().
Referenced by IsBuiltIn(), IsOprt(), and ReadNextToken().
|
private |
Check if a string position contains a binary operator.
a_Tok | [out] Operator token if one is found. This can either be a binary operator or an infix operator token. |
Definition at line 642 of file qmuparsertokenreader.cpp.
References ExtractOperatorToken(), qmu::QmuParserBase::GetOprtDef(), qmu::QmuParserBase::HasBuiltInOprt(), IsInfixOpTok(), m_iPos, m_iSynFlags, m_pOprtDef, m_pParser, m_strFormula, noARG_SEP, noASSIGN, noBC, noEND, noOPT, noPOSTOP, and qmu::QmuParserToken< TBase, TString >::Set().
Referenced by ReadNextToken().
|
private |
Check if a string position contains a unary post value operator.
Definition at line 711 of file qmuparsertokenreader.cpp.
References ExtractToken(), m_iPos, m_iSynFlags, m_pParser, m_pPostOprtDef, noASSIGN, noBO, noFUN, noPOSTOP, noSTR, noVAL, noVAR, qmu::QmuParserToken< TBase, TString >::Set(), and qmu::QmuParserBase::ValidOprtChars().
Referenced by ReadNextToken().
|
private |
Check wheter a token at a given position is a string.
a_Tok | [out] If a variable token has been found it will be placed here. |
Definition at line 968 of file qmuparsertokenreader.cpp.
References qmu::ecUNEXPECTED_STR, qmu::ecUNTERMINATED_STRING, Error(), m_iPos, m_iSynFlags, m_pParser, m_strFormula, qmu::QmuParserBase::m_vStringBuf, noANY, noARG_SEP, noBC, noEND, noOPT, noSTR, and qmu::QmuParserToken< TBase, TString >::SetString().
Referenced by ReadNextToken().
|
private |
Definition at line 868 of file qmuparsertokenreader.cpp.
References qmu::ecINTERNAL_ERROR, qmu::ecUNEXPECTED_VAR, Error(), ExtractToken(), m_iPos, m_iSynFlags, m_pParser, m_pStrVarDef, qmu::QmuParserBase::m_vStringVarBuf, noANY, noARG_SEP, noBC, noEND, noOPT, noSTR, qmu::QmuParserToken< TBase, TString >::SetString(), and qmu::QmuParserBase::ValidNameChars().
Referenced by ReadNextToken().
|
private |
Check wheter a token at a given position is an undefined variable.
a_Tok | [out] If a variable tom_pParser->m_vStringBufken has been found it will be placed here. |
nothrow |
Definition at line 914 of file qmuparsertokenreader.cpp.
References qmu::ecUNEXPECTED_VAR, Error(), ExtractToken(), qmu::QmuParserToken< TBase, TString >::GetAsString(), m_fZero, m_iPos, m_iSynFlags, m_pFactory, m_pFactoryData, m_pParser, m_UsedVar, noBO, noFUN, noINFIXOP, noPOSTOP, noSTR, noVAL, noVAR, qmu::QmuParserToken< TBase, TString >::SetVar(), and qmu::QmuParserBase::ValidNameChars().
Referenced by ReadNextToken().
|
private |
Check whether the token at a given position is a value token.
Value tokens are either values or constants.
a_Tok | [out] If a value token is found it will be placed here. |
Definition at line 768 of file qmuparsertokenreader.cpp.
References qmu::ecUNEXPECTED_VAL, Error(), ExtractToken(), m_iPos, m_iSynFlags, m_pConstDef, m_pParser, m_strFormula, m_vIdentFun, noASSIGN, noBO, noFUN, noINFIXOP, noSTR, noVAL, noVAR, qmu::QmuParserToken< TBase, TString >::SetVal(), and qmu::QmuParserBase::ValidNameChars().
Referenced by ReadNextToken().
|
private |
Check wheter a token at a given position is a variable token.
a_Tok | [out] If a variable token has been found it will be placed here. |
Definition at line 829 of file qmuparsertokenreader.cpp.
References qmu::ecUNEXPECTED_VAR, Error(), ExtractToken(), m_iPos, m_iSynFlags, m_pParser, m_pVarDef, m_strFormula, m_UsedVar, noBO, noFUN, noINFIXOP, noSTR, noVAL, noVAR, qmu::QmuParserBase::OnDetectVar(), qmu::QmuParserToken< TBase, TString >::SetVar(), and qmu::QmuParserBase::ValidNameChars().
Referenced by ReadNextToken().
|
private |
Assignement operator.
Self assignement will be suppressed otherwise Assign is called.
a_Reader | Object to copy to this token reader. |
nothrow |
Definition at line 75 of file qmuparsertokenreader.cpp.
References Assign().
QmuParserTokenReader::token_type qmu::QmuParserTokenReader::ReadNextToken | ( | const QLocale & | locale, |
const QChar & | decimal, | ||
const QChar & | thousand | ||
) |
Read the next token from the string.
Definition at line 216 of file qmuparsertokenreader.cpp.
References qmu::ecUNASSIGNABLE_TOKEN, Error(), ExtractToken(), IsArgSep(), IsBuiltIn(), IsEOF(), IsFunTok(), IsInfixOpTok(), IsOprt(), IsPostOpTok(), IsString(), IsStrVarTok(), IsUndefVarTok(), IsValTok(), IsVarTok(), m_bIgnoreUndefVar, m_iPos, m_pFactory, m_pParser, m_strFormula, SaveBeforeReturn(), and qmu::QmuParserBase::ValidNameChars().
void qmu::QmuParserTokenReader::ReInit | ( | ) |
Reset the token reader to the start of the formula.
The syntax flags will be reset to a value appropriate for the start of a formula.
nothrow |
Definition at line 203 of file qmuparsertokenreader.cpp.
References m_iBrackets, m_iPos, m_iSynFlags, m_lastTok, m_UsedVar, and sfSTART_OF_LINE.
Referenced by SetFormula().
|
private |
Definition at line 156 of file qmuparsertokenreader.cpp.
References m_lastTok.
Referenced by ReadNextToken().
|
inline |
Definition at line 194 of file qmuparsertokenreader.h.
References m_cArgSep.
void qmu::QmuParserTokenReader::SetFormula | ( | const QString & | a_strFormula | ) |
Initialize the token Reader.
Sets the formula position index to zero and set Syntax flags to default for initial formula parsing.
Definition at line 188 of file qmuparsertokenreader.cpp.
References m_strFormula, and ReInit().
|
private |
Definition at line 302 of file qmuparsertokenreader.cpp.
References qmu::QmuParserBase::m_ConstDef, qmu::QmuParserBase::m_FunDef, qmu::QmuParserBase::m_InfixOprtDef, qmu::QmuParserBase::m_OprtDef, m_pConstDef, m_pFunDef, m_pInfixOprtDef, m_pOprtDef, qmu::QmuParserBase::m_PostOprtDef, m_pParser, m_pPostOprtDef, m_pStrVarDef, m_pVarDef, qmu::QmuParserBase::m_StrVarDef, and qmu::QmuParserBase::m_VarDef.
Referenced by QmuParserTokenReader().
void qmu::QmuParserTokenReader::SetVarCreator | ( | facfun_type | a_pFactory, |
void * | pUserData | ||
) |
Definition at line 175 of file qmuparsertokenreader.cpp.
References m_pFactory, and m_pFactoryData.
|
private |
Definition at line 127 of file qmuparsertokenreader.h.
Referenced by Assign(), IgnoreUndefVar(), and ReadNextToken().
|
private |
The character used for separating function arguments.
Definition at line 143 of file qmuparsertokenreader.h.
Referenced by Assign(), GetArgSep(), IsArgSep(), and SetArgSep().
|
private |
Dummy value of zero, referenced by undefined variables.
Definition at line 140 of file qmuparsertokenreader.h.
Referenced by Assign(), and IsUndefVarTok().
|
private |
Keep count open brackets.
Definition at line 141 of file qmuparsertokenreader.h.
Referenced by Assign(), IsBuiltIn(), IsEOF(), and ReInit().
|
private |
Definition at line 125 of file qmuparsertokenreader.h.
Referenced by Assign(), GetPos(), IsArgSep(), IsBuiltIn(), IsEOF(), IsFunTok(), IsInfixOpTok(), IsOprt(), IsPostOpTok(), IsString(), IsStrVarTok(), IsUndefVarTok(), IsValTok(), IsVarTok(), ReadNextToken(), and ReInit().
|
private |
Definition at line 126 of file qmuparsertokenreader.h.
Referenced by Assign(), IsArgSep(), IsBuiltIn(), IsEOF(), IsFunTok(), IsInfixOpTok(), IsOprt(), IsPostOpTok(), IsString(), IsStrVarTok(), IsUndefVarTok(), IsValTok(), IsVarTok(), and ReInit().
|
private |
Definition at line 142 of file qmuparsertokenreader.h.
Referenced by Assign(), IsBuiltIn(), ReInit(), and SaveBeforeReturn().
|
private |
Definition at line 133 of file qmuparsertokenreader.h.
Referenced by Assign(), IsValTok(), and SetParent().
|
private |
Definition at line 136 of file qmuparsertokenreader.h.
Referenced by Assign(), IsUndefVarTok(), ReadNextToken(), and SetVarCreator().
|
private |
Definition at line 137 of file qmuparsertokenreader.h.
Referenced by Assign(), IsUndefVarTok(), and SetVarCreator().
|
private |
Definition at line 129 of file qmuparsertokenreader.h.
Referenced by Assign(), IsFunTok(), and SetParent().
|
private |
Definition at line 131 of file qmuparsertokenreader.h.
Referenced by Assign(), IsInfixOpTok(), and SetParent().
|
private |
Definition at line 132 of file qmuparsertokenreader.h.
Referenced by Assign(), IsOprt(), and SetParent().
|
private |
Definition at line 123 of file qmuparsertokenreader.h.
Referenced by Assign(), Error(), ExtractOperatorToken(), IsBuiltIn(), IsFunTok(), IsInfixOpTok(), IsOprt(), IsPostOpTok(), IsString(), IsStrVarTok(), IsUndefVarTok(), IsValTok(), IsVarTok(), QmuParserTokenReader(), ReadNextToken(), and SetParent().
|
private |
Definition at line 130 of file qmuparsertokenreader.h.
Referenced by Assign(), IsPostOpTok(), and SetParent().
|
private |
Definition at line 134 of file qmuparsertokenreader.h.
Referenced by Assign(), IsStrVarTok(), and SetParent().
|
private |
The only non const pointer to parser internals.
Definition at line 135 of file qmuparsertokenreader.h.
Referenced by Assign(), IsVarTok(), and SetParent().
|
private |
Definition at line 124 of file qmuparsertokenreader.h.
Referenced by Assign(), ExtractOperatorToken(), GetExpr(), IsArgSep(), IsBuiltIn(), IsEOF(), IsFunTok(), IsOprt(), IsString(), IsValTok(), IsVarTok(), ReadNextToken(), and SetFormula().
|
private |
Definition at line 139 of file qmuparsertokenreader.h.
Referenced by Assign(), GetUsedVar(), IsUndefVarTok(), IsVarTok(), and ReInit().
|
private |
Value token identification function.
Definition at line 138 of file qmuparsertokenreader.h.
Referenced by AddValIdent(), Assign(), and IsValTok().