39 lines
1.2 KiB
Rust
39 lines
1.2 KiB
Rust
use crate::parsing::parser::parsed_statement::{ParsedStatement, ParsedStatementData};
|
|
use crate::types::script_type::ScriptType;
|
|
use crate::types::script_type_namespace::ScriptTypeNamespace;
|
|
use crate::types::type_library::TypeLibrary;
|
|
|
|
pub fn register_types(statement: &ParsedStatement) -> TypeLibrary {
|
|
let mut library = TypeLibrary::new();
|
|
library = find_types_in_statement(statement, library, None);
|
|
|
|
library
|
|
}
|
|
|
|
fn find_types_in_statement(
|
|
statement: &ParsedStatement,
|
|
mut library: TypeLibrary,
|
|
active_namespace: Option<ScriptTypeNamespace>,
|
|
) -> TypeLibrary {
|
|
match &statement.data {
|
|
ParsedStatementData::Script { statements } => {
|
|
for statement in statements {
|
|
library = find_types_in_statement(statement.as_ref(), library, None);
|
|
}
|
|
}
|
|
ParsedStatementData::ClassDeclaration { name, .. } => {
|
|
let script_type = ScriptType::new();
|
|
|
|
if let Some(mut ns) = active_namespace {
|
|
ns.register(name, script_type);
|
|
} else {
|
|
library
|
|
.get_global_namespace_mut()
|
|
.register(name, script_type);
|
|
};
|
|
}
|
|
_ => {}
|
|
}
|
|
library
|
|
}
|