create folder objects to contains Structure and Entree
This commit is contained in:
parent
a09c5024e7
commit
d1d31a7d15
5 changed files with 132 additions and 113 deletions
|
@ -3,6 +3,7 @@ mod parser;
|
|||
mod job;
|
||||
mod variables;
|
||||
mod error;
|
||||
mod objects;
|
||||
|
||||
use std::process::exit;
|
||||
use variables::Variables;
|
||||
|
|
28
src/objects/entree.rs
Normal file
28
src/objects/entree.rs
Normal 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
3
src/objects/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
pub mod structure;
|
||||
pub mod entree;
|
91
src/objects/structure.rs
Normal file
91
src/objects/structure.rs
Normal 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
|
||||
}
|
||||
|
||||
}
|
122
src/parser.rs
122
src/parser.rs
|
@ -1,118 +1,9 @@
|
|||
|
||||
// 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.
|
||||
// This is the parser. It can be called by two commands:
|
||||
// parse(command_line: &String) -> Vec<String>
|
||||
// parse2(command_line: &String) -> 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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
use crate::objects::entree::Entree;
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// Up to this line is the old version parser.
|
||||
|
||||
|
||||
|
||||
|
||||
pub fn parse2(command_line: &String) -> Entree {
|
||||
// prends en paramettre un ligne de commande, et retourne une Entree.
|
||||
let mut jaaj: Entree = Entree::new();
|
||||
|
|
Reference in a new issue