From 16d6ff83112265a2d5618e96e80034316b1b5317 Mon Sep 17 00:00:00 2001 From: WanderingPenwing Date: Fri, 13 Dec 2024 13:49:51 +0100 Subject: [PATCH] colors --- pendragon.project | 2 +- src/main.rs | 15 +++++----- src/pendragon/debug.rs | 40 ++++++++++++++++++++++++-- src/pendragon/mod.rs | 4 +-- src/pendragon/texte.rs | 1 - src/pendragon/vocabulaire.rs | 54 ------------------------------------ 6 files changed, 48 insertions(+), 68 deletions(-) delete mode 100644 src/pendragon/vocabulaire.rs diff --git a/pendragon.project b/pendragon.project index 14db419..40b5f7f 100644 --- a/pendragon.project +++ b/pendragon.project @@ -1 +1 @@ -{"categories":[{"name":"todo","content":[{"name":"if","description":"implémente if avec des guillemets de délimitation","id":1},{"name":"scope variable","description":"// Hello there","id":6},{"name":"while","description":"implémente un while","id":2},{"name":"else","description":"// Hello there","id":7},{"name":"break","description":"// Hello there","id":8},{"name":"continue","description":"// Hello there","id":9},{"name":"compilation","description":"// Hello there","id":3}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"comparaison","description":"// Hello there","id":2},{"name":"booleen type","description":"// Hello there","id":4},{"name":"soixante-dix","description":"// Hello there","id":1},{"name":"parenthese comparaison","description":"// Hello there","id":1},{"name":"test comparaison","description":"// Hello there","id":4},{"name":"error ligne compilation","description":"// Hello there","id":2},{"name":"commentaires","description":"// Hello there","id":3},{"name":"compile time verification","description":"odre des termes rpn","id":1},{"name":"test multiple space in texte","description":"// Hello there","id":3},{"name":"test puis in texte","description":"// Hello there","id":2},{"name":"enchainement puis","description":"// Hello there","id":5},{"name":"guillemet mal ferme","description":"// Hello there","id":4},{"name":"display element","description":"for better print","id":6},{"name":"puis à la ligne, alinéa","description":"// Hello there","id":1},{"name":"teste double tiret","description":"// Hello there","id":2},{"name":"teste puis seul","description":"tout seul, seul devant, seul fin","id":3},{"name":"erreur calcul bool/nombre","description":"affiche element precedent lorsque mauvais enchainement","id":1}]},{"name":"bug","content":[]},{"name":"to test","content":[{"name":"tests mod","description":"// Hello there","id":3},{"name":"test variable","description":"// Hello there","id":2}]},{"name":"bonus","content":[{"name":"stop cheating with \"-\"","description":"// Hello there","id":5},{"name":"affiche ligne et position erreur","description":"// Hello there","id":1},{"name":"pour numero de ligne execution","description":"sauvegarde numero de ligne dans la commande\n\ncommande.ligne(12)","id":3},{"name":"standardizer erreur","description":"regarder les texte répétés","id":1}]},{"name":"+","content":[]}]} \ No newline at end of file +{"categories":[{"name":"todo","content":[{"name":"multiple compilation error","description":"// Hello there","id":1},{"name":"if","description":"implémente if avec des guillemets de délimitation","id":1},{"name":"scope variable","description":"// Hello there","id":6},{"name":"while","description":"implémente un while","id":2},{"name":"else","description":"// Hello there","id":7},{"name":"break","description":"// Hello there","id":8},{"name":"continue","description":"// Hello there","id":9},{"name":"compilation","description":"// Hello there","id":3}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"comparaison","description":"// Hello there","id":2},{"name":"booleen type","description":"// Hello there","id":4},{"name":"soixante-dix","description":"// Hello there","id":1},{"name":"parenthese comparaison","description":"// Hello there","id":1},{"name":"test comparaison","description":"// Hello there","id":4},{"name":"error ligne compilation","description":"// Hello there","id":2},{"name":"commentaires","description":"// Hello there","id":3},{"name":"compile time verification","description":"odre des termes rpn","id":1},{"name":"test multiple space in texte","description":"// Hello there","id":3},{"name":"test puis in texte","description":"// Hello there","id":2},{"name":"enchainement puis","description":"// Hello there","id":5},{"name":"guillemet mal ferme","description":"// Hello there","id":4},{"name":"display element","description":"for better print","id":6},{"name":"puis à la ligne, alinéa","description":"// Hello there","id":1},{"name":"teste double tiret","description":"// Hello there","id":2},{"name":"teste puis seul","description":"tout seul, seul devant, seul fin","id":3},{"name":"erreur calcul bool/nombre","description":"affiche element precedent lorsque mauvais enchainement","id":1}]},{"name":"bug","content":[]},{"name":"to test","content":[{"name":"tests mod","description":"// Hello there","id":3},{"name":"test variable","description":"// Hello there","id":2}]},{"name":"bonus","content":[{"name":"stop cheating with \"-\"","description":"// Hello there","id":5},{"name":"affiche ligne et position erreur","description":"// Hello there","id":1},{"name":"pour numero de ligne execution","description":"sauvegarde numero de ligne dans la commande\n\ncommande.ligne(12)","id":3},{"name":"standardizer erreur","description":"regarder les texte répétés","id":1}]},{"name":"+","content":[]}]} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 82a08fe..7573b77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,31 +21,30 @@ fn main() { let lecture = fs::read_to_string(chemin_de_fichier); if let Err(raison) = lecture { - eprintln!("Fichier illisible : {}", raison); + eprintln!("{}Fichier illisible :{} {}", debug::TEXTE_ROUGE, raison, debug::TEXTE_NORMAL); return } - println!("# Compilation de '{}'.", chemin_de_fichier); + debug::message_compilation(chemin_de_fichier); let debut = Instant::now(); if let Err(raison) = pendragon.compile(lecture.unwrap()) { eprintln!("\n{}", raison); - eprintln!("\n# Échec de la compilation."); + debug::message_compilation_echec(); return } - println!("# Compilation Ok. ({:.2?})\n", debut.elapsed()); + debug::message_compilation_ok(debut.elapsed()); if debug_mode { println!("{}\n", pendragon.programme); } - println!("# Exécution de '{}'.\n", chemin_de_fichier); + debug::message_execution(chemin_de_fichier); let debut = Instant::now(); if let Err(raison) = pendragon.programme.execute() { eprintln!("\nErreur : {}", raison); - eprintln!("\n# Échec de l'exécution."); + debug::message_execution_echec(); return } - - println!("\n# Exécution Ok. ({:.2?})", debut.elapsed()); + debug::message_execution_ok(debut.elapsed()); } diff --git a/src/pendragon/debug.rs b/src/pendragon/debug.rs index 5ac9f21..572f218 100644 --- a/src/pendragon/debug.rs +++ b/src/pendragon/debug.rs @@ -1,18 +1,54 @@ use std::fmt; +use std::time::Duration; use super::*; +pub const TEXTE_ROUGE: &str = "\x1b[31m"; +//pub const TEXTE_VERT: &str = "\x1b[32m"; +//pub const TEXTE_JAUNE: &str = "\x1b[33m"; +//pub const TEXTE_BLEU: &str = "\x1b[34m"; +pub const TEXTE_GRIS: &str = "\x1b[37m"; +pub const TEXTE_NORMAL: &str = "\x1b[0m"; + +pub fn message_compilation(chemin_de_fichier: &str) { + println!("# Compilation de '{}'.", chemin_de_fichier); +} + +pub fn message_compilation_echec() { + eprintln!("\n# Échec de la compilation."); +} + +pub fn message_compilation_ok(temps: Duration) { + println!("# Compilation Ok. ({:.2?})\n", temps); +} + +pub fn message_execution(chemin_de_fichier: &str) { + println!("# Exécution de '{}'.\n", chemin_de_fichier); +} + +pub fn message_execution_echec() { + eprintln!("\n# Échec de l'exécution."); +} + +pub fn message_execution_ok(temps: Duration) { + println!("\n# Exécution Ok. ({:.2?})", temps); +} + pub struct ErreurCompilation { index_ligne: usize, + ligne: String, erreur: ErreurPendragon, } impl ErreurCompilation { - pub fn nouvelle(index_ligne: usize, erreur: ErreurPendragon) -> Self { + pub fn nouvelle(index_ligne: usize, ligne: String, erreur: ErreurPendragon) -> Self { Self { index_ligne, + ligne, erreur, } } + + #[cfg(test)] pub fn raison(&self) -> ErreurPendragon { self.erreur.clone() } @@ -21,7 +57,7 @@ impl ErreurCompilation { impl fmt::Display for ErreurCompilation { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {//' - write!(f, "Erreur ligne {} : {}", self.index_ligne + 1, self.erreur) + write!(f, "{}Erreur :{} {}\n{}ligne {} : {}{}", TEXTE_ROUGE, TEXTE_NORMAL, self.erreur, TEXTE_GRIS, self.index_ligne + 1, self.ligne, TEXTE_NORMAL) } } diff --git a/src/pendragon/mod.rs b/src/pendragon/mod.rs index 7a05c99..0f3f5b4 100644 --- a/src/pendragon/mod.rs +++ b/src/pendragon/mod.rs @@ -28,7 +28,7 @@ impl Pendragon { continue }; if !derniere_phrase.ends_with('.') && !derniere_phrase.ends_with(',') { - return Err(ErreurCompilation::nouvelle(index_ligne, ErreurPendragon::ManquePonctuation)) + return Err(ErreurCompilation::nouvelle(index_ligne, ligne.into(), ErreurPendragon::ManquePonctuation)) } for phrase in phrases { if phrase.ends_with(".") { @@ -37,7 +37,7 @@ impl Pendragon { } match self.compile_commande(&phrase[..phrase.len() - 1]) { Ok(commande) => self.programme.ajoute_commande(commande), - Err(raison) => return Err(ErreurCompilation::nouvelle(index_ligne, raison)), + Err(raison) => return Err(ErreurCompilation::nouvelle(index_ligne, ligne.into(), raison)), } continue; } diff --git a/src/pendragon/texte.rs b/src/pendragon/texte.rs index b2d8e6a..ebc1288 100644 --- a/src/pendragon/texte.rs +++ b/src/pendragon/texte.rs @@ -42,7 +42,6 @@ impl Pendragon { expression.push(Element::Operateur(Operateur::Puis)); } expression.extend(self.puis(&expression, &pile_inconnu)?); - pile_inconnu = Vec::new(); expression.push(Element::Operateur(Operateur::Puis)); Ok(expression) } diff --git a/src/pendragon/vocabulaire.rs b/src/pendragon/vocabulaire.rs deleted file mode 100644 index 26e4b59..0000000 --- a/src/pendragon/vocabulaire.rs +++ /dev/null @@ -1,54 +0,0 @@ - - -pub enum MotCle { - Definis, - Modifie, - Affiche, - Demande, - Si, - Sinon, - NotaBene, - Plus, - Moins, - Fois, - Divise, - Et, - Ou, - Non, - OuvreParenthese, - FermeParenthese, - Puis, - Alinea, - RetourLigne, -} - -pub impl MotCle { - fn comme_texte(&self) -> String { - match Self { - Self::Definis, - Self::Modifie, - Self::Affiche, - Self::Demande, - Self::Si, - Self::Sinon, - Self::NotaBene, - Plus, - Moins, - Fois, - Divise, - Et, - Ou, - Non, - OuvreParenthese, - FermeParenthese, - Puis, - Alinea, - RetourLigne, - } - } - - fn depuis_texte(texte: &str) -> Self { - match texte { - - } - } \ No newline at end of file