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