mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2026-02-04 07:02:11 +00:00
Much better function ARG parsing, allowing other functions as ARGs
This commit is contained in:
parent
19073fcc7c
commit
3c684f2153
@ -143,34 +143,33 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
|
|||||||
//bool isFunc = IsFunction(split(expression, '(')[0]);
|
//bool isFunc = IsFunction(split(expression, '(')[0]);
|
||||||
if (isFunc && !inQuotes)
|
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))
|
// start -> FuncCall(0, x, OtherFunc(a))
|
||||||
// changeto -> 0, x, OtherFunc(a)
|
// changeto -> 0, x, OtherFunc(a)
|
||||||
string insideFunArgs = betweenChars(expression, '(', ')');
|
string insideFunArgs = betweenChars(expression, '(', ')');
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
cout << insideFunArgs << endl;
|
||||||
|
#endif
|
||||||
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
cout << "["<<unWrapVec(argList) <<"]" << endl;
|
||||||
|
#endif
|
||||||
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
||||||
return ExecuteFunction(trim(split(expression, '(')[0]), funcArgs);
|
return ExecuteFunction(trim(split(expression, '(')[0]), funcArgs);
|
||||||
}
|
}
|
||||||
else if (isZS && !inQuotes)
|
else if (isZS && !inQuotes)
|
||||||
{
|
{
|
||||||
string argContents = "";
|
// start -> FuncCall(0, x, OtherFunc(a))
|
||||||
int y = indexInStr(expression, '(') + 1;
|
// changeto -> 0, x, OtherFunc(a)
|
||||||
while (y < expression.size() && expression[y] != ')')
|
string insideFunArgs = betweenChars(expression, '(', ')');
|
||||||
{
|
#if DEVELOPER_MESSAGES == true
|
||||||
argContents += expression[y];
|
cout << insideFunArgs << endl;
|
||||||
|
#endif
|
||||||
y++;
|
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
||||||
}
|
#if DEVELOPER_MESSAGES == true
|
||||||
return ZSFunction(split(expression, '(')[0], VarValues(split(argContents, ','), variableValues));
|
cout << "[" << unWrapVec(argList) << "]" << endl;
|
||||||
|
#endif
|
||||||
|
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
||||||
|
return ZSFunction(trim(split(expression, '(')[0]), funcArgs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return GetVariableValue(expression, variableValues);
|
return GetVariableValue(expression, variableValues);
|
||||||
@ -198,38 +197,34 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
|
|||||||
bool isFunc = IsFunction(name);
|
bool isFunc = IsFunction(name);
|
||||||
if (isFunc && !inQuotes)
|
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))
|
// start -> FuncCall(0, x, OtherFunc(a))
|
||||||
// changeto -> 0, x, OtherFunc(a)
|
// changeto -> 0, x, OtherFunc(a)
|
||||||
string insideFunArgs = betweenChars(expression, '(', ')');
|
string insideFunArgs = betweenChars(expression, '(', ')');
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
cout << insideFunArgs << endl;
|
||||||
|
#endif
|
||||||
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
||||||
|
#if DEVELOPER_MESSAGES == true
|
||||||
|
cout << unWrapVec(argList) << endl;
|
||||||
|
#endif
|
||||||
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
||||||
string returnVal = AnyAsString(ExecuteFunction(trim(split(expression, '(')[0]), funcArgs));
|
string returnVal = AnyAsString(ExecuteFunction(trim(split(expression, '(')[0]), funcArgs));
|
||||||
newExpression += returnVal;
|
newExpression += returnVal;
|
||||||
}
|
}
|
||||||
else if (split(name, '.')[0] == "ZS" && !inQuotes)
|
else if (split(name, '.')[0] == "ZS" && !inQuotes)
|
||||||
{
|
{
|
||||||
string argContents = "";
|
// start -> FuncCall(0, x, OtherFunc(a))
|
||||||
int y = indexInStr(expression, '(') + 1;
|
// changeto -> 0, x, OtherFunc(a)
|
||||||
while (y < expression.size() && expression[y] != ')')
|
string insideFunArgs = betweenChars(expression, '(', ')');
|
||||||
{
|
#if DEVELOPER_MESSAGES == true
|
||||||
argContents += expression[y];
|
cout << insideFunArgs << endl;
|
||||||
|
#endif
|
||||||
y++;
|
vector<string> argList = splitNoOverlap(insideFunArgs, ',', '(', ')');
|
||||||
}
|
#if DEVELOPER_MESSAGES == true
|
||||||
//cout << split(expression, '(')[0] << " " << argContents << endl;
|
cout << unWrapVec(argList) << endl;
|
||||||
string returnVal = AnyAsString(ZSFunction(split(name, '(')[0], VarValues(split(argContents, ','), variableValues)));
|
#endif
|
||||||
|
vector<boost::any> funcArgs = VarValues(argList, variableValues);
|
||||||
|
string returnVal = AnyAsString(ExecuteFunction(trim(split(expression, '(')[0]), funcArgs));
|
||||||
newExpression += returnVal;
|
newExpression += returnVal;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -246,7 +241,7 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
|
|||||||
{
|
{
|
||||||
newExpression += expression[i];
|
newExpression += expression[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if DEVELOPER_MESSAGES == true
|
#if DEVELOPER_MESSAGES == true
|
||||||
//InterpreterLog(" new expression: |" + newExpression + "|");
|
//InterpreterLog(" new expression: |" + newExpression + "|");
|
||||||
#endif
|
#endif
|
||||||
@ -626,7 +621,7 @@ boost::any ExecuteFunction(const string& functionName, const vector<boost::any>&
|
|||||||
cout << functionName + " \x1B[33m" << funcArgs[i] << " == " << AnyAsString(inputVarVals[i]) << "\033[0m\t\t" << endl;
|
cout << functionName + " \x1B[33m" << funcArgs[i] << " == " << AnyAsString(inputVarVals[i]) << "\033[0m\t\t" << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Iterate through all lines in function
|
//Iterate through all lines in function
|
||||||
for (int lineNum = 1; lineNum < (int)words.size(); lineNum++)
|
for (int lineNum = 1; lineNum < (int)words.size(); lineNum++)
|
||||||
@ -761,7 +756,7 @@ int parseZSharp(string script)
|
|||||||
/*else
|
/*else
|
||||||
LogWarning("unrecognized type \'" + words.at(lineNum).at(0) + "\' on line: " + to_string(lineNum));*/
|
LogWarning("unrecognized type \'" + words.at(lineNum).at(0) + "\' on line: " + to_string(lineNum));*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -790,7 +785,7 @@ int main(int argc, char* argv[])
|
|||||||
#if DEVELOPER_MESSAGES
|
#if DEVELOPER_MESSAGES
|
||||||
cout << scriptPath << endl;
|
cout << scriptPath << endl;
|
||||||
#endif
|
#endif
|
||||||
if (!fileExists(scriptPath)
|
if (!fileExists(scriptPath))
|
||||||
LogCriticalError("Failed to load script from path: \"" + scriptPath + "\"");
|
LogCriticalError("Failed to load script from path: \"" + scriptPath + "\"");
|
||||||
|
|
||||||
std::string projectDirectory = scriptPath.substr(0, scriptPath.find_last_of("/\\"));
|
std::string projectDirectory = scriptPath.substr(0, scriptPath.find_last_of("/\\"));
|
||||||
@ -806,7 +801,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
// Change the current working directory to that of the script
|
// Change the current working directory to that of the script
|
||||||
int chErr = chdir(projectDirectory.c_str());
|
int chErr = chdir(projectDirectory.c_str());
|
||||||
if(chErr < 0)
|
if (chErr < 0)
|
||||||
LogCriticalError("Failed to change directory to: \"" + projectDirectory.c_str() + "\", error num: " + chErr);
|
LogCriticalError("Failed to change directory to: \"" + projectDirectory.c_str() + "\", error num: " + chErr);
|
||||||
#if DEVELOPER_MESSAGES
|
#if DEVELOPER_MESSAGES
|
||||||
InterpreterLog("Changed directory to " + projectDirectory + "...");
|
InterpreterLog("Changed directory to " + projectDirectory + "...");
|
||||||
|
|||||||
@ -159,16 +159,26 @@ vector<string> splitNoOverlap(const string& str, const char& splitBy, const char
|
|||||||
string tmpStr = "";
|
string tmpStr = "";
|
||||||
for (int i = 0; i < (int)str.size(); i++)
|
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)
|
if (str[i] == splitBy && openCount == 0)
|
||||||
{
|
{
|
||||||
newStr.push_back(tmpStr);
|
newStr.push_back(tmpStr);
|
||||||
tmpStr = "";
|
tmpStr = "";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (str[i] == openChar)
|
else if (str[i] == openChar) {
|
||||||
|
tmpStr += str[i];
|
||||||
openCount += 1;
|
openCount += 1;
|
||||||
else if (str[i] == closeChar)
|
}
|
||||||
|
else if (str[i] == closeChar) {
|
||||||
|
tmpStr += str[i];
|
||||||
openCount -= 1;
|
openCount -= 1;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
tmpStr += str[i];
|
tmpStr += str[i];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user