NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
NumeRe::StringParser Class Reference

This class is the central string expression parser. It is designed as being a singleton with a persistent existence linked to the kernel class. More...

#include <stringparser.hpp>

Inheritance diagram for NumeRe::StringParser:
Collaboration diagram for NumeRe::StringParser:

Public Types

enum  StringParserRetVal { STRING_NUMERICAL = -1 , STRING_SUCCESS = 1 }
 

Public Member Functions

 StringParser (mu::Parser &parser, MemoryManager &data, Settings &option)
 String parser constructor. More...
 
virtual ~StringParser ()
 
StringParserRetVal evalAndFormat (std::string &sLine, std::string &sCache, bool bSilent=false, bool bCheckAssertions=false)
 This public member function evaluates the passed string expression and formats the results for the console. More...
 
virtual bool isStringExpression (const std::string &sExpression) override
 Returns true, if the passed expression is an expression containing strings, string variables or string vector variables. More...
 
- Public Member Functions inherited from NumeRe::StringFuncHandler
virtual ~StringFuncHandler ()
 
virtual bool isStringExpression (const std::string &sExpression)=0
 
- Public Member Functions inherited from NumeRe::StringVarFactory
bool containsStringVectorVars (const std::string &sLine)
 This member function determines, whether there are string vector variables in the passed command line. More...
 
std::string createTempStringVectorVar (const std::vector< std::string > &vStringVector)
 This member function is used to create a temporary string vector variable. More...
 
void removeTempStringVectorVars ()
 This member function removes all temporary string vector variables. More...
 
bool containsStringVars (const std::string &sLine) const
 This public member function determines, whether the passed string line contains string variables as part of the expression. More...
 
bool isStringVar (const std::string &sVarName) const
 Determine, whether the passed string is the identifier of a string variable. More...
 
void getStringValues (std::string &sLine)
 This public member function resolves all string variable occurences and replaces them with their value or the standard string function signature, if the string variable is connected to a method. More...
 
std::string getStringValue (const std::string &sVar) const
 Returns the value of the selected string variable. More...
 
void setStringValue (const std::string &sVar, const std::string &sValue)
 This public member function creates or updates a string variable and fills it with the passed value. More...
 
void removeStringVar (const std::string &sVar)
 This public member function removes the selected string variable from memory. More...
 
const std::map< std::string, std::string > & getStringVars () const
 

Private Member Functions

std::string getDataForString (std::string sLine, size_t n_pos)
 This member function returns the contents of the data objects and expands them as a list. More...
 
std::string parseStringsInIndices (std::string sIndexExpression)
 Parses the string expressions in index expressions so that they may used as numerical index expressions. More...
 
void replaceDataOccurence (std::string &sLine, const std::string &sOccurence)
 Replaces all occurences of the passed data access occurence in the passed string. More...
 
