Much better function ARG parsing, allowing other functions as ARGs

This commit is contained in:
sam-astro 2022-05-24 16:10:39 -04:00
parent 19073fcc7c
commit 3c684f2153
2 changed files with 61 additions and 56 deletions

View File

@ -143,34 +143,33 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
//bool isFunc = IsFunction(split(expression, '(')[0]);
if (isFunc && !inQuotes)
{
//cout << split(expression, '(')[0] << endl;
//string argContents = "";
//int y = indexInStr(expression, '(') + 1;
//while (y < expression.size() && expression[y] != ')')
//{
// argContents += expression[y];
// y++;
//}
//return ExecuteFunction(split(expression, '(')[0], VarValues(split(argContents, ','), variableValues));
// start -> FuncCall(0, x, OtherFunc(a))
// changeto -> 0, x, OtherFunc(a)
string insideFunArgs = betweenChars(expression, '(', ')');
#if DEVELOPER_MESSAGES == true
cout << insideFunArgs << endl;
#endif
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
#if DEVELOPER_MESSAGES == true
cout << "["<<unWrapVec(argList) <<"]" << endl;
#endif
vector<boost::any> funcArgs = VarValues(argList, variableValues);
return ExecuteFunction(trim(split(expression, '(')[0]), funcArgs);
}
else if (isZS && !inQuotes)
{
string argContents = "";
int y = indexInStr(expression, '(') + 1;
while (y < expression.size() && expression[y] != ')')
{
argContents += expression[y];
y++;
}
return ZSFunction(split(expression, '(')[0], VarValues(split(argContents, ','), variableValues));
// start -> FuncCall(0, x, OtherFunc(a))
// changeto -> 0, x, OtherFunc(a)
string insideFunArgs = betweenChars(expression, '(', ')');
#if DEVELOPER_MESSAGES == true
cout << insideFunArgs << endl;
#endif
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
#if DEVELOPER_MESSAGES == true
cout << "[" << unWrapVec(argList) << "]" << endl;
#endif
vector<boost::any> funcArgs = VarValues(argList, variableValues);
return ZSFunction(trim(split(expression, '(')[0]), funcArgs);
}
else
return GetVariableValue(expression, variableValues);
@ -198,38 +197,34 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
bool isFunc = IsFunction(name);
if (isFunc && !inQuotes)
{
//string argContents = "";
//i++;
//while (i < expression.size() && expression[i] != ')')
//{
// argContents += expression[i];
// i++;
//}
//string returnVal = AnyAsString(ExecuteFunction(name, VarValues(split(argContents, ','), variableValues)));
//newExpression += returnVal;
// start -> FuncCall(0, x, OtherFunc(a))
// changeto -> 0, x, OtherFunc(a)
string insideFunArgs = betweenChars(expression, '(', ')');
#if DEVELOPER_MESSAGES == true
cout << insideFunArgs << endl;
#endif
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
#if DEVELOPER_MESSAGES == true
cout << unWrapVec(argList) << endl;
#endif
vector<boost::any> funcArgs = VarValues(argList, variableValues);
string returnVal = AnyAsString(ExecuteFunction(trim(split(expression, '(')[0]), funcArgs));
newExpression += returnVal;
}
else if (split(name, '.')[0] == "ZS" && !inQuotes)
{
string argContents = "";
int y = indexInStr(expression, '(') + 1;
while (y < expression.size() && expression[y] != ')')
{
argContents += expression[y];
y++;
}
//cout << split(expression, '(')[0] << " " << argContents << endl;
string returnVal = AnyAsString(ZSFunction(split(name, '(')[0], VarValues(split(argContents, ','), variableValues)));
// start -> FuncCall(0, x, OtherFunc(a))
// changeto -> 0, x, OtherFunc(a)
string insideFunArgs = betweenChars(expression, '(', ')');
#if DEVELOPER_MESSAGES == true
cout << insideFunArgs << endl;
#endif
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
#if DEVELOPER_MESSAGES == true
cout << unWrapVec(argList) << endl;
#endif
vector<boost::any> funcArgs = VarValues(argList, variableValues);
string returnVal = AnyAsString(ExecuteFunction(trim(split(expression, '(')[0]), funcArgs));
newExpression += returnVal;
}
else
@ -790,7 +785,7 @@ int main(int argc, char* argv[])
#if DEVELOPER_MESSAGES
cout << scriptPath << endl;
#endif
if (!fileExists(scriptPath)
if (!fileExists(scriptPath))
LogCriticalError("Failed to load script from path: \"" + scriptPath + "\"");
std::string projectDirectory = scriptPath.substr(0, scriptPath.find_last_of("/\\"));

View File

@ -159,16 +159,26 @@ vector<string> splitNoOverlap(const string& str, const char& splitBy, const char
string tmpStr = "";
for (int i = 0; i < (int)str.size(); i++)
{
if (i == (int)str.size() - 1)
{
newStr.push_back(tmpStr+ str[i]);
break;
}
if (str[i] == splitBy && openCount == 0)
{
newStr.push_back(tmpStr);
tmpStr = "";
continue;
}
else if (str[i] == openChar)
else if (str[i] == openChar) {
tmpStr += str[i];
openCount += 1;
else if (str[i] == closeChar)
}
else if (str[i] == closeChar) {
tmpStr += str[i];
openCount -= 1;
}
else
tmpStr += str[i];
}