devalang_core/core/preprocessor/
module.rs

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