Allow for same-line curly brackets on: if, while, func

This commit is contained in:
sam-astro 2022-05-22 13:28:57 -04:00
parent cefbbd140b
commit 74df9cdaf7
2 changed files with 45 additions and 19 deletions

View File

@ -441,11 +441,19 @@ boost::any ProcessLine(const vector<vector<string>>& words, int lineNum, unorder
vector<vector<string>> whileContents; vector<vector<string>> whileContents;
vector<string> whileParameters; vector<string> whileParameters;
for (int w = 1; w < (int)words.at(lineNum).size(); w++) int numOfBrackets = 0;
for (int w = 1; w < (int)words.at(lineNum).size(); w++) {
if (count(words.at(lineNum).at(w), '{') == 0)
whileParameters.push_back(words.at(lineNum)[w]); whileParameters.push_back(words.at(lineNum)[w]);
else
{
whileParameters.push_back(replace(words.at(lineNum)[w], "{", ""));
numOfBrackets = 1;
break;
}
}
int numOfBrackets = 1; for (int p = lineNum + 1; p < (int)words.size(); p++)
for (int p = lineNum + 2; p < (int)words.size(); p++)
{ {
numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}"); numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}");
if (numOfBrackets == 0) if (numOfBrackets == 0)
@ -473,18 +481,24 @@ boost::any ProcessLine(const vector<vector<string>>& words, int lineNum, unorder
vector<vector<string>> ifContents; vector<vector<string>> ifContents;
vector<string> ifParameters; vector<string> ifParameters;
for (int w = 1; w < (int)words.at(lineNum).size(); w++) int numOfBrackets = 0;
ifParameters.push_back(words.at(lineNum).at(w)); for (int w = 1; w < (int)words.at(lineNum).size(); w++) {
if (count(words.at(lineNum).at(w), '{') == 0)
int numOfBrackets = 1; ifParameters.push_back(words.at(lineNum)[w]);
lineNum += 2; else
while (lineNum < (int)words.size())
{ {
numOfBrackets += countInVector(words.at(lineNum), "{") - countInVector(words.at(lineNum), "}"); ifParameters.push_back(replace(words.at(lineNum)[w], "{", ""));
numOfBrackets = 1;
break;
}
}
for (int p = lineNum + 1; p < (int)words.size(); p++)
{
numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}");
if (numOfBrackets == 0) if (numOfBrackets == 0)
break; break;
ifContents.push_back(words.at(lineNum)); ifContents.push_back(words.at(p));
lineNum++;
} }
ifContents = removeTabsWdArry(ifContents, 1); ifContents = removeTabsWdArry(ifContents, 1);
@ -612,14 +626,22 @@ int parseZSharp(string script)
if (indexInStr(unWrapVec(words.at(lineNum)), ')') - indexInStr(unWrapVec(words.at(lineNum)), '(') > 1) if (indexInStr(unWrapVec(words.at(lineNum)), ')') - indexInStr(unWrapVec(words.at(lineNum)), '(') > 1)
for (int w = 1; w < (int)words.at(lineNum).size(); w++) // Get all words from the instantiation line: these are the args for (int w = 1; w < (int)words.at(lineNum).size(); w++) // Get all words from the instantiation line: these are the args
{ {
if (count(words.at(lineNum).at(w), '{') == 0)
args += replace(replace(words.at(lineNum).at(w), "(", " "), ")", ""); args += replace(replace(words.at(lineNum).at(w), "(", " "), ")", "");
} }
args = trim(replace(args, functName + " ", "")); args = trim(replace(args, functName + " ", ""));
functionContents.push_back(split(args, ',')); functionContents.push_back(split(args, ','));
int numOfBrackets = 1; int numOfBrackets = 0;
for (int p = lineNum + 2; p < (int)words.size(); p++) for (int w = 1; w < (int)words.at(lineNum).size(); w++) {
if (count(words.at(lineNum).at(w), '{') != 0) {
numOfBrackets = 1;
break;
}
}
for (int p = lineNum + 1; p < (int)words.size(); p++)
{ {
numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}"); numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}");
if (numOfBrackets == 0) if (numOfBrackets == 0)

View File

@ -36,10 +36,15 @@ func Start()
global Text g_instructionsText = ZS.Graphics.Text("Use Arrow Keys or WASD to Move, and Spacebar to Jump", "./arial.ttf", instructionsPos, 20, 0, 255, 255, 255) global Text g_instructionsText = ZS.Graphics.Text("Use Arrow Keys or WASD to Move, and Spacebar to Jump", "./arial.ttf", instructionsPos, 20, 0, 255, 255, 255)
global Vec2 g_playerTargetPosition = playerPos global Vec2 g_playerTargetPosition = playerPos
int i = 0
while i < 10 {
i += 1
print "while iter : " + i
}
} }
func Update(deltaTime) func Update(deltaTime) {
{
float fps = 1 / deltaTime float fps = 1 / deltaTime
print "FPS: " + fps print "FPS: " + fps
TestInclude() TestInclude()
@ -51,8 +56,7 @@ func Update(deltaTime)
// Shift key lets you sprint // Shift key lets you sprint
g_running = GetKey("SHIFT_L") g_running = GetKey("SHIFT_L")
if g_running == true if g_running == true{
{
g_currPlayerSpeed = g_playerRunSpeed g_currPlayerSpeed = g_playerRunSpeed
} }
if g_running == false if g_running == false