Skip to content

Commit 1cfb882

Browse files
committed
Instruction "verifier" (WIP)
1 parent 33f3b54 commit 1cfb882

File tree

1 file changed

+82
-3
lines changed

1 file changed

+82
-3
lines changed

src/Parser.cpp

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ namespace FPL {
2828
"importer",
2929
"convertir",
3030
"bool",
31-
"booleen"
31+
"booleen",
32+
"verifier"
3233
};
3334
}
3435

@@ -193,6 +194,82 @@ namespace FPL {
193194
return false;
194195
}
195196

197+
bool Parser::VerifierInstruction(std::optional<FonctionDefinition>& fonction) {
198+
auto PossibleVar = CheckerIdentifiant();
199+
if (PossibleVar.has_value()) {
200+
if (CheckerOperateur("{").has_value()) {
201+
while (!CheckerOperateur("}").has_value()) {
202+
std::vector<std::string> contentChecking;
203+
204+
auto checkerInstruction = CheckerIdentifiant();
205+
if (!checkerInstruction.has_value() && CheckerOperateur("}").has_value()) {
206+
break;
207+
} else if (!checkerInstruction.has_value() || checkerInstruction->mText != "quand") {
208+
std::cerr << "Vous devez verifier une valeur avec 'quand' !" << std::endl;
209+
exit(1);
210+
}
211+
212+
auto wantCheckValue = CheckerValue();
213+
if (!wantCheckValue.has_value()) {
214+
std::cerr << "Vous devez une valeur que vous souhaitez verifier !" << std::endl;
215+
exit(1);
216+
}
217+
218+
if (CheckerOperateur(":").has_value()) {
219+
while (!CheckerOperateur(",").has_value()) {
220+
if (mCurrentToken->mType == CHAINE_LITERAL) {
221+
mCurrentToken->mText += "\"";
222+
}
223+
224+
contentChecking.push_back(mCurrentToken->mText);
225+
++mCurrentToken;
226+
}
227+
} else {
228+
std::cerr << "Vous devez mettre le symbole ':' pour mettre votre code." << std::endl;
229+
exit(1);
230+
}
231+
232+
std::string finalContent;
233+
234+
for (auto const &a : contentChecking) {
235+
finalContent.append(a).append(" ");
236+
}
237+
238+
TokenBuilding t;
239+
std::cout << "" << std::endl; // IGNORE (finalContent) -> sans le print, cela ne marche plus.
240+
std::vector<Token> tokens = t.parseToken(finalContent);
241+
242+
auto FCurrToken = tokens.begin();
243+
auto oldCurrentToken = mCurrentToken;
244+
std::optional<FonctionDefinition> f = fonction;
245+
246+
if (fonction.has_value() && isArgument(fonction->FonctionName, PossibleVar->mText)) {
247+
auto argument = mArguments[fonction->FonctionName][PossibleVar->mText];
248+
if (argument.ArgValue == wantCheckValue->StatementName) {
249+
parse(tokens, f);
250+
mCurrentToken = oldCurrentToken;
251+
}
252+
} else if (isVariable(PossibleVar->mText)) {
253+
auto variable = mVariables[PossibleVar->mText];
254+
if (variable.VariableValue == wantCheckValue->StatementName) {
255+
parse(tokens, f);
256+
mCurrentToken = oldCurrentToken;
257+
}
258+
}
259+
260+
if (CheckerOperateur("}").has_value()) {
261+
break;
262+
}
263+
}
264+
return true;
265+
} else {
266+
std::cerr << "Vous devez mettre le symbole '{' pour ouvrir l'instruction." << std::endl;
267+
exit(1);
268+
}
269+
}
270+
return false;
271+
}
272+
196273
bool Parser::AppelerInstruction() {
197274
auto PossibleFonctionName = CheckerIdentifiant();
198275
if (PossibleFonctionName.has_value()) {
@@ -1183,8 +1260,8 @@ namespace FPL {
11831260
}
11841261

11851262
bool Parser::ManagerInstruction(std::optional<FonctionDefinition>& fonction) {
1186-
auto const parseStart = mCurrentToken; // std::vector<Token>::iterator
1187-
auto const PeutEtreInstruction = CheckerIdentifiant();
1263+
auto parseStart = mCurrentToken; // std::vector<Token>::iterator
1264+
auto PeutEtreInstruction = CheckerIdentifiant();
11881265
if (PeutEtreInstruction.has_value()) {
11891266
if (PeutEtreInstruction->mText == "envoyer") {
11901267
if (PrintInstruction(parseStart, fonction)) { return true; } else { return false; }
@@ -1204,6 +1281,8 @@ namespace FPL {
12041281
if (ImportInstruction(fonction)) { return true; } else { return false; }
12051282
} else if (PeutEtreInstruction->mText == "convertir") {
12061283
if (ConversionInstruction(fonction)) { return true; } else { return false; }
1284+
} else if (PeutEtreInstruction->mText == "verifier") {
1285+
if (VerifierInstruction(fonction)) { return true; } else { return false; }
12071286
}
12081287
else {
12091288
mCurrentToken = parseStart;

0 commit comments

Comments
 (0)