devalang_core/core/preprocessor/
module.rs1use crate::core::{lexer::token::Token, parser::statement::Statement};
2use devalang_types::{ExportTable, FunctionTable, ImportTable, VariableTable};
3
4#[derive(Debug, Clone)]
5pub struct Module {
6 pub path: String,
7 pub resolved: bool,
8 pub tokens: Vec<Token>,
9 pub statements: Vec<Statement>,
10 pub variable_table: VariableTable,
11 pub function_table: FunctionTable,
12 pub export_table: ExportTable,
13 pub import_table: ImportTable,
14 pub content: String,
15 pub current_dir: String,
16}
17
18impl Module {
19 pub fn new(path: &str) -> Self {
20 Module {
21 path: path.to_string(),
22 tokens: Vec::new(),
23 statements: Vec::new(),
24 variable_table: VariableTable::new(),
25 function_table: FunctionTable::new(),
26 export_table: ExportTable::new(),
27 import_table: ImportTable::new(),
28 resolved: false,
29 content: String::new(),
30 current_dir: String::new(),
31 }
32 }
33
34 pub fn is_resolved(&self) -> bool {
35 self.resolved
36 }
37
38 pub fn set_resolved(&mut self, resolved: bool) {
39 self.resolved = resolved;
40 }
41
42 pub fn add_token(&mut self, token: Token) {
43 self.tokens.push(token);
44 }
45
46 pub fn add_statement(&mut self, statement: Statement) {
47 self.statements.push(statement);
48 }
49
50 pub fn from_existing(path: &str, content: String) -> Self {
51 let mut module = Module::new(path);
52 module.content = content;
53 module
54 }
55}