Skip to content

Commit ea5d8be

Browse files
committed
Possibilité de verifier plusieurs valeurs dans un seul 'quand'.
1 parent c4ef939 commit ea5d8be

File tree

1 file changed

+75
-14
lines changed

1 file changed

+75
-14
lines changed

src/Parser.cpp

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ namespace FPL {
3333
};
3434
}
3535

36+
bool ValueInSTRvector(std::vector<std::string>& array, std::string& value) {
37+
for (auto e : array) {
38+
39+
if (e == value) {
40+
return true;
41+
}
42+
}
43+
return false;
44+
}
45+
3646
void Parser::ManageVariableName(std::optional<FonctionDefinition>& fonction, std::string name) {
3747
if (isVariable(name)) {
3848
std::cerr << "Veuillez choisir un autre nom pour votre variable." << std::endl;
@@ -200,6 +210,8 @@ namespace FPL {
200210
if (CheckerOperateur("{").has_value()) {
201211
while (!CheckerOperateur("}").has_value()) {
202212
std::vector<std::string> contentChecking;
213+
std::vector<std::string> contentValues;
214+
bool morethanoneValue = false;
203215

204216
auto checkerInstruction = CheckerIdentifiant();
205217
if (!checkerInstruction.has_value() && CheckerOperateur("}").has_value()) {
@@ -211,11 +223,48 @@ namespace FPL {
211223

212224
auto wantCheckValue = CheckerValue();
213225
if (!wantCheckValue.has_value()) {
214-
std::cerr << "Vous devez une valeur que vous souhaitez verifier !" << std::endl;
226+
std::cerr << "Vous devez mettre une valeur que vous souhaitez verifier !" << std::endl;
215227
exit(1);
216228
}
217229

218-
if (CheckerOperateur(":").has_value()) {
230+
if (CheckerOperateur(",").has_value()) {
231+
auto wantCheckValue2 = CheckerValue();
232+
if (wantCheckValue2.has_value()) {
233+
morethanoneValue = true;
234+
contentValues.push_back(wantCheckValue2->StatementName);
235+
contentValues.push_back(wantCheckValue->StatementName);
236+
237+
while (!CheckerOperateur(":").has_value()) {
238+
auto nextValue = CheckerValue();
239+
if (!nextValue.has_value()) {
240+
std::cerr << "Vous devez mettre une valeur que vous souhaitez verifier !" << std::endl;
241+
exit(1);
242+
}
243+
244+
contentValues.push_back(nextValue->StatementName);
245+
246+
if (!CheckerOperateur(",").has_value()) {
247+
break;
248+
}
249+
}
250+
}
251+
}
252+
253+
if (!morethanoneValue) {
254+
if (CheckerOperateur(":").has_value()) {
255+
while (!CheckerOperateur(",").has_value()) {
256+
if (mCurrentToken->mType == CHAINE_LITERAL) {
257+
mCurrentToken->mText += "\"";
258+
}
259+
260+
contentChecking.push_back(mCurrentToken->mText);
261+
++mCurrentToken;
262+
}
263+
} else {
264+
std::cerr << "Vous devez mettre le symbole ':' pour mettre votre code." << std::endl;
265+
exit(1);
266+
}
267+
} else {
219268
while (!CheckerOperateur(",").has_value()) {
220269
if (mCurrentToken->mType == CHAINE_LITERAL) {
221270
mCurrentToken->mText += "\"";
@@ -224,9 +273,6 @@ namespace FPL {
224273
contentChecking.push_back(mCurrentToken->mText);
225274
++mCurrentToken;
226275
}
227-
} else {
228-
std::cerr << "Vous devez mettre le symbole ':' pour mettre votre code." << std::endl;
229-
exit(1);
230276
}
231277

232278
std::string finalContent;
@@ -246,21 +292,36 @@ namespace FPL {
246292

247293
if (fonction.has_value() && isArgument(fonction->FonctionName, PossibleVar->mText)) {
248294
auto argument = mArguments[fonction->FonctionName][PossibleVar->mText];
249-
if (argument.ArgValue == wantCheckValue->StatementName) {
250-
parse(tokens, f);
251-
mCurrentToken = oldCurrentToken;
252-
didNotExecuteTheCodeWithif = true;
295+
if (!morethanoneValue) {
296+
if (argument.ArgValue == wantCheckValue->StatementName) {
297+
parse(tokens, f);
298+
mCurrentToken = oldCurrentToken;
299+
didNotExecuteTheCodeWithif = true;
300+
}
301+
} else {
302+
if (ValueInSTRvector(contentValues, argument.ArgValue)) {
303+
parse(tokens, f);
304+
mCurrentToken = oldCurrentToken;
305+
didNotExecuteTheCodeWithif = true;
306+
}
253307
}
254308
} else if (isVariable(PossibleVar->mText)) {
255309
auto variable = mVariables[PossibleVar->mText];
256-
if (variable.VariableValue == wantCheckValue->StatementName) {
257-
parse(tokens, f);
258-
mCurrentToken = oldCurrentToken;
259-
didNotExecuteTheCodeWithif = true;
310+
if (!morethanoneValue) {
311+
if (variable.VariableValue == wantCheckValue->StatementName) {
312+
parse(tokens, f);
313+
mCurrentToken = oldCurrentToken;
314+
didNotExecuteTheCodeWithif = true;
315+
}
316+
} else {
317+
if (ValueInSTRvector(contentValues, variable.VariableValue)) {
318+
parse(tokens, f);
319+
mCurrentToken = oldCurrentToken;
320+
didNotExecuteTheCodeWithif = true;
321+
}
260322
}
261323
}
262324

263-
264325
auto elseInstruction = CheckerIdentifiant();
265326
if (elseInstruction.has_value() && elseInstruction->mText == "defaut") {
266327
if (CheckerOperateur(":").has_value()) {

0 commit comments

Comments
 (0)