File MIES_SweepFormula_Parser.ipf¶
SFP Sweep formula parser
Functions
-
std::tuple<variable, variable> SFP_ParseFormulaToJSON(string formula)¶
-
static string SFP_StringifyState(variable state)¶
-
static string SFP_StringifyAction(variable action)¶
-
static variable SFP_LogParserState(string token, variable state, variable lastState, variable lastCalculation, variable action, variable level)¶
-
variable SFP_LogParserErrorState(string msg)¶
-
static variable SFP_LogParserStateInit(string formula)¶
-
variable SFP_SaveParserStateLog()¶
-
std::tuple<variable, WaveText> SFP_FormulaParser(string formula, variable bufOffset, variable *createdArray = defaultValue, variable indentLevel = defaultValue)¶
serialize a string formula into JSON
- Parameters:
formula – string formula
bufOffset – Parser internal character offset into the initial formula string. When SFP_FormulaParser is called from a outside the parser this should be zero.
createdArray – [optional, default 0] set on recursive calls, returns boolean if parser created a JSON array
indentLevel – [internal use only] recursive call level, used for debug output
- Returns:
a JSONid representation
-
static variable SFP_ParserHandleRemainingBuffer(SF_ParserData *pad, string formula, string buffer)¶
-
static std::tuple<SF_ParserData, variable, variable, variable> SFP_ParserModifyJSON(variable action, variable lastAction, variable state, string buffer, string token, variable indentLevel)¶
-
static std::tuple<variable, variable, variable> SFP_ParserGetActionFromState(variable jsonId, variable state, variable lastCalculation, variable bufferIsEmpty)¶
-
static std::tuple<variable, variable, variable> SFP_ParserGetStateFromToken(string token, variable jsonId, string buffer)¶
-
static std::tuple<string, variable, SF_ParserData> SFP_ParserEvaluatePossibleSign()¶
If buffer has a sign then it is removed from buffer. If the sign was a minus then a negation is prefixed in the json.
-
static std::tuple<SF_ParserData> SFP_ParserAddJSON(string formula, variable bufOffset, variable indentLevel)¶
Parses a formula to json and puts it at jsonPath into the current json.
-
static std::tuple<SF_ParserData> SFP_ParserInsertNegation()¶
-
static std::tuple<SF_ParserData> SFP_ParserAdaptSubPath(string subPath)¶
-
static std::tuple<SF_ParserData> SFP_FPPutInArrayAtPath(string jsonPathArray)¶
Create a new empty array object, add mainId into it at path and return created json, release subId.
-
static std::tuple<SF_ParserData> SFP_FPAddArray(variable subId, variable createArray, variable firstElementOffset = defaultValue)¶
Adds subId to mainId, if necessary puts subId into an array, release subId.
-
static string SF_GetAddJSONPath(variable jsonId, string jsonPath)¶
-
static variable SFP_AddSourceLocation(SF_ParserData *pad, variable formulaOffset, variable arrayOnly = defaultValue)¶
Adds the current jsonPath with formulaOffset as source location to the source location wave.
The following modifications are made to the path string:
the path is always prefixed with a “/” if it is not empty and has no “/” at the start
if the current pad.jsonPath points to an array then the last existing array index is added to the path, e.g. “/array” -> “/array/3”
if arrayOnly flag is set and pad.jsonPath points to an array then only the path to the array without index is added
-
static variable SFP_AdaptSourceSubPaths(SF_ParserData *pad, WaveText srcLocsSub, variable addArrayIndex)¶
When the parsing returns from a recursion where a deeper level of the formula was parsed it also returns the gathered source locations from this deeper level. These source locations need to be prefixed by the path where the JSON returned by the recursion is inserted for the current level. This function applies that prefixing. The caller usually concatenates the wave with the modified paths to the wave with the paths from the current recursion level. The prefix is the current pad.jsonPath with the following modifications:
the prefix is always prefixed with a “/” if it is not empty and has no “/” at the start
if addArrayIndex flag is set and the current pad.jsonPath is an array then the last existing array index is added to the prefix e.g. “/currentPath” -> “/currentPath/3” All source location paths from the deeper recursion are then prefixed with this path
-
static variable SFP_ConvertSourceLocWaveToJSON(WaveText srcLocs, string formula)¶
After parsing a SF formula the gathered source locations are put into a JSON by this function. The JSON has a simple format and is used a key/value store:
key : value
“” : formula (string) “<path1>” : character offset (numeric) “<path2>” : character offset (numeric) … : …
The JSON has to be released by the caller of SFP_ParseFormulaToJSON after its information is no longer needed or in the case of a SFH_ASSERT by the assertion handler (currently in SFH_GetAssertLocationMessage)
-
static variable SFP_AddArray(SF_ParserData *pad, WaveText srcLocsSub, variable subId, variable createArray)¶
-
static variable SFP_AdaptSourceSubPathsAtJSONPath(SF_ParserData *pad, WaveText srcLocsSub, string jsonPath)¶
Variables
-
static const double SF_STATE_UNINITIALIZED = -1¶
-
static const double SF_STATE_COLLECT = 1¶
-
static const double SF_STATE_ADDITION = 2¶
-
static const double SF_STATE_SUBTRACTION = 3¶
-
static const double SF_STATE_MULTIPLICATION = 4¶
-
static const double SF_STATE_PARENTHESIS = 6¶
-
static const double SF_STATE_FUNCTION = 7¶
-
static const double SF_STATE_ARRAY = 8¶
-
static const double SF_STATE_ARRAYELEMENT = 9¶
-
static const double SF_STATE_WHITESPACE = 10¶
-
static const double SF_STATE_NEWLINE = 12¶
-
static const double SF_STATE_DIVISION = 13¶
-
static const double SF_STATE_STRING = 14¶
-
static const double SF_STATE_STRINGTERMINATOR = 15¶
-
static const double SF_ACTION_UNINITIALIZED = -1¶
-
static const double SF_ACTION_SKIP = 0¶
-
static const double SF_ACTION_COLLECT = 1¶
-
static const double SF_ACTION_LOWERORDER = 2¶
-
static const double SF_ACTION_HIGHERORDER = 3¶
-
static const double SF_ACTION_ARRAYELEMENT = 4¶
-
static const double SF_ACTION_PARENTHESIS = 5¶
-
static const double SF_ACTION_FUNCTION = 6¶
-
static const double SF_ACTION_ARRAY = 7¶
-
static const string SF_PARSER_REGEX_SIGNED_NUMBER = "^(?i)[+-]?[0-9]+(?:\.[0-9]+)?(?:[\+-]?E[0-9]+)?$"¶
-
static const string SF_PARSER_REGEX_QUOTED_STRING = "^\".*\"$"¶
-
static const string SF_PARSER_REGEX_SIGNED_PARENTHESIS = "^(?i)[+-]?\\([\s\S]*$"¶
-
static const string SF_PARSER_REGEX_SIGNED_FUNCTION = "^(?i)[+-]?[A-Za-z]+"¶
-
static const string SF_PARSER_REGEX_OTHER_VALID_CHARS = "[A-Za-z0-9_\.:;=!$]"¶
-
struct SF_ParserData¶