Skip to main content

sysml_v2_parser/ast/
view.rs

1use super::behavior::InOutDecl;
2use super::common::FilterMember;
3use super::common::{ConnectBody, DocComment, Identification, ParseErrorNode};
4use super::requirement::RequirementDefBody;
5use crate::ast::core::{Expression, Node, Span};
6
7/// Constraint definition: `constraint def` Identification body.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct ConstraintDef {
10    pub identification: Identification,
11    pub specializes: Option<String>,
12    pub specializes_span: Option<Span>,
13    pub body: ConstraintDefBody,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq)]
17pub enum ConstraintDefBody {
18    Semicolon,
19    Brace {
20        elements: Vec<Node<ConstraintDefBodyElement>>,
21    },
22}
23
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub enum ConstraintDefBodyElement {
26    Error(Node<ParseErrorNode>),
27    Doc(Node<DocComment>),
28    InOutDecl(Node<InOutDecl>),
29    Expression(Node<Expression>), // e.g. totalThrust >= totalWeight * margin
30    /// Unmodeled constraint-body element captured as raw text (used for library parsing).
31    Other(String),
32}
33
34/// constraint body {}
35#[derive(Debug, Clone, PartialEq, Eq)]
36pub enum ConstraintBody {
37    Semicolon,
38    Brace, // Often contains docs or block of expressions
39}
40
41/// Calc definition: `calc def` Identification body.
42#[derive(Debug, Clone, PartialEq, Eq)]
43pub struct CalcDef {
44    pub identification: Identification,
45    pub body: CalcDefBody,
46}
47
48/// Calculation usage: `calc` Identification (`:` type)? body.
49#[derive(Debug, Clone, PartialEq, Eq)]
50pub struct CalcUsage {
51    pub identification: Identification,
52    pub type_name: Option<String>,
53    pub body: CalcDefBody,
54}
55
56#[derive(Debug, Clone, PartialEq, Eq)]
57pub enum CalcDefBody {
58    Semicolon,
59    Brace {
60        elements: Vec<Node<CalcDefBodyElement>>,
61    },
62}
63
64#[derive(Debug, Clone, PartialEq, Eq)]
65pub enum CalcDefBodyElement {
66    Error(Node<ParseErrorNode>),
67    Doc(Node<DocComment>),
68    InOutDecl(Node<InOutDecl>),
69    ReturnDecl(Node<ReturnDecl>),
70    Expression(Node<Expression>), // formula
71    /// Unmodeled calc-body element captured as raw text (used for library parsing).
72    Other(String),
73}
74
75/// Return declaration: `return` name `:` type `;`.
76#[derive(Debug, Clone, PartialEq, Eq)]
77pub struct ReturnDecl {
78    pub name: String,
79    pub type_name: String,
80}
81
82// ---------------------------------------------------------------------------
83// Views and Viewpoints (SysML v2 Clause 8.2.2.26)
84// ---------------------------------------------------------------------------
85
86/// View definition: `view def` Identification ViewDefinitionBody.
87#[derive(Debug, Clone, PartialEq, Eq)]
88pub struct ViewDef {
89    pub identification: Identification,
90    pub specializes: Option<String>,
91    pub specializes_span: Option<Span>,
92    pub body: ViewDefBody,
93}
94
95#[derive(Debug, Clone, PartialEq, Eq)]
96pub enum ViewDefBody {
97    Semicolon,
98    Brace {
99        elements: Vec<Node<ViewDefBodyElement>>,
100    },
101}
102
103#[derive(Debug, Clone, PartialEq, Eq)]
104pub enum ViewDefBodyElement {
105    Error(Node<ParseErrorNode>),
106    /// Unmodeled view-definition body element captured as raw text (used for library parsing).
107    Other(String),
108    Doc(Node<DocComment>),
109    Filter(Node<FilterMember>),
110    ViewRendering(Node<ViewRenderingUsage>),
111}
112
113/// View rendering usage: `render` name `:` type (`;` or body).
114#[derive(Debug, Clone, PartialEq, Eq)]
115pub struct ViewRenderingUsage {
116    pub name: String,
117    pub type_name: Option<String>,
118    pub body: ConnectBody,
119}
120
121/// Viewpoint definition: `viewpoint def` Identification RequirementBody.
122#[derive(Debug, Clone, PartialEq, Eq)]
123pub struct ViewpointDef {
124    pub identification: Identification,
125    pub specializes: Option<String>,
126    pub specializes_span: Option<Span>,
127    pub body: RequirementDefBody,
128}
129
130/// Rendering definition: `rendering def` Definition.
131#[derive(Debug, Clone, PartialEq, Eq)]
132pub struct RenderingDef {
133    pub identification: Identification,
134    pub specializes: Option<String>,
135    pub specializes_span: Option<Span>,
136    pub body: RenderingDefBody,
137}
138
139#[derive(Debug, Clone, PartialEq, Eq)]
140pub enum RenderingDefBody {
141    Semicolon,
142    Brace {
143        elements: Vec<Node<RenderingDefBodyElement>>,
144    },
145}
146
147#[derive(Debug, Clone, PartialEq, Eq)]
148pub enum RenderingDefBodyElement {
149    Error(Node<ParseErrorNode>),
150    Doc(Node<DocComment>),
151    Filter(Node<FilterMember>),
152    ViewRendering(Node<ViewRenderingUsage>),
153    Other(String),
154}
155
156/// View usage: `view` name `:` type? ViewBody.
157#[derive(Debug, Clone, PartialEq, Eq)]
158pub struct ViewUsage {
159    pub name: String,
160    pub type_name: Option<String>,
161    pub body: ViewBody,
162}
163
164#[derive(Debug, Clone, PartialEq, Eq)]
165pub enum ViewBody {
166    Semicolon,
167    Brace {
168        elements: Vec<Node<ViewBodyElement>>,
169    },
170}
171
172#[derive(Debug, Clone, PartialEq, Eq)]
173pub enum ViewBodyElement {
174    Error(Node<ParseErrorNode>),
175    /// Unmodeled view body element captured as raw text (used for library parsing).
176    Other(String),
177    Doc(Node<DocComment>),
178    Filter(Node<FilterMember>),
179    ViewRendering(Node<ViewRenderingUsage>),
180    Expose(Node<ExposeMember>),
181    Satisfy(Node<SatisfyViewMember>),
182}
183
184/// Expose in view body: `expose` (MembershipImport | NamespaceImport) RelationshipBody.
185#[derive(Debug, Clone, PartialEq, Eq)]
186pub struct ExposeMember {
187    /// Full target path (e.g. vehicle, vehicle::*, vehicle::*::**, SystemModel::vehicle::**).
188    pub target: String,
189    pub body: ConnectBody,
190}
191
192/// Satisfy in view body: `satisfy` QualifiedName RelationshipBody.
193#[derive(Debug, Clone, PartialEq, Eq)]
194pub struct SatisfyViewMember {
195    pub viewpoint_ref: String,
196    pub body: ConnectBody,
197}
198
199/// Viewpoint usage: `viewpoint` ConstraintUsageDeclaration RequirementBody.
200#[derive(Debug, Clone, PartialEq, Eq)]
201pub struct ViewpointUsage {
202    pub name: String,
203    pub type_name: String,
204    pub body: RequirementDefBody,
205}
206
207/// Rendering usage: `rendering` Usage.
208#[derive(Debug, Clone, PartialEq, Eq)]
209pub struct RenderingUsage {
210    pub name: String,
211    pub type_name: Option<String>,
212    pub body: ConnectBody,
213}