Skip to content

Commit 10b702b

Browse files
committed
Optimisations.
1 parent dca6c55 commit 10b702b

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

src/Parser.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ namespace FPL {
105105
variable.VariableType = Type(VarType->mName, VarType->mType);
106106
variable.VariableValue = VarValue->StatementName;
107107

108+
if (VarType->mType == STRING) {
109+
std::replace(variable.VariableValue.begin(), variable.VariableValue.end(), '"', ' ');
110+
}
111+
108112
mVariables[variable.VariableName] = variable;
109113

110114
std::cout << "La variable '"
@@ -140,17 +144,17 @@ namespace FPL {
140144
return false;
141145
}
142146

143-
144147
bool Parser::Print() {
145148
auto parseStart = mCurrentToken; // std::vector<Token>::iterator
146149
auto PeutEtreInstruction = CheckerIdentifiant();
147150
if (PeutEtreInstruction.has_value()) {
148151
if (PeutEtreInstruction->mText == "envoyer") {
149-
auto ChaineEnter = CheckerChaineLitteral();
150-
if (ChaineEnter.has_value()) {
151-
std::string printContent = ChaineEnter->mText;
152-
std::replace(printContent.begin(), printContent.end(), '"', ' ');
153-
std::cout << printContent << std::endl;
152+
auto Value = CheckerValue();
153+
if (Value.has_value()) {
154+
if (Value->StatementType.mType == STRING) {
155+
std::replace(Value->StatementName.begin(), Value->StatementName.end(), '"', ' ');
156+
}
157+
std::cout << Value->StatementName << std::endl;
154158
return true;
155159
} else {
156160
mCurrentToken = parseStart;
@@ -191,17 +195,7 @@ namespace FPL {
191195
}
192196
}
193197

194-
std::optional<Token> Parser::CheckerChaineLitteral(const std::string &name) {
195-
if (mCurrentToken == mEndToken) { return std::nullopt; }
196-
if (mCurrentToken->mType != CHAINE_LITERAL) { return std::nullopt; }
197-
if (mCurrentToken->mText != name && !name.empty()) { return std::nullopt; }
198-
199-
auto returnToken = mCurrentToken;
200-
++mCurrentToken;
201-
return *returnToken;
202-
}
203-
204-
std::optional<Token> Parser::CheckerIdentifiant(const std::string &name) {
198+
std::optional<Token> Parser::CheckerIdentifiant(std::string_view name) {
205199
if (mCurrentToken == mEndToken) { return std::nullopt; }
206200
if (mCurrentToken->mType != IDENTIFIANT) { return std::nullopt; }
207201
if (mCurrentToken->mText != name && !name.empty()) { return std::nullopt; }
@@ -211,7 +205,7 @@ namespace FPL {
211205
return *returnToken;
212206
}
213207

214-
std::optional<Token> Parser::CheckerOperateur(const std::string &name) {
208+
std::optional<Token> Parser::CheckerOperateur(std::string_view name) {
215209
if (mCurrentToken == mEndToken) { return std::nullopt; }
216210
if (mCurrentToken->mType != OPERATEUR) { return std::nullopt; }
217211
if (mCurrentToken->mText != name && !name.empty()) { return std::nullopt; }
@@ -222,7 +216,7 @@ namespace FPL {
222216
return *returnToken; // On donne l'opérateur
223217
}
224218

225-
std::optional<Type> Parser::CheckerType(const std::string &name) {
219+
std::optional<Type> Parser::CheckerType(std::string_view name) {
226220
auto possibleType = CheckerIdentifiant();
227221
if (!possibleType.has_value()) { return std::nullopt; }
228222

src/Parser.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <iostream>
44
#include <vector>
55
#include <string>
6+
#include <string_view>
67
#include <stdexcept>
78
#include <optional>
89
#include <map>
@@ -25,10 +26,9 @@ namespace FPL {
2526

2627
private:
2728
// Essentielles:
28-
std::optional<Type> CheckerType(const std::string &name = std::string());
29-
std::optional<Token> CheckerIdentifiant(const std::string &name = std::string());
30-
std::optional<Token> CheckerOperateur(const std::string &name = std::string());
31-
std::optional<Token> CheckerChaineLitteral(const std::string &name = std::string());
29+
std::optional<Type> CheckerType(std::string_view name = std::string());
30+
std::optional<Token> CheckerIdentifiant(std::string_view name = std::string());
31+
std::optional<Token> CheckerOperateur(std::string_view name = std::string());
3232
std::optional<Statement> CheckerValue();
3333

3434

0 commit comments

Comments
 (0)