From da52af342b3d40e91ddd93905ced5c5f8586b20c Mon Sep 17 00:00:00 2001 From: primardj Date: Thu, 11 Jan 2024 00:09:40 +0000 Subject: [PATCH] =?UTF-8?q?creation=20de=20la=20structure=20Entree=20et=20?= =?UTF-8?q?de=20la=20structure=20Structure.=20Une=20entr=C3=A9e=20contient?= =?UTF-8?q?=20une=20liste=20de=20structure.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser.rs | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 97a4bf6..a670af4 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,3 +1,78 @@ + +// Definition des structures utilisés par le parseur. +// s'utilise par l'appel de la fonction static parse, qui prends en param une ligne de commande +// (Vect) et qui renvois une Entree. + +struct Structure { + /* + * Il y à 5 types de structs differentes. + * - commande + * - control + * - 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, + contents: Vec, +} + +impl Structure { + fn new_commande(cont: Vec) -> Self { + Self { + name: String::from("commande"), + contents: cont, + } + } + fn new_control(cont: Vec) -> Self { + Self { + name: String::from("control"), + contents: cont, + } + } +} + +struct Entree { + /* + * Correspond à une entrée. C'est ce que renvois le parser. + */ + size: i32, + inputs: Vec, +} + +impl Entree { + fn new() -> Self { + Self { + size: 0, + inputs: Vec::new(), + } + } +} + + fn parse_after_whitespace(char_splitted_command_line: &mut Vec, argv: &mut Vec) -> Vec { let current_char_option = char_splitted_command_line.pop();