donet_core/parser/generation.rs
1/*
2 This file is part of Donet.
3
4 Copyright © 2025 Max Rodriguez
5
6 Donet is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Affero General Public License,
8 as published by the Free Software Foundation, either version 3
9 of the License, or (at your option) any later version.
10
11 Donet is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with Donet. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20use super::ast;
21use super::error::DCReadError;
22use super::pipeline::PipelineData;
23use crate::dcfile;
24use anyhow::Result;
25
26/// Last step of the DC parser pipeline. Generates the final immutable DC element tree
27/// data structure for usage by Donet clients and Donet server services.
28///
29pub fn dc_tree_generation(pipeline: &mut PipelineData) -> dcfile::DCFile {
30 // tell the pipeline we are moving onto the next stage
31 pipeline.next_stage();
32
33 let mut tree: dcfile::DCFile = dcfile::DCFile {
34 imports: vec![],
35 type_defs: vec![],
36 keywords: vec![],
37 structs: vec![],
38 dclasses: vec![],
39 all_object_valid: true,
40 inherited_fields_stale: false,
41 };
42
43 // Iterate through all ASTs and add them to our final DC element tree.
44 for ast in pipeline.syntax_trees.clone() {
45 for type_declaration in ast.type_declarations.iter() {
46 match type_declaration {
47 ast::TypeDeclaration::PythonImport(import) => {
48 tree.imports.extend(dcfile::generation::add_python_import(import));
49 }
50 ast::TypeDeclaration::KeywordType(_keyword) => {
51 // TODO
52 }
53 ast::TypeDeclaration::StructType(_strukt) => {
54 // TODO
55 }
56 ast::TypeDeclaration::DClassType(_dclass) => {
57 // TODO
58 }
59 ast::TypeDeclaration::TypedefType(_typedef) => {
60 // TODO
61 }
62 }
63 }
64 pipeline.next_file(); // tell the pipeline we are processing the next file
65 }
66 tree
67}