solve import in main.py as new_package_Obj

This commit is contained in:
lyon1998 2021-10-18 10:23:54 +08:00
parent 4034383f13
commit cf480c2b85
2 changed files with 8 additions and 5 deletions

View File

@ -21,7 +21,7 @@ impl Compiler {
};
return compiler;
}
pub fn analyze_main_line(mut compiler: Compiler, line: String) -> Compiler {
pub fn analyze_main_line(mut compiler: Compiler, line: &String) -> Compiler {
let file_name = "main".to_string();
let class_name = "PikaMain".to_string();
let class_now = match compiler.class_list.get_mut(&"PikaMain".to_string()) {
@ -39,6 +39,9 @@ impl Compiler {
if line.starts_with("from ") {
return compiler;
}
if line.starts_with("import ") {
return compiler;
}
class_now.script_list.add(&line);
return compiler;
}
@ -58,6 +61,10 @@ impl Compiler {
pub fn analyze_line(mut compiler: Compiler, line: String, file_name: &String) -> Compiler {
let line = line.replace("\r", "");
if file_name == "main" {
compiler = Compiler::analyze_main_line(compiler, &line);
}
if line.starts_with("import ") {
let tokens: Vec<&str> = line.split(" ").collect();
let file = tokens[1];
@ -91,10 +98,6 @@ impl Compiler {
return compiler;
}
if file_name == "main" {
return Compiler::analyze_main_line(compiler, line);
}
if line.starts_with(" ")
&& line.contains("(")
&& line.contains(")")