@@ -73,6 +73,42 @@ namespace FPL {
7373
7474
7575
76+
77+
78+ bool Parser::ImportInstruction (std::optional<FonctionDefinition>& fonction) {
79+ auto fichierName = CheckerValue ();
80+ if (fichierName.has_value ()) {
81+ if (fonction.has_value ()) {
82+ std::cerr << " Vous ne pouvez pas importer un fichier F.P.L dans une fonction." << std::endl;
83+ exit (1 );
84+ }
85+
86+ if (CheckerOperateur (" ;" ).has_value ()) {
87+ std::replace (fichierName->StatementName .begin (), fichierName->StatementName .end (), ' "' , ' ' );
88+ fichierName->StatementName .erase (std::remove_if (fichierName->StatementName .begin (), fichierName->StatementName .end (), ::isspace), fichierName->StatementName .end ());
89+
90+ std::ifstream file { fichierName->StatementName };
91+ if (!file) {
92+ std::cerr << " Donnez le nom correct du fichier : '" << fichierName->StatementName << " '." << std::endl;
93+ exit (1 );
94+ }
95+ std::string f_content ((std::istreambuf_iterator<char >(file)), (std::istreambuf_iterator<char >()));
96+ TokenBuilding t;
97+ std::vector<Token> tokens = t.parseToken (f_content);
98+
99+ auto FCurrToken = tokens.begin ();
100+ auto oldCurrentToken = mCurrentToken ;
101+ std::optional<FonctionDefinition> f = fonction;
102+ parse (tokens, f);
103+ mCurrentToken = oldCurrentToken;
104+ return true ;
105+ }
106+ std::cerr << " Vous devez mettre le symbole ';' pour mettre fin a l'instruction." << std::endl;
107+ exit (1 );
108+ }
109+ return false ;
110+ }
111+
76112 bool Parser::FichierInstruction (std::optional<FonctionDefinition>& fonction) {
77113 auto arg = CheckerIdentifiant ();
78114 if (arg.has_value ()) {
@@ -94,10 +130,6 @@ namespace FPL {
94130 if (valueInFile.has_value ()) {
95131 if (CheckerOperateur (" ;" ).has_value ()) {
96132 std::ofstream file { fichierName->StatementName };
97- /* if (!file) {
98- std::cerr << "Donnez le nom correct du fichier : '" << fichierName->StatementName << "'." << std::endl;
99- exit(1);
100- }*/
101133 std::replace (valueInFile->StatementName .begin (), valueInFile->StatementName .end (), ' "' , ' ' );
102134 file << valueInFile->StatementName << std::endl;
103135 file.close ();
@@ -983,6 +1015,8 @@ namespace FPL {
9831015 if (SaisirInstruction (fonction)) { return true ; } else { return false ; }
9841016 } else if (PeutEtreInstruction->mText == " fichier" ) {
9851017 if (FichierInstruction (fonction)) {return true ;} else {return false ;}
1018+ } else if (PeutEtreInstruction->mText == " importer" ) {
1019+ if (ImportInstruction (fonction)) { return true ; } else { return false ; }
9861020 }
9871021 else {
9881022 mCurrentToken = parseStart;
@@ -999,7 +1033,7 @@ namespace FPL {
9991033 if (ManagerInstruction (fonction)) {
10001034
10011035 } else {
1002- if (mCurrentToken ->mText .empty () || mCurrentToken ->mType == ESPACEVIDE ) {
1036+ if (mCurrentToken ->mText .empty () || mCurrentToken ->mType == ESPACEVIDE || mCurrentToken -> mText == " " || mCurrentToken -> mText == " " ) {
10031037 continue ;
10041038 }
10051039
0 commit comments