From 19ec0dcf366dd66bffdc1c73df7a8be2ab69d78f Mon Sep 17 00:00:00 2001 From: WanderingPenwing Date: Wed, 11 Dec 2024 14:58:26 +0100 Subject: [PATCH] nice ui --- pendragon.project | 2 +- src/main.rs | 3 +-- src/pendragon/mod.rs | 10 ++++++---- src/pendragon/structure.rs | 4 ++++ test.dr | 8 +++----- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pendragon.project b/pendragon.project index 7181274..2550450 100644 --- a/pendragon.project +++ b/pendragon.project @@ -1 +1 @@ -{"categories":[{"name":"todo","content":[{"name":"booleen type","description":"// Hello there","id":4},{"name":"if","description":"implémente if avec des guillemets de délimitation","id":1},{"name":"while","description":"implémente un while","id":2},{"name":"compilation","description":"// Hello there","id":3},{"name":"soixante-dix","description":"// Hello there","id":1}]},{"name":"in progress","content":[]},{"name":"done","content":[]},{"name":"bug","content":[]},{"name":"to test","content":[]},{"name":"+","content":[]}]} \ No newline at end of file +{"categories":[{"name":"todo","content":[{"name":"commentaires","description":"// Hello there","id":3},{"name":"compile time verification","description":"odre des termes rpn","id":1},{"name":"error context","description":"// Hello there","id":2},{"name":"test correct error","description":"// Hello there","id":3},{"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":"bug","content":[]},{"name":"to test","content":[]},{"name":"bonus","content":[{"name":"stop cheating with \"-\"","description":"// Hello there","id":5}]},{"name":"+","content":[]}]} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 04ad141..73e3ab0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,13 +24,12 @@ fn main() { return }; if debug_mode { - println!("{}\n-----------", pendragon.programme); + println!("{}\n", pendragon.programme); } if let Err(raison) = pendragon.programme.execute() { eprintln!("Erreur Execution : {}", raison); return } - println!("\n# Success"); } Err(raison) => { eprintln!("Fichier illisible : {}", raison); diff --git a/src/pendragon/mod.rs b/src/pendragon/mod.rs index 68f69f7..fb5a89a 100644 --- a/src/pendragon/mod.rs +++ b/src/pendragon/mod.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::time::Instant; pub mod nombre; pub mod texte; @@ -8,9 +9,6 @@ use structure::*; pub mod debug; use debug::*; -//#[cfg(test)] -//mod tests; - pub struct Pendragon { pub programme: Programme, } @@ -23,7 +21,9 @@ impl Pendragon { } pub fn compile(&mut self, contenu: String) -> Result<(), ErreurPendragon> { - let contenu_propre = contenu.replace("\n", ""); + println!(); + let debut = Instant::now(); + let contenu_propre = contenu.replace("\n", " "); let mut texte: Vec<&str> = contenu_propre.split('.').collect(); let reste = texte.pop(); if reste != Some("") { @@ -31,6 +31,7 @@ impl Pendragon { return Err(ErreurPendragon::ManquePoint) } for (index_phrase, phrase) in texte.iter().enumerate() { + let phrase = phrase.trim(); match self.compile_phrase(phrase) { Ok(commande) => {self.programme.ajoute_commande(commande)}, Err(raison) => { @@ -39,6 +40,7 @@ impl Pendragon { } } } + println!("# Compilation Ok. ({:.2?})\n", debut.elapsed()); Ok(()) } diff --git a/src/pendragon/structure.rs b/src/pendragon/structure.rs index e909280..ff9af12 100644 --- a/src/pendragon/structure.rs +++ b/src/pendragon/structure.rs @@ -1,5 +1,6 @@ use std::io; use std::collections::HashMap; +use std::time::Instant; use super::*; @@ -53,6 +54,8 @@ impl Programme { } pub fn execute(&self) -> Result<(), ErreurPendragon> { + let debut = Instant::now(); + println!("# Execution...\n"); let mut variables_globales: HashMap = HashMap::new(); for commande in &self.commandes { match commande { @@ -76,6 +79,7 @@ impl Programme { } } } + println!("\n# Exécution Ok. ({:.2?})", debut.elapsed()); Ok(()) } } diff --git a/test.dr b/test.dr index 0f33650..85bb0e2 100644 --- a/test.dr +++ b/test.dr @@ -1,5 +1,3 @@ -Définis A comme entier. -Modifie A avec dix-huit. -Définis B comme booléen. -Modifie B avec non faux et ouvre la parenthèse trois-mille-un divisé par A est supérieur ou égal à sept ou faux ferme la parenthèse. -Affiche B. \ No newline at end of file +Affiche soixante-dix. +Affiche soixante-et-onze. +Affiche vrai et ouvre la parenthèse six plus un est supérieur à ouvre la parenthèse deux fois deux ferme la parenthèse ferme la parenthèse. \ No newline at end of file