2024-12-06 14:59:59 +01:00
|
|
|
use std::env;
|
|
|
|
use std::fs;
|
2024-12-06 23:43:35 +01:00
|
|
|
|
2024-12-09 13:19:00 +01:00
|
|
|
mod pendragon;
|
|
|
|
use pendragon::*;
|
2024-12-08 15:45:49 +01:00
|
|
|
|
2024-12-07 10:43:48 +01:00
|
|
|
fn main() {
|
|
|
|
let arguments: Vec<String> = env::args().collect();
|
|
|
|
|
|
|
|
if arguments.len() < 2 {
|
2024-12-09 13:19:00 +01:00
|
|
|
eprintln!("Utilisation : pendragon <FILE>");
|
2024-12-07 10:43:48 +01:00
|
|
|
return
|
|
|
|
}
|
2024-12-10 13:24:36 +01:00
|
|
|
|
|
|
|
let debug_mode = arguments.contains(&"--debug".to_string());
|
2024-12-07 10:43:48 +01:00
|
|
|
|
|
|
|
let chemin_de_fichier = &arguments[1];
|
2024-12-10 13:24:36 +01:00
|
|
|
let mut pendragon = Pendragon::nouveau();
|
2024-12-07 10:43:48 +01:00
|
|
|
|
|
|
|
match fs::read_to_string(chemin_de_fichier) {
|
|
|
|
Ok(contenu) => {
|
2024-12-10 13:24:36 +01:00
|
|
|
let Ok(_) = pendragon.compile(contenu) else {
|
|
|
|
eprintln!("Compilation interrompue");
|
|
|
|
return
|
|
|
|
};
|
|
|
|
if debug_mode {
|
|
|
|
println!("{}\n-----------", pendragon.programme);
|
|
|
|
}
|
|
|
|
if let Err(raison) = pendragon.programme.execute() {
|
|
|
|
eprintln!("Erreur Execution : {}", raison);
|
|
|
|
return
|
|
|
|
}
|
|
|
|
println!("\n# Success");
|
2024-12-07 10:43:48 +01:00
|
|
|
}
|
|
|
|
Err(raison) => {
|
|
|
|
eprintln!("Fichier illisible : {}", raison);
|
|
|
|
}
|
|
|
|
}
|
2024-12-06 23:43:35 +01:00
|
|
|
}
|