From f3491fb333e22f8ef8f85d6cce3e1f41878d7caa Mon Sep 17 00:00:00 2001 From: primardj Date: Thu, 11 Jan 2024 19:33:27 +0000 Subject: [PATCH] =?UTF-8?q?mise=20en=20place=20correctement=20des=20comman?= =?UTF-8?q?taires,=20et=20permi=C3=A8re=20version=20des=20objets=20Structu?= =?UTF-8?q?re=20et=20Entree.=20Plus=20qu'as=20modifier=20parser.rs=20et=20?= =?UTF-8?q?buffer.rs=20pour=20les=20tester?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser.rs | 81 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 24 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index a670af4..fc5373e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -11,29 +11,6 @@ struct Structure { * - def variable * - def function * - pipes - * - * Cas 1; commande - * name: "commande" - * contents: ["nom commande", "parametter", "arg1", ...] - * - * Cas 2; control - * name: "control" - * contents: ["if|elif|else|while|for", "condition", "liste String avec (faudra la reparser - * quand on tomberas dessus pour obtenir son objet de classe Entree) "] - * - * Cas 3; def variable - * name: "variable" - * contents: ["type [string|list]", "name", "value"] - * - * Cas 4; def function - * name: "function" - * contents: ["name", "nb parametter", "param1", ..., "liste String interieur fonction(faudra - * la repasser quand on tomberas dessus pour obtenir son objet de classe Entree)"] - * - * Cas 5; pipes - * name: "pipe" - * contents: ["String Commande1 (faudra la repasser dans le parser)", "String Commande2(tout - * le reste du pipe faudra le repasser dans le parser)"] */ name: String, @@ -41,18 +18,68 @@ struct Structure { } impl Structure { + /* + * name: "commande" + * contents: ["nom commande", "parametter", "arg1", ...] + * + * parametter define if the command is in background or not. For now, parametter can only be + * either "" or "&" + */ fn new_commande(cont: Vec) -> Self { Self { name: String::from("commande"), contents: cont, } } + /* + * name: "control" + * contents: ["if|elif|else|while|for", "condition", "liste String avec (faudra la reparser + * quand on tomberas dessus pour obtenir son objet de classe Entree) "] + */ fn new_control(cont: Vec) -> Self { Self { name: String::from("control"), contents: cont, } } + /* + * name: "variable" + * contents: ["type [string|list]","parametter", "name", "value"] + * + * parametter says if the variable is to export or not. right now it's either "" or "export" + */ + fn new_variable(cont: Vec) -> Self { + Self { + name: String::from("variable"), + contents: cont, + } + } + /* + * name: "function" + * contents: ["name", "nb parametter", "param1", ..., "liste String interieur fonction(faudra + * la repasser quand on tomberas dessus pour obtenir son objet de classe Entree)"] + */ + fn new_function(cont: Vec) -> Self { + Self { + name: String::from("variable"), + contents: cont, + } + } + /* + * name: "pipe" + * contents: ["String Commande1 (faudra la repasser dans le parser)", "String Commande2(tout + * le reste du pipe faudra le repasser dans le parser)"] + */ + fn new_pipe(cont: Vec) -> Self { + Self { + name: String::from("pipe"), + contents: cont, + } + } + fn get_name(&self) -> &String { + &self.name + } + } struct Entree { @@ -64,12 +91,18 @@ struct Entree { } impl Entree { - fn new() -> Self { + pub fn new() -> Self { Self { size: 0, inputs: Vec::new(), } } + + pub fn add_structure(&mut self, structure: Structure) -> i8 { + self.inputs.push(structure); + 0 + } + }