std::string numToString (const std::string &sLine)
 This member function implements the so-called value-to-string parser (called via #VAR in code). More...
 
int storeStringResults (StringResult &strRes, std::string sObject)
 This member function stores the processed and calculated string results in their desired targets. More...
 
std::string createStringOutput (StringResult &strRes, std::string &sLine, int parserFlags, bool bSilent)
 This member function converts the processed string parser results into an output string, which is formatted for the console. More...
 
std::string createTerminalOutput (StringResult &strRes, int parserFlags)
 This private member function creates the output specialized for the terminal. More...
 
std::vector< StringStackItemcreateStack (StringView sExpr) const
 This member function creates a stack from the passed expression, which may then be evaluated more easily. More...
 
StringVector evaluateStack (const std::vector< StringStackItem > &rpnStack, size_t from, size_t to)
 Evaluate the created RPN stack between the selected start and end points. More...
 
StringResult createAndEvaluateStack (StringView sExpr)
 Create a stack from the expression and evaluate it. More...
 
std::vector< bool > applyElementaryStringOperations (std::vector< std::string > &vFinal, bool &bReturningLogicals)
 This member function applies some elementary string operations like concatenation to the string expression. More...
 
void storeStringToDataObjects (StringResult &strRes, std::string &sObject, size_t &nCurrentComponent, size_t nStrings)
 This member function is a helper for StringParser::storeStringResults(). It will store the strings into the data tables. More...
 
void storeStringToStringObject (const std::vector< std::string > &vFinal, std::string &sObject, size_t &nCurrentComponent, size_t nStrings)
 This member function is a helper for StringParser::storeStringResults(). It will store the strings into the string object. More...
 
int decodeStringParams (std::string &sLine)
 This member function finds and decodes all passed string expression parameters and removes them from the expression. More...
 
bool isSimpleString (const std::string &sLine)
 This member function determines, whether the passed string is simple, i.e. it is a string literal without any operation. More...
 
bool isToken (const char *sToken, const std::string &sLine, size_t pos)
 Determines, whether the passed token can be found at the passed position. More...
 
std::string maskControlCharacters (std::string sString)
 This member function masks the line break and the tabulator control characters for storing the processed results. More...
 
virtual StringResult eval (std::string &sLine, std::string sCache, bool bParseNumericals=true) override
 This public member function provides the string parser core functionality and is the function, which is called recursively. More...
 

Private Attributes

std::map< std::string, int > m_mStringParams
 
mu::Parser_parser
 
MemoryManager_data
 
Settings_option
 

Additional Inherited Members

- Protected Member Functions inherited from NumeRe::StringLogicParser
bool detectStringLogicals (const std::string &sString)
 This member function is may detect logical expressions in the passed string expression. More...
 
std::string evalStringLogic (std::string sLine, bool &bReturningLogicals)
 This member function will evaluate logical string expressions in the passed command line. More...
 
void concatenateStrings (std::string &sExpr)
 This member function performs the actual string concatenation of the passed string expression. More...
 
- Protected Member Functions inherited from NumeRe::StringFuncHandler
std::string applySpecialStringFuncs (std::string sLine)
 This member function applies special string functions in the expression, which cannot be implemented as standard string functions. More...
 
std::string applyStringFuncs (std::string sLine)
 This member function searches for an occurence of a known string function in the passed command line and passes the control to StringFuncHandler::evalFunction() member function for evaluation. More...
 
void declareStringFuncs (const std::map< std::string, StringFuncHandle > &mStringFuncs)
 This member function is used to fill the internal map of declared string functions with the data of the passed one. More...
 
size_t findNextFunction (const std::string &sFunc, StringView sLine, size_t nStartPos, size_t &nEndPosition, bool searchForMethods=false)
 Finds the position of the next function occurence in the passed string including the position of the closing parenthesis. More...
 
StringView getFunctionArgumentList (const std::string &sFunc, StringView sLine, size_t nStartPosition, size_t nEndPosition)
 Returns the contents of the argument parentheses of the function starting at nStartPosition. More...
 
std::string printValue (const mu::value_type &value)
 Prints a value to a string respecting possible integer optimizations. More...
 
size_t getStringFuncMapSize () const
 
virtual StringResult eval (std::string &sLine, std::string sCache, bool bParseNumericals=true)=0
 
- Protected Member Functions inherited from NumeRe::StringVarFactory
StringVector evaluateStringVectors (std::string sLine)
 This member function evaluates the passed string vector and returns it's evaluated components in separate vector components. More...
 
StringVector expandStringVectorComponents (std::vector< StringVector > &vStringVector)
 This member function expands the internal multi-expressions in the veector into separate components by enlarging the dimension of the vector. More...
 
void removeStringVectorVars ()
 This member function removes all internal string vector variables. More...
 
std::string createStringVectorVar (const std::vector< std::string > &vStringVector)
 This member function is used to create a string vector variable. More...
 
bool isStringVectorVar (const std::string &sVarName) const
 Check, whether the passed string identifies a string vector variable. More...
 
const StringVectorgetStringVectorVar (const std::string &sVarName) const
 Return a reference to the identified string vector variable or throw if it does not exist. More...
 
void getStringValuesAsInternalVar (std::string &sLine, unsigned int nPos=0)
 This public member function resolves all string variable occurences and replaces them with an internal string vector variable or the standard string function signature, if the string variable is connected to a method. More...
 

Detailed Description

This class is the central string expression parser. It is designed as being a singleton with a persistent existence linked to the kernel class.

Definition at line 40 of file stringparser.hpp.

Member Enumeration Documentation

◆ StringParserRetVal

Enumerator
STRING_NUMERICAL 
STRING_SUCCESS 

Definition at line 68 of file stringparser.hpp.

Constructor & Destructor Documentation

◆ StringParser()

NumeRe::StringParser::StringParser ( mu::Parser parser,
MemoryManager data,
Settings option 
)

String parser constructor.

Parameters
parsermu::Parser&
dataDatafile&
optionSettings&

Definition at line 42 of file stringparser.cpp.

References NumeRe::StringFuncHandler::declareStringFuncs(), getStringFuncHandles(), KEEP_MASKED_CONTROL_CHARS, KEEP_MASKED_QUOTES, m_mStringParams, NO_QUOTES, and PEEK.

Here is the call graph for this function:

◆ ~StringParser()

virtual NumeRe::StringParser::~StringParser ( )
inlinevirtual

Definition at line 75 of file stringparser.hpp.

Member Function Documentation

◆ applyElementaryStringOperations()

std::vector< bool > NumeRe::StringParser::applyElementaryStringOperations ( std::vector< std::string > &  vFinal,
bool &  bReturningLogicals 
)
private

This member function applies some elementary string operations like concatenation to the string expression.

Parameters
vFinalstd::vector<std::string>&
bReturningLogicalsbool&
Returns
std::vector<bool>

Definition at line 1766 of file stringparser.cpp.

References NumeRe::StringLogicParser::concatenateStrings(), NumeRe::StringLogicParser::detectStringLogicals(), NumeRe::StringLogicParser::evalStringLogic(), and StripSpaces().

Referenced by replaceDataOccurence().

Here is the call graph for this function:

◆ createAndEvaluateStack()

StringResult NumeRe::StringParser::createAndEvaluateStack ( StringView  sExpr)
private

Create a stack from the expression and evaluate it.

Parameters
sExprStringView
Returns
StringResult

Definition at line 1735 of file stringparser.cpp.

References StringResult::bOnlyLogicals, createStack(), evaluateStack(), StringVector::is_string(), StringResult::vNoStringVal, and StringResult::vResult.

Referenced by eval().

Here is the call graph for this function:

◆ createStack()

std::vector< StringStackItem > NumeRe::StringParser::createStack ( StringView  sExpr) const
private

This member function creates a stack from the passed expression, which may then be evaluated more easily.

Parameters
sExprStringView
Returns
std::vector<StringStackItem>

Definition at line 1475 of file stringparser.cpp.

References NumeRe::convertToStack(), g_logger, getMatchingParenthesis(), StringViewBase::length(), StringViewBase::strip(), StringView::subview(), StringViewBase::trim_front(), and DetachedLogger::warning().

Referenced by createAndEvaluateStack().

Here is the call graph for this function:

◆ createStringOutput()

std::string NumeRe::StringParser::createStringOutput ( StringResult StrRes,
std::string &  sLine,
int  parserFlags,
bool  bSilent 
)
private

This member function converts the processed string parser results into an output string, which is formatted for the console.

Parameters
StrResStringResult&
sLinestd::string&
parserFlagsint
bSilentbool
Returns
std::string

Definition at line 967 of file stringparser.cpp.

References _parser, StringResult::bOnlyLogicals, NumeReKernel::bSupressAnswer, NumeRe::Cluster::clear(), mu::ParserBase::CreateTempVectorVar(), createTerminalOutput(), mu::ParserBase::Eval(), NumeReKernel::getAns(), NumeReKernel::getInstance(), NumeReKernel::getParser(), StringVector::getRef(), KEEP_MASKED_CONTROL_CHARS, KEEP_MASKED_QUOTES, NO_QUOTES, PEEK, NumeRe::Cluster::push_back(), mu::ParserBase::SetExpr(), toCmdString(), StringResult::vNoStringVal, StringResult::vNumericalValues, and StringResult::vResult.

Referenced by evalAndFormat().

Here is the call graph for this function:

◆ createTerminalOutput()

std::string NumeRe::StringParser::createTerminalOutput ( StringResult strRes,
int  parserFlags 
)
private

This private member function creates the output specialized for the terminal.

Parameters
strResStringResult&
parserFlagsint
Returns
std::string

Definition at line 1068 of file stringparser.cpp.

References _option, _parser, mu::ParserBase::Eval(), NumeReKernel::formatResultOutput(), Settings::getPrecision(), StringVector::getRef(), NO_QUOTES, PEEK, replaceAll(), mu::ParserBase::SetExpr(), toString(), StringResult::vNoStringVal, and StringResult::vResult.

Referenced by createStringOutput().

Here is the call graph for this function:

◆ decodeStringParams()

int NumeRe::StringParser::decodeStringParams ( std::string &  sLine)
private

This member function finds and decodes all passed string expression parameters and removes them from the expression.

Parameters
sLinestd::string&
Returns
int

Definition at line 1175 of file stringparser.cpp.

References findParameter(), m_mStringParams, and NO_FLAG.

Referenced by evalAndFormat().

Here is the call graph for this function:

◆ eval()

StringResult NumeRe::StringParser::eval ( std::string &  sLine,
std::string  sCache,
bool  bParseNumericals = true 
)
overrideprivatevirtual

This public member function provides the string parser core functionality and is the function, which is called recursively.

Parameters
sLinestd::string&
sCachestd::string
bParseNumericalsbool
Returns
StringResult

Implements NumeRe::StringFuncHandler.

Definition at line 1825 of file stringparser.cpp.

References _data, _parser, NumeRe::StringFuncHandler::applySpecialStringFuncs(), NumeRe::StringFuncHandler::applyStringFuncs(), StringResult::bOnlyLogicals, checkDelimiter(), NumeRe::StringVarFactory::containsStringVars(), NumeRe::StringVarFactory::containsStringVectorVars(), MemoryManager::containsTablesOrClusters(), createAndEvaluateStack(), NumeRe::StringVarFactory::createStringVectorVar(), mu::ParserBase::CreateTempVectorVar(), mu::ParserBase::Eval(), eval(), NumeRe::StringExpression::findAssignmentOperator(), NumeReKernel::getAns(), getDataForString(), NumeReKernel::getInstance(), getMatchingParenthesis(), getNextArgument(), StringVector::getRef(), NumeRe::StringVarFactory::getStringValuesAsInternalVar(), SyntaxError::invalid_position, isSimpleString(), isStringExpression(), NumeRe::StringExpression::nEqPos, numToString(), StringVector::push_generic(), NumeRe::StringExpression::sAssignee, NumeRe::Cluster::setDoubleArray(), mu::ParserBase::SetExpr(), NumeRe::StringExpression::sLine, NumeRe::StringExpression::split(), storeStringResults(), SyntaxError::STRING_ERROR, StripSpaces(), SyntaxError::UNMATCHED_PARENTHESIS, vAns, StringResult::vNoStringVal, StringResult::vNumericalValues, and StringResult::vResult.

Referenced by eval(), evalAndFormat(), numToString(), and parseStringsInIndices().

Here is the call graph for this function:

◆ evalAndFormat()

StringParser::StringParserRetVal NumeRe::StringParser::evalAndFormat ( std::string &  sLine,
std::string &  sCache,
bool  bSilent = false,
bool  bCheckAssertions = false 
)

This public member function evaluates the passed string expression and formats the results for the console.

Parameters
sLinestd::string&
sCachestd::string&
bSilentbool
bCheckAssertionsbool
Returns
StringParser::StringParserRetVal

Definition at line 2234 of file stringparser.cpp.

References _assertionHandler, StringResult::bOnlyLogicals, NumeReKernel::bSupressAnswer, Assertion::checkAssertion(), createStringOutput(), decodeStringParams(), eval(), PEEK, NumeReKernel::printPreFmt(), NumeRe::StringVarFactory::removeStringVectorVars(), STRING_NUMERICAL, and STRING_SUCCESS.

Referenced by FlowCtrl::calc(), cmd_pack(), cmd_print(), FlowCtrl::compile(), Plot::create2dDrawing(), Plot::create2dPlot(), Plot::create3dDrawing(), ProcedureVarFactory::createLocalClusters(), ProcedureVarFactory::createLocalInlineStrings(), ProcedureVarFactory::createLocalInlineVars(), ProcedureVarFactory::createLocalStrings(), ProcedureVarFactory::createLocalTables(), ProcedureVarFactory::createLocalVars(), Plot::createStd3dPlot(), Plot::createStdPlot(), dialogCommand(), FlowCtrl::evalHeader(), FlowCtrl::evalRangeBasedHeader(), evaluateExpression(), evaluateParameterValues(), ProcedureVarFactory::evaluateProcedureArguments(), NumeReKernel::evaluateStrings(), Procedure::execute(), extractFirstParameterStringValue(), Plot::filename(), CommandLineParser::getExprAsFileName(), CommandLineParser::getFileParameterValue(), getIndices(), NumeReKernel::handleToCmd(), moveOrCopyFiles(), parseArg(), CommandLineParser::parseExprAsNumericalValues(), CommandLineParser::parseExprAsString(), plotTableBySize(), Procedure::ProcCalc(), tableMethod_aliasof(), tableMethod_annotate(), tableMethod_categorize(), tableMethod_convert(), tableMethod_counteq(), tableMethod_findCols(), tableMethod_index(), tableMethod_rank(), windowCommand(), and writeToFile().

Here is the call graph for this function:

◆ evaluateStack()

StringVector NumeRe::StringParser::evaluateStack ( const std::vector< StringStackItem > &  rpnStack,
size_t  from,
size_t  to 
)
private

Evaluate the created RPN stack between the selected start and end points.

Parameters
rpnStackconst std::vector<StringStackItem>&
fromsize_t
tosize_t
Returns
StringVector

Definition at line 1593 of file stringparser.cpp.

References _parser, StringVector::and_f(), NumeRe::StringVarFactory::containsStringVectorVars(), mu::ParserBase::ContainsVectorVars(), StringVector::convert_literal(), evaluateStack(), NumeRe::StringVarFactory::evaluateStringVectors(), NumeRe::StringVarFactory::getStringVectorVar(), NumeRe::StringVarFactory::isStringVectorVar(), StringVector::or_f(), toString(), and StringVector::xor_f().

Referenced by createAndEvaluateStack(), and evaluateStack().

Here is the call graph for this function:

◆ getDataForString()

std::string NumeRe::StringParser::getDataForString ( std::string  sLine,
size_t  n_pos 
)
private

◆ isSimpleString()

bool NumeRe::StringParser::isSimpleString ( const std::string &  sLine)
private

This member function determines, whether the passed string is simple, i.e. it is a string literal without any operation.

Parameters
sLineconst std::string&
Returns
bool

This function is called mainly first in the recursion cycle to avoid not necessary calculations, because already evaluated string literals mainly do not need any processing.

Definition at line 1230 of file stringparser.cpp.

Referenced by eval().

◆ isStringExpression()

bool NumeRe::StringParser::isStringExpression ( const std::string &  sExpression)
overridevirtual

◆ isToken()

bool NumeRe::StringParser::isToken ( const char *  sToken,
const std::string &  sLine,
size_t  pos 
)
private

Determines, whether the passed token can be found at the passed position.

Parameters
sTokenconst char*
sLineconst std::string&
possize_t
Returns
bool

Definition at line 1263 of file stringparser.cpp.

References isDelimiter().

Here is the call graph for this function:

◆ maskControlCharacters()

std::string NumeRe::StringParser::maskControlCharacters ( std::string  sString)
private

This member function masks the line break and the tabulator control characters for storing the processed results.

Parameters
sStringstd::string
Returns
std::string

Definition at line 1286 of file stringparser.cpp.

References replaceAll().

Here is the call graph for this function:

◆ numToString()

std::string NumeRe::StringParser::numToString ( const std::string &  sLine)
private

◆ parseStringsInIndices()

std::string NumeRe::StringParser::parseStringsInIndices ( std::string  sIndexExpression)
private

Parses the string expressions in index expressions so that they may used as numerical index expressions.

Parameters
sIndexExpressionstd::string
Returns
std::string

Definition at line 170 of file stringparser.cpp.

References _parser, StringResult::bOnlyLogicals, mu::ParserBase::CreateTempVectorVar(), eval(), getNextArgument(), SyntaxError::invalid_position, isStringExpression(), SyntaxError::STRING_ERROR, StrToDb(), and StringResult::vResult.

Referenced by getDataForString(), and replaceDataOccurence().

Here is the call graph for this function:

◆ replaceDataOccurence()

void NumeRe::StringParser::replaceDataOccurence ( std::string &  sLine,
const std::string &  sOccurence 
)
private

Replaces all occurences of the passed data access occurence in the passed string.

Parameters
sLinestd::string&
sOccurenceconst std::string&
Returns
void

Definition at line 245 of file stringparser.cpp.

References _data, _option, _parser, applyElementaryStringOperations(), NumeRe::StringVarFactory::containsStringVectorVars(), NumeRe::StringVarFactory::evaluateStringVectors(), NumeRe::StringFuncHandler::findNextFunction(), getDataElements(), NumeRe::StringFuncHandler::getFunctionArgumentList(), INSERT_STRINGS, parser_CheckMultArgFunc(), parseStringsInIndices(), REPLACE_NAN, replaceDataEntities(), and StripSpaces().

Referenced by getDataForString().

Here is the call graph for this function:

◆ storeStringResults()

int NumeRe::StringParser::storeStringResults ( StringResult strRes,
std::string  __sObject 
)
private

This member function stores the processed and calculated string results in their desired targets.

Parameters
strResStringResult&
__sObjectstd::string
Returns
int

Definition at line 805 of file stringparser.cpp.

References _data, _option, _parser, NumeRe::StringVarFactory::containsStringVars(), MemoryManager::containsTablesOrClusters(), convertVectorToExpression(), mu::ParserBase::Eval(), NumeReKernel::getAns(), NumeReKernel::getInstance(), getNextArgument(), getPointerToVariable(), Settings::getPrecision(), NumeRe::Cluster::setDoubleArray(), mu::ParserBase::SetExpr(), NumeRe::StringVarFactory::setStringValue(), storeStringToDataObjects(), storeStringToStringObject(), StripSpaces(), toString(), vAns, StringResult::vNoStringVal, StringResult::vNumericalValues, and StringResult::vResult.

Referenced by eval().

Here is the call graph for this function:

◆ storeStringToDataObjects()

void NumeRe::StringParser::storeStringToDataObjects ( StringResult strRes,
std::string &  sObject,
size_t &  nCurrentComponent,
size_t  nStrings 
)
private

◆ storeStringToStringObject()

void NumeRe::StringParser::storeStringToStringObject ( const std::vector< std::string > &  vFinal,
std::string &  sObject,
size_t &  nCurrentComponent,
size_t  nStrings 
)
private

This member function is a helper for StringParser::storeStringResults(). It will store the strings into the string object.

Parameters
vFinalconst std::vector<std::string>&
sObjectstd::string&
nCurrentComponentsize_t&
nStringssize_t
Returns
void

Definition at line 774 of file stringparser.cpp.

References _data, _option, _parser, Indices::col, VectorIndex::front(), getIndices(), VectorIndex::isOpenEnd(), VectorIndex::isValid(), removeQuotationMarks(), Indices::row, VectorIndex::setRange(), VectorIndex::size(), and StringMemory::writeString().

Referenced by storeStringResults().

Here is the call graph for this function:

Member Data Documentation

◆ _data

◆ _option

Settings& NumeRe::StringParser::_option
private

◆ _parser

◆ m_mStringParams

std::map<std::string, int> NumeRe::StringParser::m_mStringParams
private

Definition at line 43 of file stringparser.hpp.

Referenced by decodeStringParams(), and StringParser().


The documentation for this class was generated from the following files: