Skip to main content

oak_ada/ast/
mod.rs

1#![doc = include_str!("readme.md")]
2/// Root node of the Ada syntax tree.
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct AdaRoot {
5    /// Items in this Ada file.
6    pub items: Vec<AdaItem>,
7}
8
9impl AdaRoot {
10    /// Creates a new Ada root node.
11    pub fn new(items: Vec<AdaItem>) -> Self {
12        Self { items }
13    }
14
15    /// Gets all top-level items in this Ada file.
16    pub fn items(&self) -> &[AdaItem] {
17        &self.items
18    }
19}
20
21/// Item in an Ada file (package, procedure, function, etc.).
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub enum AdaItem {
24    /// Package declaration.
25    Package(AdaPackage),
26    /// Procedure declaration.
27    Procedure(AdaProcedure),
28    /// Function declaration.
29    Function(AdaFunction),
30    /// Type declaration.
31    Type(AdaTypeDeclaration),
32    /// Variable declaration.
33    Variable(AdaVariableDeclaration),
34}
35
36/// Ada package declaration.
37#[derive(Debug, Clone, PartialEq, Eq)]
38pub struct AdaPackage {
39    /// Package name.
40    pub name: String,
41}
42
43impl AdaPackage {
44    /// Creates a new package declaration.
45    pub fn new(name: String) -> Self {
46        Self { name }
47    }
48}
49
50/// Ada procedure declaration.
51#[derive(Debug, Clone, PartialEq, Eq)]
52pub struct AdaProcedure {
53    /// Procedure name.
54    pub name: String,
55    /// Parameter list.
56    pub parameters: Vec<AdaParameter>,
57}
58
59impl AdaProcedure {
60    /// Creates a new procedure declaration.
61    pub fn new(name: String, parameters: Vec<AdaParameter>) -> Self {
62        Self { name, parameters }
63    }
64}
65
66/// Ada function declaration.
67#[derive(Debug, Clone, PartialEq, Eq)]
68pub struct AdaFunction {
69    /// Function name.
70    pub name: String,
71    /// Parameter list.
72    pub parameters: Vec<AdaParameter>,
73    /// Return type.
74    pub return_type: String,
75}
76
77impl AdaFunction {
78    /// Creates a new function declaration.
79    pub fn new(name: String, parameters: Vec<AdaParameter>, return_type: String) -> Self {
80        Self { name, parameters, return_type }
81    }
82}
83
84/// Ada parameter.
85#[derive(Debug, Clone, PartialEq, Eq)]
86pub struct AdaParameter {
87    /// Parameter name.
88    pub name: String,
89    /// Parameter type.
90    pub param_type: String,
91}
92
93impl AdaParameter {
94    /// Creates a new parameter.
95    pub fn new(name: String, param_type: String) -> Self {
96        Self { name, param_type }
97    }
98}
99
100/// Ada type declaration.
101#[derive(Debug, Clone, PartialEq, Eq)]
102pub struct AdaTypeDeclaration {
103    /// Type name.
104    pub name: String,
105    /// Type definition.
106    pub type_def: String,
107}
108
109impl AdaTypeDeclaration {
110    /// Creates a new type declaration.
111    pub fn new(name: String, type_def: String) -> Self {
112        Self { name, type_def }
113    }
114}
115
116/// Ada variable declaration.
117#[derive(Debug, Clone, PartialEq, Eq)]
118pub struct AdaVariableDeclaration {
119    /// Variable name.
120    pub name: String,
121    /// Variable type.
122    pub var_type: String,
123}
124
125impl AdaVariableDeclaration {
126    pub fn new(name: String, var_type: String) -> Self {
127        Self { name, var_type }
128    }
129}
130
131impl Default for AdaRoot {
132    fn default() -> Self {
133        Self::new(Vec::new())
134    }
135}