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 + } + }