mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
support class XXX: and class XXX():
This commit is contained in:
parent
908769ed0a
commit
71c3923f43
@ -1,5 +1,5 @@
|
||||
#api
|
||||
class PyObj(BaseObj):
|
||||
class PyObj:
|
||||
|
||||
def importClass(self, className: str, fp: str):
|
||||
pass
|
||||
@ -17,7 +17,7 @@ class PyObj(BaseObj):
|
||||
pass
|
||||
|
||||
|
||||
class PyMethod (SysObj):
|
||||
class PyMethod ( ):
|
||||
def makeMethodFun(fp: str):
|
||||
pass
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import PikaStdLib
|
||||
import PyInfo
|
||||
from pika_cjson import cJSON
|
||||
print('hello pikascript!')
|
||||
mem = PikaStdLib.MemChecker()
|
||||
|
@ -34,17 +34,25 @@ impl ClassInfo {
|
||||
pub fn new(file_name: &String, define: &String, is_package: bool) -> Option<ClassInfo> {
|
||||
let define = define.strip_prefix("class ").unwrap().to_string();
|
||||
let define = define.replace(" ", "");
|
||||
let super_class_name = match my_string::cut(&define, '(', ')') {
|
||||
let mut super_class_name = match my_string::cut(&define, '(', ')') {
|
||||
Some(s) => s,
|
||||
None => return None,
|
||||
None => "TinyObj".to_string(),
|
||||
};
|
||||
if super_class_name == "" {
|
||||
super_class_name = "TinyObj".to_string();
|
||||
}
|
||||
let super_class_name = match super_class_name.find(".") {
|
||||
None => ClassInfo::add_file_profix(&file_name, &super_class_name, is_package),
|
||||
Some(_x) => super_class_name.replace(".", "_"),
|
||||
};
|
||||
let mut this_calss_name = match my_string::get_first_token(&define, '(') {
|
||||
Some(s) => s,
|
||||
None => return None,
|
||||
None => match my_string::get_first_token(&define, ':') {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
return None;
|
||||
}
|
||||
},
|
||||
};
|
||||
let this_class_name_without_file = this_calss_name.clone();
|
||||
this_calss_name = ClassInfo::add_file_profix(&file_name, &this_calss_name, is_package);
|
||||
|
@ -84,7 +84,7 @@ impl Compiler {
|
||||
|
||||
let package_obj_define = format!("{} = {}()", package_name, package_name);
|
||||
class_now.push_object(package_obj_define, &file_name);
|
||||
return Compiler::__do_analyse_file(compiler, package_name.to_string(), true);
|
||||
return Compiler::analyse_top_package(compiler, package_name.to_string());
|
||||
}
|
||||
class_now.script_list.add(&line);
|
||||
return compiler;
|
||||
@ -197,13 +197,13 @@ impl Compiler {
|
||||
if file_name == "main" {
|
||||
self = Compiler::analyse_main_line(self, &line);
|
||||
} else {
|
||||
self = Compiler::analyse_line(self, line.to_string(), &file_name, is_top_pkg);
|
||||
self = Compiler::analyse_pyi_line(self, line.to_string(), &file_name, is_top_pkg);
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn analyse_line(
|
||||
pub fn analyse_pyi_line(
|
||||
mut compiler: Compiler,
|
||||
line: String,
|
||||
file_name: &String,
|
||||
@ -212,7 +212,7 @@ impl Compiler {
|
||||
if line.starts_with("import ") {
|
||||
let tokens: Vec<&str> = line.split(" ").collect();
|
||||
let file = tokens[1];
|
||||
return Compiler::__do_analyse_file(compiler, file.to_string(), false);
|
||||
return Compiler::analyse_inner_package(compiler, file.to_string());
|
||||
}
|
||||
|
||||
if line.starts_with("#") {
|
||||
@ -299,19 +299,19 @@ mod tests {
|
||||
#[test]
|
||||
fn test_analyse() {
|
||||
let compiler = Compiler::new(String::from(""), String::from(""));
|
||||
let compiler = Compiler::analyse_line(
|
||||
let compiler = Compiler::analyse_pyi_line(
|
||||
compiler,
|
||||
String::from("class Test(SuperTest):"),
|
||||
&"Pkg".to_string(),
|
||||
false,
|
||||
);
|
||||
let compiler = Compiler::analyse_line(
|
||||
let compiler = Compiler::analyse_pyi_line(
|
||||
compiler,
|
||||
String::from(" def test()"),
|
||||
&"Pkg".to_string(),
|
||||
false,
|
||||
);
|
||||
let compiler = Compiler::analyse_line(
|
||||
let compiler = Compiler::analyse_pyi_line(
|
||||
compiler,
|
||||
String::from(" testObj = TestObj()"),
|
||||
&"Pkg".to_string(),
|
||||
|
@ -15,17 +15,18 @@ pub fn pika_compiler_entry() {
|
||||
let mut compiler = Compiler::new(String::from(""), String::from("pikascript-api/"));
|
||||
|
||||
/* analyse file begin with main.py */
|
||||
compiler = Compiler::analyse_inner_package(compiler, String::from("main"));
|
||||
compiler = Compiler::analyse_top_package(compiler, String::from("main"));
|
||||
/*
|
||||
Compile packages in requestment.txt, solve the packages
|
||||
as the top packages.
|
||||
*/
|
||||
for package in &version_info.package_list {
|
||||
let package_name = package.0;
|
||||
/* skip pikascript-core */
|
||||
if package.0 == "pikascript-core" {
|
||||
if package_name == "pikascript-core" {
|
||||
continue;
|
||||
}
|
||||
compiler = Compiler::analyse_top_package(compiler, String::from(package.0));
|
||||
compiler = Compiler::analyse_top_package(compiler, String::from(package_name));
|
||||
}
|
||||
|
||||
/* Compile packages in PikaStdLib */
|
||||
|
Loading…
x
Reference in New Issue
Block a user