update info output

This commit is contained in:
lyon 2022-01-31 00:29:05 +08:00
parent 041e924967
commit 250a35025e
3 changed files with 21 additions and 5 deletions

View File

@ -56,7 +56,7 @@ impl Compiler {
pub fn analyze_file(mut compiler: Compiler, file_name: String, is_top_pkg: bool) -> Compiler {
println!(
"(PikaScript) compiling {}{}.py...",
" compiling {}{}.py...",
compiler.source_path, file_name
);
let file = File::open(format!("{}{}.py", compiler.source_path, file_name));

View File

@ -15,13 +15,16 @@ use std::io::prelude::*;
use version_info::*;
fn main() {
/* new a version_info object */
println!("(PikaScript) packages installed:");
let mut version_info = VersionInfo::new();
version_info = VersionInfo::analyze_file(version_info, String::from("requestment.txt"));
println!("(PikaScript) pika compiler:");
/* new a compiler, sellect to path */
let mut compiler = Compiler::new(String::from(""), String::from("pikascript-api/"));
/* analyze file begin with main.py */
compiler = Compiler::analyze_file(compiler, String::from("main"), false);
/* new a version_info object */
let mut version_info = VersionInfo::new();
version_info = VersionInfo::analyze_file(version_info, String::from("requestment.txt"));
/* write the infomatrion to compiler-info */
let mut compiler_info_file =
File::create(format!("{}compiler-info.txt", compiler.dist_path)).unwrap();

View File

@ -18,16 +18,29 @@ impl VersionInfo {
return version_info;
}
fn analyze_line(mut self, line: String) -> VersionInfo {
println!(" {}", line.as_str());
return self;
}
pub fn analyze_file(mut self, source_path: String) -> VersionInfo {
self.source_path = source_path;
let file = File::open(&self.source_path);
let mut file = match file {
Ok(file) => file,
Err(_) => {
println!("(PikaScript) requestment.txt no found.");
println!("(PikaScript) 'requestment.txt' no found.");
return self;
}
};
/* solve lines in file */
let mut file_str = String::new();
file.read_to_string(&mut file_str).unwrap();
let lines: Vec<&str> = file_str.split('\n').collect();
/* analyze each line of pikascript-api.py */
for line in lines.iter() {
self = VersionInfo::analyze_line(self, line.to_string());
}
return self;
}
}