create folder objects to contains Structure and Entree

This commit is contained in:
primardj 2024-01-14 17:54:27 +00:00
parent a09c5024e7
commit d1d31a7d15
5 changed files with 132 additions and 113 deletions

View file

@ -3,6 +3,7 @@ mod parser;
mod job; mod job;
mod variables; mod variables;
mod error; mod error;
mod objects;
use std::process::exit; use std::process::exit;
use variables::Variables; use variables::Variables;

28
src/objects/entree.rs Normal file
View file

@ -0,0 +1,28 @@
use crate::objects::structure::Structure;
// Définition de l'objet Entree, utilise un object Structure.
pub struct Entree {
/*
* Correspond à une entrée. C'est ce que renvois le parser.
*/
size: i32,
inputs: Vec<Structure>,
}
impl Entree {
pub fn new() -> Self {
Self {
size: 0,
inputs: Vec::new(),
}
}
pub fn add_structure(&mut self, structure: Structure) -> i8 {
self.inputs.push(structure);
self.size +=1;
0
}
}

3
src/objects/mod.rs Normal file
View file

@ -0,0 +1,3 @@
pub mod structure;
pub mod entree;

91
src/objects/structure.rs Normal file
View file

@ -0,0 +1,91 @@
// 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<String>) et qui renvois une Entree.
pub struct Structure {
/*
* Il y à 5 types de structs differentes.
* - commande
* - control
* - def variable
* - def function
* - pipes
*/
name: String,
contents: Vec<String>,
}
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<String>) -> 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<String>) -> 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<String>) -> 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<String>) -> 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<String>) -> Self {
Self {
name: String::from("pipe"),
contents: cont,
}
}
pub fn get_name(&self) -> &String {
&self.name
}
pub fn get_contents(&self) -> &Vec<String> {
&self.contents
}
fn add_to_contents(&mut self, word: &String) -> &Self {
let _ = &self.contents.push(word.to_string());
self
}
}

View file

@ -1,118 +1,9 @@
// Definition des structures utilisés par le parseur. // This is the parser. It can be called by two commands:
// s'utilise par l'appel de la fonction static parse, qui prends en param une ligne de commande // parse(command_line: &String) -> Vec<String>
// (Vect<String>) et qui renvois une Entree. // parse2(command_line: &String) -> Entree
pub struct Structure { use crate::objects::entree::Entree;
/*
* Il y à 5 types de structs differentes.
* - commande
* - control
* - def variable
* - def function
* - pipes
*/
name: String,
contents: Vec<String>,
}
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<String>) -> 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<String>) -> 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<String>) -> 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<String>) -> 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<String>) -> Self {
Self {
name: String::from("pipe"),
contents: cont,
}
}
pub fn get_name(&self) -> &String {
&self.name
}
pub fn get_contents(&self) -> &Vec<String> {
&self.contents
}
fn add_to_contents(&mut self, word: &String) -> &Self {
let _ = &self.contents.push(word.to_string());
self
}
}
pub struct Entree {
/*
* Correspond à une entrée. C'est ce que renvois le parser.
*/
size: i32,
inputs: Vec<Structure>,
}
impl Entree {
pub fn new() -> Self {
Self {
size: 0,
inputs: Vec::new(),
}
}
pub fn add_structure(&mut self, structure: Structure) -> i8 {
self.inputs.push(structure);
self.size +=1;
0
}
}
fn parse_after_whitespace(char_splitted_command_line: &mut Vec<char>, argv: &mut Vec<String>) -> Vec<String> { fn parse_after_whitespace(char_splitted_command_line: &mut Vec<char>, argv: &mut Vec<String>) -> Vec<String> {
@ -163,6 +54,11 @@ pub fn parse(command_line: &String) -> Vec<String> {
argv argv
} }
// Up to this line is the old version parser.
pub fn parse2(command_line: &String) -> Entree { pub fn parse2(command_line: &String) -> Entree {
// prends en paramettre un ligne de commande, et retourne une Entree. // prends en paramettre un ligne de commande, et retourne une Entree.
let mut jaaj: Entree = Entree::new(); let mut jaaj: Entree = Entree::new();