Skip to main content

iso_10303/express/
declaration.rs

1use super::{DataType, Expression};
2
3#[derive(Debug)]
4pub enum Declaration {
5    TypeDef(TypeDef),
6    Entity(Entity),
7    Function(Function),
8    Rule(Rule),
9}
10
11#[derive(Debug)]
12pub struct TypeDef {
13    pub name: String,
14    pub underlying_type: DataType,
15    pub domain_rules: Vec<DomainRule>,
16}
17
18#[derive(Debug)]
19pub struct Entity {
20    pub name: String,
21    pub is_abstract: bool,
22    pub supertypes: Vec<String>,
23    pub attributes: Vec<Attribute>,
24    pub derives: Vec<DerivedAttribute>,
25    pub domain_rules: Vec<DomainRule>,
26    pub unique_rules: Vec<UniqueRule>,
27}
28
29#[derive(Debug)]
30pub struct Function {
31    pub name: String,
32    pub return_type: DataType,
33    pub parameters: Vec<Parameter>,
34    pub statements: Vec<Statement>,
35    pub declarations: Vec<Declaration>,
36}
37
38#[derive(Debug)]
39pub struct Rule {
40    pub name: String,
41    pub entities: Vec<String>,
42    pub statements: Vec<Statement>,
43    pub domain_rules: Vec<DomainRule>,
44    pub declarations: Vec<Declaration>,
45}
46
47#[derive(Debug, Clone)]
48pub struct Attribute {
49    pub name: String,
50    pub supertype: Option<String>,
51    pub data_type: DataType,
52    pub optional: bool,
53}
54
55#[derive(Debug)]
56pub struct DerivedAttribute {
57    pub name: String,
58    pub supertype: Option<String>,
59    pub data_type: DataType,
60    pub expr: Expression,
61}
62
63#[derive(Debug)]
64pub struct AttributeReference {
65    pub name: String,
66    pub entity: Option<String>,
67}
68
69#[derive(Debug)]
70pub struct DomainRule {
71    pub label: Option<String>,
72    pub expr: Expression,
73}
74
75#[derive(Debug)]
76pub struct UniqueRule {
77    pub label: Option<String>,
78    pub attributes: Vec<AttributeReference>,
79}
80
81#[derive(Debug)]
82pub struct Parameter {
83    pub name: String,
84    pub data_type: DataType,
85}
86
87#[derive(Debug)]
88pub struct Constant {
89    pub name: String,
90    pub data_type: DataType,
91    pub expr: Expression,
92}
93
94#[derive(Debug)]
95pub struct Statement {
96    pub text: String,
97}
98
99impl Declaration {
100    pub fn is_type_def(&self) -> bool {
101        match self {
102            Declaration::TypeDef(_) => true,
103            _ => false,
104        }
105    }
106}
107
108impl Entity {
109    pub fn get_attribute(&self, name: &str) -> Option<&Attribute> {
110        for attribute in &self.attributes {
111            if attribute.name == name {
112                return Some(attribute);
113            }
114        }
115        return None;
116    }
117}