Skip to main content

sysml_v2_parser/
ast.rs

1//! Abstract syntax tree types for SysML v2 textual notation.
2
3/// Source location: byte offset, line, column, and length in the source file.
4/// Line and column are **1-based**. Use [`Span::to_lsp_range`] for 0-based LSP ranges.
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct Span {
7    pub offset: usize,
8    pub line: u32,
9    pub column: usize,
10    pub len: usize,
11}
12
13impl Span {
14    /// Dummy span for tests or synthetic nodes (offset 0, line 1, column 1, len 0).
15    pub fn dummy() -> Self {
16        Self {
17            offset: 0,
18            line: 1,
19            column: 1,
20            len: 0,
21        }
22    }
23
24    /// LSP uses 0-based line and 0-based character. Returns (start_line, start_character, end_line, end_character).
25    pub fn to_lsp_range(&self) -> (u32, u32, u32, u32) {
26        let start_line = self.line.saturating_sub(1);
27        let start_char = self.column.saturating_sub(1);
28        let end_char = start_char.saturating_add(self.len);
29        (start_line, start_char as u32, start_line, end_char as u32)
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::Span;
36
37    #[test]
38    fn span_dummy() {
39        let s = Span::dummy();
40        assert_eq!(s.offset, 0);
41        assert_eq!(s.line, 1);
42        assert_eq!(s.column, 1);
43        assert_eq!(s.len, 0);
44    }
45}
46
47#[derive(Debug, Clone)]
48pub struct Node<T> {
49    pub span: Span,
50    pub value: T,
51}
52
53impl<T: PartialEq> PartialEq for Node<T> {
54    fn eq(&self, other: &Self) -> bool {
55        self.value == other.value
56    }
57}
58
59impl<T: Eq> Eq for Node<T> {}
60
61impl<T> Node<T> {
62    pub fn new(span: Span, value: T) -> Self {
63        Self { span, value }
64    }
65}
66
67impl<T> std::ops::Deref for Node<T> {
68    type Target = T;
69    fn deref(&self) -> &T {
70        &self.value
71    }
72}
73
74/// Trait for generic access to node source span (e.g. visitors).
75pub trait AstNode {
76    fn span(&self) -> Span;
77}
78
79impl<T> AstNode for Node<T> {
80    fn span(&self) -> Span {
81        self.span.clone()
82    }
83}
84
85/// Expression: literals, feature refs, member access, index, bracket/unit, etc.
86#[derive(Debug, Clone, PartialEq, Eq)]
87pub enum Expression {
88    LiteralInteger(i64),
89    LiteralReal(String),
90    LiteralString(String),
91    LiteralBoolean(bool),
92    /// Single name or qualified name.
93    FeatureRef(String),
94    /// base.member (e.g. engine.fuelCmdPort).
95    MemberAccess(Box<Node<Expression>>, String),
96    /// base#(index) e.g. frontWheel#(1).
97    Index {
98        base: Box<Node<Expression>>,
99        index: Box<Node<Expression>>,
100    },
101    /// [unit] e.g. [kg].
102    Bracket(Box<Node<Expression>>),
103    /// value [unit] e.g. 1750 [kg].
104    LiteralWithUnit {
105        value: Box<Node<Expression>>,
106        unit: Box<Node<Expression>>,
107    },
108    /// Binary infix operation e.g. `a >= b * c`, `x / y`.
109    BinaryOp {
110        op: String,
111        left: Box<Node<Expression>>,
112        right: Box<Node<Expression>>,
113    },
114    /// Unary prefix: + - ~ not
115    UnaryOp {
116        op: String,
117        operand: Box<Node<Expression>>,
118    },
119    /// Function-like invocation, e.g. `ComputeMargin(a, b)`.
120    Invocation {
121        callee: Box<Node<Expression>>,
122        args: Vec<Node<Expression>>,
123    },
124    /// Comma-separated sequence in parentheses, e.g. `(engine1, engine2)` for ordered composition values.
125    Tuple(Vec<Node<Expression>>),
126    /// KerML null or empty sequence ().
127    Null,
128}
129
130/// KerML top-level element: package, namespace, import, or library package (BNF RootNamespace = PackageBodyElement*).
131#[derive(Debug, Clone, PartialEq, Eq)]
132pub enum RootElement {
133    Package(Node<Package>),
134    LibraryPackage(Node<LibraryPackage>),
135    Namespace(Node<NamespaceDecl>),
136    Import(Node<Import>),
137}
138
139/// KerML NamespaceDeclaration: `namespace` Identification NamespaceBody (same body structure as Package).
140#[derive(Debug, Clone, PartialEq, Eq)]
141pub struct NamespaceDecl {
142    pub identification: Identification,
143    pub body: PackageBody,
144}
145
146/// Root of a SysML/KerML document: a sequence of top-level package or namespace elements.
147#[derive(Debug, Clone, PartialEq, Eq)]
148pub struct RootNamespace {
149    pub elements: Vec<Node<RootElement>>,
150}
151
152/// KerML ElementFilterMember: MemberPrefix? 'filter' condition ';'
153#[derive(Debug, Clone, PartialEq, Eq)]
154pub struct FilterMember {
155    pub visibility: Option<Visibility>,
156    pub condition: Node<Expression>,
157}
158
159/// Placeholder node inserted when resilient parsing skips malformed input.
160#[derive(Debug, Clone, PartialEq, Eq)]
161pub struct ParseErrorNode {
162    pub message: String,
163    pub code: String,
164    pub expected: Option<String>,
165    pub found: Option<String>,
166    pub suggestion: Option<String>,
167    pub category: Option<crate::error::DiagnosticCategory>,
168}
169
170/// Modeled KerML semantic declaration captured as package-level syntax.
171#[derive(Debug, Clone, PartialEq, Eq)]
172pub struct KermlSemanticDecl {
173    pub bnf_production: String,
174    pub text: String,
175}
176
177/// Modeled KerML feature declaration family (occurrence/expr/predicate/succession).
178#[derive(Debug, Clone, PartialEq, Eq)]
179pub struct KermlFeatureDecl {
180    pub bnf_production: String,
181    pub text: String,
182}
183
184/// Package-level KerML feature declaration captured as an explicit dedicated node.
185#[derive(Debug, Clone, PartialEq, Eq)]
186pub struct FeatureDecl {
187    pub keyword: String,
188    pub text: String,
189}
190
191/// Package-level KerML classifier declaration captured as an explicit dedicated node.
192#[derive(Debug, Clone, PartialEq, Eq)]
193pub struct ClassifierDecl {
194    pub keyword: String,
195    pub text: String,
196}
197
198/// Modeled extended SysML/KerML declaration family not yet represented by
199/// dedicated concrete nodes (e.g. concern/message style library declarations).
200#[derive(Debug, Clone, PartialEq, Eq)]
201pub struct ExtendedLibraryDecl {
202    pub bnf_production: String,
203    pub text: String,
204}
205
206/// Top-level element inside a namespace or package body.
207#[derive(Debug, Clone, PartialEq, Eq)]
208pub enum PackageBodyElement {
209    Error(Node<ParseErrorNode>),
210    Doc(Node<DocComment>),
211    Comment(Node<CommentAnnotation>),
212    TextualRep(Node<TextualRepresentation>),
213    Filter(Node<FilterMember>),
214    Package(Node<Package>),
215    LibraryPackage(Node<LibraryPackage>),
216    Import(Node<Import>),
217    PartDef(Node<PartDef>),
218    PartUsage(Node<PartUsage>),
219    PortDef(Node<PortDef>),
220    InterfaceDef(Node<InterfaceDef>),
221    AliasDef(Node<AliasDef>),
222    AttributeDef(Node<AttributeDef>),
223    ActionDef(Node<ActionDef>),
224    ActionUsage(Node<ActionUsage>),
225    RequirementDef(Node<RequirementDef>),
226    RequirementUsage(Node<RequirementUsage>),
227    Satisfy(Node<Satisfy>),
228    UseCaseDef(Node<UseCaseDef>),
229    Actor(Node<ActorDecl>),
230    StateDef(Node<StateDef>),
231    StateUsage(Node<StateUsage>),
232    ItemDef(Node<ItemDef>),
233    IndividualDef(Node<IndividualDef>),
234    ConstraintDef(Node<ConstraintDef>),
235    CalcDef(Node<CalcDef>),
236    ViewDef(Node<ViewDef>),
237    ViewpointDef(Node<ViewpointDef>),
238    RenderingDef(Node<RenderingDef>),
239    ViewUsage(Node<ViewUsage>),
240    ViewpointUsage(Node<ViewpointUsage>),
241    RenderingUsage(Node<RenderingUsage>),
242    ConnectionDef(Node<ConnectionDef>),
243    MetadataDef(Node<MetadataDef>),
244    EnumDef(Node<EnumDef>),
245    OccurrenceDef(Node<OccurrenceDef>),
246    OccurrenceUsage(Node<OccurrenceUsage>),
247    Dependency(Node<Dependency>),
248    AllocationDef(Node<AllocationDef>),
249    AllocationUsage(Node<AllocationUsage>),
250    FlowDef(Node<FlowDef>),
251    FlowUsage(Node<FlowUsage>),
252    ConcernUsage(Node<ConcernUsage>),
253    CaseDef(Node<CaseDef>),
254    CaseUsage(Node<CaseUsage>),
255    AnalysisCaseDef(Node<AnalysisCaseDef>),
256    AnalysisCaseUsage(Node<AnalysisCaseUsage>),
257    VerificationCaseDef(Node<VerificationCaseDef>),
258    VerificationCaseUsage(Node<VerificationCaseUsage>),
259    UseCaseUsage(Node<UseCaseUsage>),
260    FeatureDecl(Node<FeatureDecl>),
261    ClassifierDecl(Node<ClassifierDecl>),
262    KermlSemanticDecl(Node<KermlSemanticDecl>),
263    KermlFeatureDecl(Node<KermlFeatureDecl>),
264    ExtendedLibraryDecl(Node<ExtendedLibraryDecl>),
265}
266
267/// A package declaration: `package` Identification PackageBody
268#[derive(Debug, Clone, PartialEq, Eq)]
269pub struct Package {
270    pub identification: Identification,
271    pub body: PackageBody,
272}
273
274/// Identification: optional short name in `< >`, optional name.
275/// BNF: ( '<' declaredShortName = NAME '>' )? ( declaredName = NAME )?
276#[derive(Debug, Clone, PartialEq, Eq)]
277pub struct Identification {
278    /// Short name inside `< ... >`, if present.
279    pub short_name: Option<String>,
280    /// Main declared name (may be quoted, e.g. '1a-Parts Tree').
281    pub name: Option<String>,
282}
283
284/// Package body: either `;` or `{` PackageBodyElement* `}`
285#[derive(Debug, Clone, PartialEq, Eq)]
286pub enum PackageBody {
287    /// Semicolon form: no body elements.
288    Semicolon,
289    /// Brace form: list of body elements (may be empty).
290    Brace {
291        elements: Vec<Node<PackageBodyElement>>,
292    },
293}
294
295/// Visibility for imports and members.
296#[derive(Debug, Clone, Copy, PartialEq, Eq)]
297pub enum Visibility {
298    Public,
299    Private,
300    Protected,
301}
302
303/// KerML FilterPackageMember: `[` OwnedExpression `]`.
304#[derive(Debug, Clone, PartialEq, Eq)]
305pub struct FilterPackageMember {
306    pub expression: Node<Expression>,
307}
308
309/// Import: `private`? `import` `all`? QualifiedName (`::` `*`)? or FilterPackage form.
310#[derive(Debug, Clone, PartialEq, Eq)]
311pub struct Import {
312    pub visibility: Option<Visibility>,
313    /// Whether this is a namespace import (QualifiedName::* or FilterPackage) or membership import (single QualifiedName).
314    pub is_import_all: bool,
315    /// Import target, e.g. "SI::kg" or "Definitions::*".
316    pub target: String,
317    /// KerML: optional recursive import after :: (e.g. QualifiedName::** or QualifiedName::*::**).
318    pub is_recursive: bool,
319    /// KerML FilterPackage form: one or more `[ expr ]` members. When present, this is a namespace import of a filter package.
320    pub filter_members: Option<Vec<Node<FilterPackageMember>>>,
321}
322
323/// Part definition: `part def` Identification (`:>` specializes)? Body.
324#[derive(Debug, Clone, PartialEq, Eq)]
325pub struct PartDef {
326    /// Optional `abstract` or `variation` prefix (BNF BasicDefinitionPrefix).
327    pub definition_prefix: Option<DefinitionPrefix>,
328    /// Whether this is an `individual part def`.
329    pub is_individual: bool,
330    pub identification: Identification,
331    /// Supertype after `:>`, e.g. Some("Axle") for `part def FrontAxle :> Axle`.
332    pub specializes: Option<String>,
333    /// Span of the `:> <type>` fragment (for semantic tokens), when present.
334    pub specializes_span: Option<Span>,
335    pub body: PartDefBody,
336}
337
338/// BNF BasicDefinitionPrefix: `abstract` | `variation`.
339#[derive(Debug, Clone, PartialEq, Eq)]
340pub enum DefinitionPrefix {
341    Abstract,
342    Variation,
343}
344
345/// Body of a part definition: `;` or `{` PartDefBodyElement* `}`.
346#[derive(Debug, Clone, PartialEq, Eq)]
347pub enum PartDefBody {
348    Semicolon,
349    Brace {
350        elements: Vec<Node<PartDefBodyElement>>,
351    },
352}
353
354/// Element inside a part definition body.
355#[derive(Debug, Clone, PartialEq, Eq)]
356pub enum PartDefBodyElement {
357    Error(Node<ParseErrorNode>),
358    Doc(Node<DocComment>),
359    Comment(Node<CommentAnnotation>),
360    Annotation(Node<Annotation>),
361    Other(String),
362    AttributeDef(Node<AttributeDef>),
363    AttributeUsage(Node<AttributeUsage>),
364    RequirementUsage(Node<RequirementUsage>),
365    Ref(Node<RefDecl>),
366    PortUsage(Node<PortUsage>),
367    PartUsage(Box<Node<PartUsage>>),
368    OccurrenceUsage(Box<Node<OccurrenceUsage>>),
369    InterfaceDef(Node<InterfaceDef>),
370    InterfaceUsage(Node<InterfaceUsage>),
371    Connect(Node<Connect>),
372    /// `connection` usage member inside a part definition body.
373    Connection(Node<ConnectionUsageMember>),
374    Perform(Node<Perform>),
375    Allocate(Node<Allocate>),
376    OpaqueMember(Node<OpaqueMemberDecl>),
377    /// `exhibit state` name `:` type (`;` or body).
378    ExhibitState(Node<ExhibitState>),
379}
380
381/// Library-tolerant part member preserved without forcing it into an unrelated node shape.
382#[derive(Debug, Clone, PartialEq, Eq)]
383pub struct OpaqueMemberDecl {
384    pub keyword: String,
385    pub name: String,
386    pub text: String,
387    pub body: AttributeBody,
388}
389
390/// Connection usage member inside part definitions.
391#[derive(Debug, Clone, PartialEq, Eq)]
392pub struct ConnectionUsageMember {
393    pub name: Option<String>,
394    pub type_name: Option<String>,
395    pub body: ConnectionDefBody,
396    pub subsets: Option<String>,
397    pub redefines: Option<String>,
398}
399
400/// Exhibit state usage: `exhibit state` name `:` type (`;` or body).
401#[derive(Debug, Clone, PartialEq, Eq)]
402pub struct ExhibitState {
403    pub name: String,
404    pub type_name: Option<String>,
405    pub redefines: Option<String>,
406    pub body: StateDefBody,
407}
408
409/// Attribute definition: `attribute` [`def`] name (`:>` | `:` type)? (`=` value)? body.
410#[derive(Debug, Clone, PartialEq, Eq)]
411pub struct AttributeDef {
412    pub name: String,
413    /// Type after `:>`, e.g. Some("ISQ::mass").
414    pub typing: Option<String>,
415    /// Default or binding after `=` / `:=` / `default =` before the body terminator.
416    pub value: Option<Node<Expression>>,
417    pub body: AttributeBody,
418    /// Span of the defined name (for semantic tokens).
419    pub name_span: Option<Span>,
420    /// Span of the type after `:>`, if present (for semantic tokens).
421    pub typing_span: Option<Span>,
422}
423
424/// Body of an attribute (def or usage): `;` or `{` ... `}`.
425#[derive(Debug, Clone, PartialEq, Eq)]
426pub enum AttributeBody {
427    Semicolon,
428    Brace,
429}
430
431/// Item definition: `item def` Identification body (for events, etc.).
432#[derive(Debug, Clone, PartialEq, Eq)]
433pub struct ItemDef {
434    pub identification: Identification,
435    pub body: AttributeBody,
436}
437
438/// Individual definition: `individual def` Identification `:>` type body.
439#[derive(Debug, Clone, PartialEq, Eq)]
440pub struct IndividualDef {
441    pub identification: Identification,
442    pub specializes: Option<String>,
443    pub body: AttributeBody,
444}
445
446/// Part usage: `part` name `:` type multiplicity? `ordered`? (`redefines`|`:>>`)? value? body.
447#[derive(Debug, Clone, PartialEq, Eq)]
448pub struct PartUsage {
449    pub is_individual: bool,
450    pub name: String,
451    /// Type after `:`, e.g. "Vehicle", "AxleAssembly".
452    pub type_name: String,
453    /// Multiplicity, e.g. Some("[2]").
454    pub multiplicity: Option<String>,
455    pub ordered: bool,
456    /// Optional `subsets` feature and value expression.
457    pub subsets: Option<(String, Option<Node<Expression>>)>,
458    /// Redefines target, e.g. Some("frontAxleAssembly") or Some("vehicle1::mass").
459    pub redefines: Option<String>,
460    /// Value expression (= expr, default = expr, := expr).
461    pub value: Option<Node<Expression>>,
462    pub body: PartUsageBody,
463    /// Span of the usage name (for semantic tokens).
464    pub name_span: Option<Span>,
465    /// Span of the type reference after `:` (for semantic tokens).
466    pub type_ref_span: Option<Span>,
467}
468
469/// Body of a part usage: `;` or `{` PartUsageBodyElement* `}`.
470#[derive(Debug, Clone, PartialEq, Eq)]
471pub enum PartUsageBody {
472    Semicolon,
473    Brace {
474        elements: Vec<Node<PartUsageBodyElement>>,
475    },
476}
477
478/// Metadata annotation on usage: `@` Name (`:` Type)? MetadataBody (e.g. `@Security;` or `@Safety{isMandatory = true;}`).
479#[derive(Debug, Clone, PartialEq, Eq)]
480pub struct MetadataAnnotation {
481    pub name: String,
482    pub type_name: Option<String>,
483    pub body: ConnectBody,
484}
485
486/// Generic annotation or metadata usage captured in body scopes.
487#[derive(Debug, Clone, PartialEq, Eq)]
488pub struct Annotation {
489    pub sigil: String,
490    pub head: String,
491    pub type_name: Option<String>,
492    pub body: ConnectBody,
493}
494
495/// Element inside a part usage body.
496#[derive(Debug, Clone, PartialEq, Eq)]
497pub enum PartUsageBodyElement {
498    Error(Node<ParseErrorNode>),
499    Doc(Node<DocComment>),
500    Annotation(Node<Annotation>),
501    AttributeUsage(Node<AttributeUsage>),
502    PartUsage(Box<Node<PartUsage>>),
503    OccurrenceUsage(Box<Node<OccurrenceUsage>>),
504    PortUsage(Node<PortUsage>),
505    Bind(Node<Bind>),
506    /// `ref` name `:` type body (reference binding in part usage).
507    Ref(Node<RefDecl>),
508    InterfaceUsage(Node<InterfaceUsage>),
509    Connect(Node<Connect>),
510    Perform(Node<Perform>),
511    Allocate(Node<Allocate>),
512    Satisfy(Node<Satisfy>),
513    StateUsage(Node<StateUsage>),
514    MetadataAnnotation(Node<MetadataAnnotation>),
515}
516
517/// Enacted performance: `perform` action_path `{` body `}` inside a part usage.
518#[derive(Debug, Clone, PartialEq, Eq)]
519pub struct Perform {
520    /// Qualified action name (e.g. "provide power" or "provide power.generate torque").
521    pub action_name: String,
522    /// Type after `:` in "perform action name : Type" form.
523    pub type_name: Option<String>,
524    pub body: PerformBody,
525}
526
527/// Body of a perform: `;` or `{` PerformBodyElement* `}`.
528#[derive(Debug, Clone, PartialEq, Eq)]
529pub enum PerformBody {
530    Semicolon,
531    Brace {
532        elements: Vec<Node<PerformBodyElement>>,
533    },
534}
535
536/// Element inside a perform body: doc comment or in/out binding.
537#[derive(Debug, Clone, PartialEq, Eq)]
538pub enum PerformBodyElement {
539    Doc(Node<DocComment>),
540    InOut(Node<PerformInOutBinding>),
541}
542
543/// In/out binding inside a perform body: `in` name `=` expr `;` or `out` name `=` expr `;`.
544#[derive(Debug, Clone, PartialEq, Eq)]
545pub struct PerformInOutBinding {
546    pub direction: InOut,
547    pub name: String,
548    pub value: Node<Expression>,
549}
550
551/// Attribute usage: `attribute` name (`:>` | `:` type)? `redefines`? value? body.
552#[derive(Debug, Clone, PartialEq, Eq)]
553pub struct AttributeUsage {
554    pub name: String,
555    /// Type after `:` or `:>`, e.g. Some("MassValue").
556    pub typing: Option<String>,
557    /// Redefines target, e.g. Some("Vehicle::mass").
558    pub redefines: Option<String>,
559    /// Value expression.
560    pub value: Option<Node<Expression>>,
561    pub body: AttributeBody,
562    /// Span of the usage name (for semantic tokens).
563    pub name_span: Option<Span>,
564    /// Span of the type after `:` / `:>`, if present (for semantic tokens).
565    pub typing_span: Option<Span>,
566    /// Span of the redefines target after `redefines`, if present (for semantic tokens).
567    pub redefines_span: Option<Span>,
568}
569
570// ---------------------------------------------------------------------------
571// Port
572// ---------------------------------------------------------------------------
573
574/// Port definition: `port def` Identification body.
575#[derive(Debug, Clone, PartialEq, Eq)]
576pub struct PortDef {
577    pub identification: Identification,
578    /// Supertype after `:>`, e.g. Some("ClutchPort") for `port def ManualClutchPort :> ClutchPort`.
579    pub specializes: Option<String>,
580    pub body: PortDefBody,
581}
582
583/// Body of a port definition: `;` or `{` PortDefBodyElement* `}`.
584#[derive(Debug, Clone, PartialEq, Eq)]
585pub enum PortDefBody {
586    Semicolon,
587    Brace {
588        elements: Vec<Node<PortDefBodyElement>>,
589    },
590}
591
592/// Element inside a port definition body (in/out declarations or nested port usages).
593#[derive(Debug, Clone, PartialEq, Eq)]
594pub enum PortDefBodyElement {
595    InOutDecl(Node<InOutDecl>),
596    Doc(Node<DocComment>),
597    AttributeDef(Node<AttributeDef>),
598    AttributeUsage(Node<AttributeUsage>),
599    PortUsage(Node<PortUsage>),
600}
601
602/// Port usage: `port` name `:` type multiplicity? `:>` subsets? `redefines`? body.
603#[derive(Debug, Clone, PartialEq, Eq)]
604pub struct PortUsage {
605    pub name: String,
606    pub type_name: Option<String>,
607    pub multiplicity: Option<String>,
608    /// Subsets feature and optional value expression.
609    pub subsets: Option<(String, Option<Node<Expression>>)>,
610    pub redefines: Option<String>,
611    pub body: PortBody,
612    /// Span of the usage name (for semantic tokens).
613    pub name_span: Option<Span>,
614    /// Span of the type reference after `:`, if present (for semantic tokens).
615    pub type_ref_span: Option<Span>,
616}
617
618/// Body of a port usage: `;` or `{` PortUsage* `}` (nested ports).
619#[derive(Debug, Clone, PartialEq, Eq)]
620pub enum PortBody {
621    Semicolon,
622    Brace,
623    /// Brace with nested port usages (e.g. port vehicleToRoadPort redefines ... { port left...; port right...; }).
624    BraceWithPorts {
625        elements: Vec<Node<PortUsage>>,
626    },
627}
628
629// ---------------------------------------------------------------------------
630// Interface
631// ---------------------------------------------------------------------------
632
633/// Interface definition: `interface def` Identification body.
634#[derive(Debug, Clone, PartialEq, Eq)]
635pub struct InterfaceDef {
636    pub identification: Identification,
637    pub body: InterfaceDefBody,
638}
639
640/// Body of an interface definition: `;` or `{` InterfaceDefBodyElement* `}`.
641#[derive(Debug, Clone, PartialEq, Eq)]
642pub enum InterfaceDefBody {
643    Semicolon,
644    Brace {
645        elements: Vec<Node<InterfaceDefBodyElement>>,
646    },
647}
648
649/// Element inside an interface definition body.
650#[derive(Debug, Clone, PartialEq, Eq)]
651pub enum InterfaceDefBodyElement {
652    Doc(Node<DocComment>),
653    EndDecl(Node<EndDecl>),
654    RefDecl(Node<RefDecl>),
655    ConnectStmt(Node<ConnectStmt>),
656}
657
658/// End declaration in interface def: `end` name `:` type `;`.
659#[derive(Debug, Clone, PartialEq, Eq)]
660pub struct EndDecl {
661    pub name: String,
662    pub type_name: String,
663    pub uses_derived_syntax: bool,
664    /// Span of the name (for semantic tokens).
665    pub name_span: Option<Span>,
666    /// Span of the type after `:` (for semantic tokens).
667    pub type_ref_span: Option<Span>,
668}
669
670/// Ref declaration in interface def: `ref` name `:` type body.
671#[derive(Debug, Clone, PartialEq, Eq)]
672pub struct RefDecl {
673    pub name: String,
674    pub type_name: String,
675    /// Optional binding value: `= expr` (SysML shorthand binding for references).
676    pub value: Option<Node<Expression>>,
677    pub body: RefBody,
678    /// Span of the name (for semantic tokens).
679    pub name_span: Option<Span>,
680    /// Span of the type after `:` (for semantic tokens).
681    pub type_ref_span: Option<Span>,
682}
683
684/// Body of a ref declaration: `;` or `{` ... `}`.
685#[derive(Debug, Clone, PartialEq, Eq)]
686pub enum RefBody {
687    Semicolon,
688    Brace,
689}
690
691// ---------------------------------------------------------------------------
692// Connection (Phase 2)
693// ---------------------------------------------------------------------------
694
695/// Connection definition: `connection def` Identification body (BNF ConnectionDefinition).
696#[derive(Debug, Clone, PartialEq, Eq)]
697pub struct ConnectionDef {
698    pub annotation: Option<String>,
699    pub identification: Identification,
700    pub body: ConnectionDefBody,
701}
702
703/// Body of a connection definition: `;` or `{` end/ref/connect* `}`.
704#[derive(Debug, Clone, PartialEq, Eq)]
705pub enum ConnectionDefBody {
706    Semicolon,
707    Brace {
708        elements: Vec<Node<ConnectionDefBodyElement>>,
709    },
710}
711
712#[derive(Debug, Clone, PartialEq, Eq)]
713pub enum ConnectionDefBodyElement {
714    EndDecl(Node<EndDecl>),
715    RefDecl(Node<RefDecl>),
716    ConnectStmt(Node<ConnectStmt>),
717}
718
719// ---------------------------------------------------------------------------
720// Metadata (Phase 2)
721// ---------------------------------------------------------------------------
722
723/// Metadata definition: `metadata def` Identification body (BNF MetadataDefinition).
724#[derive(Debug, Clone, PartialEq, Eq)]
725pub struct MetadataDef {
726    pub is_abstract: bool,
727    pub identification: Identification,
728    pub body: DefinitionBody,
729}
730
731// ---------------------------------------------------------------------------
732// Enumeration (Phase 2)
733// ---------------------------------------------------------------------------
734
735/// Enumeration definition: `enum def` Identification EnumerationBody (BNF EnumerationDefinition).
736#[derive(Debug, Clone, PartialEq, Eq)]
737pub struct EnumDef {
738    pub identification: Identification,
739    pub body: EnumerationBody,
740}
741
742#[derive(Debug, Clone, PartialEq, Eq)]
743pub enum EnumerationBody {
744    Semicolon,
745    Brace { values: Vec<String> },
746}
747
748// ---------------------------------------------------------------------------
749// Occurrence (Phase 2)
750// ---------------------------------------------------------------------------
751
752/// Occurrence definition: `occurrence def` Identification body (BNF OccurrenceDefinition).
753#[derive(Debug, Clone, PartialEq, Eq)]
754pub struct OccurrenceDef {
755    pub is_abstract: bool,
756    pub identification: Identification,
757    pub body: DefinitionBody,
758}
759
760/// Occurrence usage: `occurrence` name (`:` type)? body, with optional individual/portion modifiers.
761#[derive(Debug, Clone, PartialEq, Eq)]
762pub struct OccurrenceUsage {
763    pub is_individual: bool,
764    pub is_then: bool,
765    pub portion_kind: Option<String>,
766    pub name: String,
767    pub type_name: Option<String>,
768    pub subsets: Option<String>,
769    pub redefines: Option<String>,
770    pub body: OccurrenceUsageBody,
771}
772
773#[derive(Debug, Clone, PartialEq, Eq)]
774pub enum OccurrenceUsageBody {
775    Semicolon,
776    Brace {
777        elements: Vec<Node<OccurrenceBodyElement>>,
778    },
779}
780
781/// Occurrence-level assert member: `assert constraint` body.
782#[derive(Debug, Clone, PartialEq, Eq)]
783pub struct AssertConstraintMember {
784    pub body: ConstraintDefBody,
785}
786
787#[derive(Debug, Clone, PartialEq, Eq)]
788pub enum OccurrenceBodyElement {
789    Error(Node<ParseErrorNode>),
790    Doc(Node<DocComment>),
791    Annotation(Node<Annotation>),
792    AssertConstraint(Node<AssertConstraintMember>),
793    Other(String),
794    AttributeUsage(Node<AttributeUsage>),
795    PartUsage(Box<Node<PartUsage>>),
796    OccurrenceUsage(Box<Node<OccurrenceUsage>>),
797}
798
799// ---------------------------------------------------------------------------
800// Library Package (Phase 2)
801// ---------------------------------------------------------------------------
802
803/// Library package: `library` (optional `standard`) `package` Identification PackageBody (BNF LibraryPackage).
804#[derive(Debug, Clone, PartialEq, Eq)]
805pub struct LibraryPackage {
806    pub is_standard: bool,
807    pub identification: Identification,
808    pub body: PackageBody,
809}
810
811/// Generic definition body: `;` or `{` ... `}` (skip content for metadata/occurrence).
812#[derive(Debug, Clone, PartialEq, Eq)]
813pub enum DefinitionBody {
814    Semicolon,
815    Brace,
816}
817
818/// Connect statement in interface def or usage: `connect` from `to` to body.
819#[derive(Debug, Clone, PartialEq, Eq)]
820pub struct ConnectStmt {
821    pub from: Node<Expression>,
822    pub to: Node<Expression>,
823    pub body: ConnectBody,
824}
825
826/// Body of a connect statement: `;` or `{` ... `}`.
827#[derive(Debug, Clone, PartialEq, Eq)]
828pub enum ConnectBody {
829    Semicolon,
830    Brace,
831}
832
833// ---------------------------------------------------------------------------
834// Part usage body: bind, interface usage, connect
835// ---------------------------------------------------------------------------
836
837/// Bind: `bind` left `=` right (`;` or `{ }`).
838#[derive(Debug, Clone, PartialEq, Eq)]
839pub struct Bind {
840    pub left: Node<Expression>,
841    pub right: Node<Expression>,
842    /// Optional body after the bind (semicolon or brace); 3a fixture uses `bind x = y { }`.
843    pub body: Option<ConnectBody>,
844}
845
846/// Interface usage: typed+connect or connection form.
847#[derive(Debug, Clone, PartialEq, Eq)]
848pub enum InterfaceUsage {
849    /// `interface` `:Type`? `connect` from `to` to body; optional body with ref redefs.
850    TypedConnect {
851        interface_type: Option<String>,
852        from: Node<Expression>,
853        to: Node<Expression>,
854        body: ConnectBody,
855        body_elements: Vec<Node<InterfaceUsageBodyElement>>,
856    },
857    /// `interface` from `to` to body.
858    Connection {
859        from: Node<Expression>,
860        to: Node<Expression>,
861        body_elements: Vec<Node<InterfaceUsageBodyElement>>,
862    },
863}
864
865/// Element in interface usage body (e.g. ref redefinition).
866#[derive(Debug, Clone, PartialEq, Eq)]
867pub enum InterfaceUsageBodyElement {
868    /// `ref` `:>>` name `=` value body.
869    RefRedef {
870        name: String,
871        value: Node<Expression>,
872        body: RefBody,
873    },
874}
875
876/// Connect at part usage level: `connect` from `to` to body.
877#[derive(Debug, Clone, PartialEq, Eq)]
878pub struct Connect {
879    pub from: Node<Expression>,
880    pub to: Node<Expression>,
881    pub body: ConnectBody,
882}
883
884// ---------------------------------------------------------------------------
885// Alias
886// ---------------------------------------------------------------------------
887
888/// Alias definition: `alias` Identification `for` qualified_name body.
889#[derive(Debug, Clone, PartialEq, Eq)]
890pub struct AliasDef {
891    pub identification: Identification,
892    pub target: String,
893    pub body: AliasBody,
894}
895
896/// Body of an alias definition: `;` or `{` ... `}`.
897#[derive(Debug, Clone, PartialEq, Eq)]
898pub enum AliasBody {
899    Semicolon,
900    Brace,
901}
902
903// ---------------------------------------------------------------------------
904// Action (function-based behavior)
905// ---------------------------------------------------------------------------
906
907/// Action definition: `action def` Identification body (in/out params).
908#[derive(Debug, Clone, PartialEq, Eq)]
909pub struct ActionDef {
910    pub identification: Identification,
911    pub body: ActionDefBody,
912}
913
914/// Body of an action definition: `;` or `{` ActionDefBodyElement* `}`.
915#[derive(Debug, Clone, PartialEq, Eq)]
916pub enum ActionDefBody {
917    Semicolon,
918    Brace {
919        elements: Vec<Node<ActionDefBodyElement>>,
920    },
921}
922
923/// Element inside an action definition body.
924#[derive(Debug, Clone, PartialEq, Eq)]
925pub enum ActionDefBodyElement {
926    Error(Node<ParseErrorNode>),
927    InOutDecl(Node<InOutDecl>),
928    Doc(Node<DocComment>),
929    Annotation(Node<Annotation>),
930    RefDecl(Node<RefDecl>),
931    Perform(Node<Perform>),
932    Bind(Node<Bind>),
933    Flow(Node<Flow>),
934    FirstStmt(Node<FirstStmt>),
935    MergeStmt(Node<MergeStmt>),
936    StateUsage(Node<StateUsage>),
937    ActionUsage(Box<Node<ActionUsage>>),
938    Assign(Node<AssignStmt>),
939    ForLoop(Node<ForLoop>),
940    ThenAction(Node<ThenAction>),
941    Decl(Node<ActionBodyDecl>),
942}
943
944/// Assignment statement (SysML v2 AssignmentNode/AssignmentActionUsage).
945///
946/// Examples:
947/// - `assign x := y;`
948/// - `then assign position := dynamics.x_out;`
949#[derive(Debug, Clone, PartialEq, Eq)]
950pub struct AssignStmt {
951    pub is_then: bool,
952    pub lhs: String,
953    pub rhs: String,
954}
955
956/// For-loop node (SysML v2 ForLoopNode) - modeled minimally.
957#[derive(Debug, Clone, PartialEq, Eq)]
958pub struct ForLoop {
959    pub var: String,
960    pub range: String,
961    pub body: ActionDefBody,
962}
963
964/// Succession to an action usage: `then action ...`.
965#[derive(Debug, Clone, PartialEq, Eq)]
966pub struct ThenAction {
967    pub action: Node<ActionUsage>,
968}
969
970/// In/out parameter in action def: `in` name `:` type `;` or `out` name `:` type `;`.
971#[derive(Debug, Clone, PartialEq, Eq)]
972pub struct InOutDecl {
973    pub direction: InOut,
974    pub name: String,
975    pub type_name: String,
976}
977
978#[derive(Debug, Clone, Copy, PartialEq, Eq)]
979pub enum InOut {
980    In,
981    Out,
982    InOut,
983}
984
985/// Action usage: `action` name `:` type_name (`accept` param_name `:` param_type)? body.
986#[derive(Debug, Clone, PartialEq, Eq)]
987pub struct ActionUsage {
988    pub name: String,
989    pub type_name: String,
990    /// For accept form: (param_name, param_type).
991    pub accept: Option<(String, String)>,
992    pub body: ActionUsageBody,
993    /// Span of the usage name (for semantic tokens).
994    pub name_span: Option<Span>,
995    /// Span of the type reference after `:` (for semantic tokens).
996    pub type_ref_span: Option<Span>,
997}
998
999/// Body of an action usage: `;` or `{` ActionUsageBodyElement* `}`.
1000#[derive(Debug, Clone, PartialEq, Eq)]
1001pub enum ActionUsageBody {
1002    Semicolon,
1003    Brace {
1004        elements: Vec<Node<ActionUsageBodyElement>>,
1005    },
1006}
1007
1008/// Element inside an action usage body.
1009#[derive(Debug, Clone, PartialEq, Eq)]
1010pub enum ActionUsageBodyElement {
1011    Error(Node<ParseErrorNode>),
1012    Doc(Node<DocComment>),
1013    Annotation(Node<Annotation>),
1014    InOutDecl(Node<InOutDecl>),
1015    RefDecl(Node<RefDecl>),
1016    Bind(Node<Bind>),
1017    Flow(Node<Flow>),
1018    FirstStmt(Node<FirstStmt>),
1019    MergeStmt(Node<MergeStmt>),
1020    StateUsage(Node<StateUsage>),
1021    ActionUsage(Box<Node<ActionUsage>>),
1022    Assign(Node<AssignStmt>),
1023    ForLoop(Node<ForLoop>),
1024    ThenAction(Node<ThenAction>),
1025    Decl(Node<ActionBodyDecl>),
1026}
1027
1028/// A minimally-modeled declaration inside an action/behavior body (e.g. `attribute ...;`, `calc ...;`).
1029#[derive(Debug, Clone, PartialEq, Eq)]
1030pub struct ActionBodyDecl {
1031    pub keyword: String,
1032    pub text: String,
1033}
1034
1035/// Flow: `flow` from `to` to body.
1036#[derive(Debug, Clone, PartialEq, Eq)]
1037pub struct Flow {
1038    pub from: Node<Expression>,
1039    pub to: Node<Expression>,
1040    pub body: ConnectBody,
1041}
1042
1043/// Flow definition: `flow def` Identification body.
1044#[derive(Debug, Clone, PartialEq, Eq)]
1045pub struct FlowDef {
1046    pub identification: Identification,
1047    pub body: DefinitionBody,
1048}
1049
1050/// Flow usage: `flow` name (`:` type)? [`from` expr `to` expr]? body.
1051#[derive(Debug, Clone, PartialEq, Eq)]
1052pub struct FlowUsage {
1053    pub name: String,
1054    pub type_name: Option<String>,
1055    pub from: Option<Node<Expression>>,
1056    pub to: Option<Node<Expression>>,
1057    pub body: DefinitionBody,
1058}
1059
1060/// First/then control flow: `first` expr `then` expr body.
1061#[derive(Debug, Clone, PartialEq, Eq)]
1062pub struct FirstStmt {
1063    pub first: Node<Expression>,
1064    pub then: Node<Expression>,
1065    pub body: FirstMergeBody,
1066}
1067
1068/// Merge: `merge` expr body.
1069#[derive(Debug, Clone, PartialEq, Eq)]
1070pub struct MergeStmt {
1071    pub merge: Node<Expression>,
1072    pub body: FirstMergeBody,
1073}
1074
1075/// Body of first/merge: `;` or `{` ... `}`.
1076#[derive(Debug, Clone, PartialEq, Eq)]
1077pub enum FirstMergeBody {
1078    Semicolon,
1079    Brace,
1080}
1081
1082// ---------------------------------------------------------------------------
1083// Allocation
1084// ---------------------------------------------------------------------------
1085
1086/// Allocate statement at part usage level: `allocate` from `to` to body.
1087#[derive(Debug, Clone, PartialEq, Eq)]
1088pub struct Allocate {
1089    pub source: Node<Expression>,
1090    pub target: Node<Expression>,
1091    pub body: ConnectBody,
1092}
1093
1094/// Allocation definition: `allocation def` Identification body.
1095#[derive(Debug, Clone, PartialEq, Eq)]
1096pub struct AllocationDef {
1097    pub identification: Identification,
1098    pub body: DefinitionBody,
1099}
1100
1101/// Allocation usage: `allocation` name (`:` type)? [`allocate` source `to` target]? body.
1102#[derive(Debug, Clone, PartialEq, Eq)]
1103pub struct AllocationUsage {
1104    pub name: String,
1105    pub type_name: Option<String>,
1106    pub source: Option<Node<Expression>>,
1107    pub target: Option<Node<Expression>>,
1108    pub body: DefinitionBody,
1109}
1110
1111// ---------------------------------------------------------------------------
1112// Requirements
1113// ---------------------------------------------------------------------------
1114
1115/// Requirement definition: `requirement def` Identification body.
1116#[derive(Debug, Clone, PartialEq, Eq)]
1117pub struct RequirementDef {
1118    pub identification: Identification,
1119    pub body: RequirementDefBody,
1120}
1121
1122/// Body of an requirement definition: `;` or `{` RequirementDefBodyElement* `}`.
1123#[derive(Debug, Clone, PartialEq, Eq)]
1124pub enum RequirementDefBody {
1125    Semicolon,
1126    Brace {
1127        elements: Vec<Node<RequirementDefBodyElement>>,
1128    },
1129}
1130
1131#[derive(Debug, Clone, PartialEq, Eq)]
1132pub enum RequirementDefBodyElement {
1133    Error(Node<ParseErrorNode>),
1134    /// Unmodeled requirement-body element captured as raw text (used for library parsing).
1135    Other(String),
1136    Annotation(Node<Annotation>),
1137    Import(Node<Import>),
1138    SubjectDecl(Node<SubjectDecl>),
1139    AttributeDef(Node<AttributeDef>),
1140    AttributeUsage(Node<AttributeUsage>),
1141    VerifyRequirement(Node<VerifyRequirementMember>),
1142    RequireConstraint(Node<RequireConstraint>),
1143    Frame(Node<FrameMember>),
1144    Doc(Node<DocComment>),
1145}
1146
1147/// Subject declaration: `subject` name `:` type `;`.
1148#[derive(Debug, Clone, PartialEq, Eq)]
1149pub struct SubjectDecl {
1150    pub name: String,
1151    pub type_name: String,
1152}
1153
1154/// Require constraint: `require constraint { ... }`.
1155#[derive(Debug, Clone, PartialEq, Eq)]
1156pub struct RequireConstraint {
1157    pub body: RequireConstraintBody,
1158}
1159
1160/// Requirement verification usage in requirement/objective bodies:
1161/// `verify requirement <...>` or shorthand `verify <qualified_name>;`.
1162#[derive(Debug, Clone, PartialEq, Eq)]
1163pub struct VerifyRequirementMember {
1164    /// True for `verify requirement ...`; false for shorthand `verify ...;`.
1165    pub explicit_requirement_keyword: bool,
1166    /// Parsed requirement usage when explicit form is used.
1167    pub requirement: Option<Node<RequirementUsage>>,
1168    /// Shorthand verified requirement reference (`verify QualifiedName;`).
1169    pub target: Option<String>,
1170}
1171
1172/// Require constraint body: `;` or `{` ConstraintDefBodyElement* `}`.
1173#[derive(Debug, Clone, PartialEq, Eq)]
1174pub enum RequireConstraintBody {
1175    Semicolon,
1176    Brace {
1177        elements: Vec<Node<ConstraintDefBodyElement>>,
1178    },
1179}
1180
1181/// Requirement usage / Satisfy. Example: `satisfy EnduranceReq by droneInstance;`
1182#[derive(Debug, Clone, PartialEq, Eq)]
1183pub struct Satisfy {
1184    pub source: Node<Expression>,
1185    pub target: Node<Expression>,
1186    pub body: ConnectBody,
1187}
1188
1189/// Bare requirement Usage.
1190#[derive(Debug, Clone, PartialEq, Eq)]
1191pub struct RequirementUsage {
1192    pub name: String,
1193    pub type_name: Option<String>,
1194    pub subsets: Option<String>,
1195    pub body: RequirementDefBody,
1196}
1197
1198/// Dependency: `dependency` (Identification `from`)? client(s) `to` supplier(s) RelationshipBody.
1199#[derive(Debug, Clone, PartialEq, Eq)]
1200pub struct Dependency {
1201    pub identification: Option<Identification>,
1202    pub clients: Vec<String>,
1203    pub suppliers: Vec<String>,
1204    pub body: ConnectBody,
1205}
1206
1207/// Framed concern member in requirement body: `frame` name (`;` or body).
1208#[derive(Debug, Clone, PartialEq, Eq)]
1209pub struct FrameMember {
1210    pub name: String,
1211    pub body: RequirementDefBody,
1212}
1213
1214/// Concern usage at package level: `concern` name (`:` type)? RequirementBody.
1215#[derive(Debug, Clone, PartialEq, Eq)]
1216pub struct ConcernUsage {
1217    pub name: String,
1218    pub type_name: Option<String>,
1219    pub body: RequirementDefBody,
1220}
1221
1222/// Case definition: `case def` Identification body.
1223#[derive(Debug, Clone, PartialEq, Eq)]
1224pub struct CaseDef {
1225    pub identification: Identification,
1226    pub body: UseCaseDefBody,
1227}
1228
1229/// Case usage: `case` name (`:` type)? body.
1230#[derive(Debug, Clone, PartialEq, Eq)]
1231pub struct CaseUsage {
1232    pub name: String,
1233    pub type_name: Option<String>,
1234    pub body: UseCaseDefBody,
1235}
1236
1237/// Analysis case definition: `analysis def` Identification body.
1238#[derive(Debug, Clone, PartialEq, Eq)]
1239pub struct AnalysisCaseDef {
1240    pub identification: Identification,
1241    pub body: UseCaseDefBody,
1242}
1243
1244/// Analysis case usage: `analysis` name (`:` type)? body.
1245#[derive(Debug, Clone, PartialEq, Eq)]
1246pub struct AnalysisCaseUsage {
1247    pub name: String,
1248    pub type_name: Option<String>,
1249    pub body: UseCaseDefBody,
1250}
1251
1252/// Verification case definition: `verification def` Identification body.
1253#[derive(Debug, Clone, PartialEq, Eq)]
1254pub struct VerificationCaseDef {
1255    pub identification: Identification,
1256    pub body: UseCaseDefBody,
1257}
1258
1259/// Verification case usage: `verification` name (`:` type)? body.
1260#[derive(Debug, Clone, PartialEq, Eq)]
1261pub struct VerificationCaseUsage {
1262    pub name: String,
1263    pub type_name: Option<String>,
1264    pub body: UseCaseDefBody,
1265}
1266
1267/// Use case usage at package level: `use case` name (`:` type)? CaseBody.
1268#[derive(Debug, Clone, PartialEq, Eq)]
1269pub struct UseCaseUsage {
1270    pub name: String,
1271    pub type_name: Option<String>,
1272    pub body: UseCaseDefBody,
1273}
1274
1275// ---------------------------------------------------------------------------
1276// Use Cases
1277// ---------------------------------------------------------------------------
1278
1279/// Actor declaration: `actor` Identification `;`.
1280#[derive(Debug, Clone, PartialEq, Eq)]
1281pub struct ActorDecl {
1282    pub identification: Identification,
1283}
1284
1285/// Use Case definition: `use case def` Identification body.
1286#[derive(Debug, Clone, PartialEq, Eq)]
1287pub struct UseCaseDef {
1288    pub identification: Identification,
1289    pub body: UseCaseDefBody,
1290}
1291
1292#[derive(Debug, Clone, PartialEq, Eq)]
1293pub enum UseCaseDefBody {
1294    Semicolon,
1295    Brace {
1296        elements: Vec<Node<UseCaseDefBodyElement>>,
1297    },
1298}
1299
1300/// `first <name>;` inside a case/use-case body (used in SysML v2 release fixtures).
1301#[derive(Debug, Clone, PartialEq, Eq)]
1302pub struct FirstSuccession {
1303    pub target: String,
1304}
1305
1306/// `then done;` inside a case/use-case body.
1307#[derive(Debug, Clone, PartialEq, Eq)]
1308pub struct ThenDone {}
1309
1310/// `include <usecase> ...` inside a case/use-case body.
1311#[derive(Debug, Clone, PartialEq, Eq)]
1312pub struct IncludeUseCase {
1313    pub name: String,
1314    /// Optional multiplicity suffix like `[0..*]` captured as raw text including brackets.
1315    pub multiplicity: Option<String>,
1316    pub body: UseCaseDefBody,
1317}
1318
1319/// `then include <usecase> ...` inside a case/use-case body.
1320#[derive(Debug, Clone, PartialEq, Eq)]
1321pub struct ThenIncludeUseCase {
1322    pub include: Node<IncludeUseCase>,
1323}
1324
1325/// `then use case <name> ...` inside a case/use-case body.
1326#[derive(Debug, Clone, PartialEq, Eq)]
1327pub struct ThenUseCaseUsage {
1328    pub use_case: Node<UseCaseUsage>,
1329}
1330
1331/// `subject;` shorthand used in SysML v2 release fixtures (subject of an enclosing case/use case).
1332#[derive(Debug, Clone, PartialEq, Eq)]
1333pub struct SubjectRef {}
1334
1335/// `actor :>> <name> = <expr>;` redefinition/assignment used in SysML v2 release fixtures.
1336#[derive(Debug, Clone, PartialEq, Eq)]
1337pub struct ActorRedefinitionAssignment {
1338    pub name: String,
1339    /// Raw RHS expression text up to `;` (we don't model the expression grammar here yet).
1340    pub rhs: String,
1341}
1342
1343/// `ref :>> <name> { ... }` redefinition used in SysML v2 release fixtures.
1344#[derive(Debug, Clone, PartialEq, Eq)]
1345pub struct RefRedefinition {
1346    pub name: String,
1347    /// Raw body text for now (balanced `{ ... }` including nested braces).
1348    pub body: String,
1349}
1350
1351/// `return ref <name><multiplicity?> { ... }` used in SysML v2 release libraries.
1352#[derive(Debug, Clone, PartialEq, Eq)]
1353pub struct ReturnRef {
1354    pub name: String,
1355    pub multiplicity: Option<String>,
1356    /// Raw body text for now (balanced `{ ... }` including nested braces).
1357    pub body: String,
1358}
1359
1360#[derive(Debug, Clone, PartialEq, Eq)]
1361pub enum UseCaseDefBodyElement {
1362    Error(Node<ParseErrorNode>),
1363    /// Unmodeled use-case / analysis-case body element captured as raw text (used for library parsing).
1364    Other(String),
1365    AttributeDef(Node<AttributeDef>),
1366    Doc(Node<DocComment>),
1367    SubjectDecl(Node<SubjectDecl>),
1368    /// `subject;` shorthand.
1369    SubjectRef(Node<SubjectRef>),
1370    ActorUsage(Node<ActorUsage>),
1371    ActorRedefinitionAssignment(Node<ActorRedefinitionAssignment>),
1372    Objective(Node<Objective>),
1373    FirstSuccession(Node<FirstSuccession>),
1374    ThenIncludeUseCase(Node<ThenIncludeUseCase>),
1375    ThenUseCaseUsage(Node<ThenUseCaseUsage>),
1376    ThenDone(Node<ThenDone>),
1377    IncludeUseCase(Node<IncludeUseCase>),
1378    RefRedefinition(Node<RefRedefinition>),
1379    ReturnRef(Node<ReturnRef>),
1380    Assign(Node<AssignStmt>),
1381    ForLoop(Node<ForLoop>),
1382    ThenAction(Node<ThenAction>),
1383}
1384
1385/// actor usage `actor pilot : Operator;`
1386#[derive(Debug, Clone, PartialEq, Eq)]
1387pub struct ActorUsage {
1388    pub name: String,
1389    pub type_name: String,
1390}
1391
1392/// Objective `objective { doc ... }`
1393#[derive(Debug, Clone, PartialEq, Eq)]
1394pub struct Objective {
1395    pub visibility: Option<Visibility>,
1396    pub requirement: Node<RequirementUsage>,
1397}
1398
1399// ---------------------------------------------------------------------------
1400// State Machine
1401// ---------------------------------------------------------------------------
1402
1403/// State definition: `state def` Identification body.
1404#[derive(Debug, Clone, PartialEq, Eq)]
1405pub struct StateDef {
1406    pub identification: Identification,
1407    pub body: StateDefBody,
1408}
1409
1410#[derive(Debug, Clone, PartialEq, Eq)]
1411pub enum StateDefBody {
1412    Semicolon,
1413    Brace {
1414        elements: Vec<Node<StateDefBodyElement>>,
1415    },
1416}
1417
1418#[derive(Debug, Clone, PartialEq, Eq)]
1419pub enum StateDefBodyElement {
1420    Error(Node<ParseErrorNode>),
1421    Doc(Node<DocComment>),
1422    Annotation(Node<Annotation>),
1423    Other(String),
1424    /// `entry` (`;` or body) - entry action.
1425    Entry(Node<EntryAction>),
1426    /// `then` name `;` - initial state.
1427    Then(Node<ThenStmt>),
1428    /// `ref` name `:` type body – reference binding in state.
1429    Ref(Node<RefDecl>),
1430    RequirementUsage(Node<RequirementUsage>),
1431    StateUsage(Node<StateUsage>),
1432    Transition(Node<Transition>),
1433}
1434
1435/// Entry action: `entry` (`;` or body).
1436#[derive(Debug, Clone, PartialEq, Eq)]
1437pub struct EntryAction {
1438    /// For `entry action name body` form; None for plain `entry` body.
1439    pub action_name: Option<String>,
1440    pub body: StateDefBody,
1441}
1442
1443/// Then (initial state): `then` name `;`
1444#[derive(Debug, Clone, PartialEq, Eq)]
1445pub struct ThenStmt {
1446    pub state_name: String,
1447}
1448
1449/// State usage: `state` name (`:` type)? body.
1450#[derive(Debug, Clone, PartialEq, Eq)]
1451pub struct StateUsage {
1452    pub name: String,
1453    pub type_name: Option<String>,
1454    pub body: StateDefBody,
1455}
1456
1457/// Transition: `transition` name [`first` source] [`if` guard] [`do` effect] `then` target body.
1458#[derive(Debug, Clone, PartialEq, Eq)]
1459pub struct Transition {
1460    pub name: Option<String>,
1461    /// If omitted, form is `transition name then target;`.
1462    pub source: Option<Node<Expression>>,
1463    pub guard: Option<Node<Expression>>,
1464    pub effect: Option<Node<Expression>>,
1465    pub target: Node<Expression>,
1466    pub body: ConnectBody,
1467}
1468
1469// ---------------------------------------------------------------------------
1470// Constraints & Calculations
1471// ---------------------------------------------------------------------------
1472
1473/// Constraint definition: `constraint def` Identification body.
1474#[derive(Debug, Clone, PartialEq, Eq)]
1475pub struct ConstraintDef {
1476    pub identification: Identification,
1477    pub body: ConstraintDefBody,
1478}
1479
1480#[derive(Debug, Clone, PartialEq, Eq)]
1481pub enum ConstraintDefBody {
1482    Semicolon,
1483    Brace {
1484        elements: Vec<Node<ConstraintDefBodyElement>>,
1485    },
1486}
1487
1488#[derive(Debug, Clone, PartialEq, Eq)]
1489pub enum ConstraintDefBodyElement {
1490    Error(Node<ParseErrorNode>),
1491    Doc(Node<DocComment>),
1492    InOutDecl(Node<InOutDecl>),
1493    Expression(Node<Expression>), // e.g. totalThrust >= totalWeight * margin
1494    /// Unmodeled constraint-body element captured as raw text (used for library parsing).
1495    Other(String),
1496}
1497
1498/// constraint body {}
1499#[derive(Debug, Clone, PartialEq, Eq)]
1500pub enum ConstraintBody {
1501    Semicolon,
1502    Brace, // Often contains docs or block of expressions
1503}
1504
1505/// KerML Documentation: 'doc' Identification? ( 'locale' STRING_VALUE )? body = REGULAR_COMMENT.
1506#[derive(Debug, Clone, PartialEq, Eq)]
1507pub struct DocComment {
1508    /// Optional identification after 'doc'.
1509    pub identification: Option<Identification>,
1510    /// Optional locale string (e.g. "en").
1511    pub locale: Option<String>,
1512    /// Body text (content between /* and */).
1513    pub text: String,
1514}
1515
1516/// KerML Comment: ( 'comment' Identification? )? ( 'locale' STRING_VALUE )? body = REGULAR_COMMENT.
1517#[derive(Debug, Clone, PartialEq, Eq)]
1518pub struct CommentAnnotation {
1519    pub identification: Option<Identification>,
1520    pub locale: Option<String>,
1521    pub text: String,
1522}
1523
1524/// KerML TextualRepresentation: ( 'rep' Identification )? 'language' STRING_VALUE body.
1525#[derive(Debug, Clone, PartialEq, Eq)]
1526pub struct TextualRepresentation {
1527    pub rep_identification: Option<Identification>,
1528    pub language: String,
1529    pub text: String,
1530}
1531
1532/// Calc definition: `calc def` Identification body.
1533#[derive(Debug, Clone, PartialEq, Eq)]
1534pub struct CalcDef {
1535    pub identification: Identification,
1536    pub body: CalcDefBody,
1537}
1538
1539#[derive(Debug, Clone, PartialEq, Eq)]
1540pub enum CalcDefBody {
1541    Semicolon,
1542    Brace {
1543        elements: Vec<Node<CalcDefBodyElement>>,
1544    },
1545}
1546
1547#[derive(Debug, Clone, PartialEq, Eq)]
1548pub enum CalcDefBodyElement {
1549    Error(Node<ParseErrorNode>),
1550    Doc(Node<DocComment>),
1551    InOutDecl(Node<InOutDecl>),
1552    ReturnDecl(Node<ReturnDecl>),
1553    Expression(Node<Expression>), // formula
1554    /// Unmodeled calc-body element captured as raw text (used for library parsing).
1555    Other(String),
1556}
1557
1558/// Return declaration: `return` name `:` type `;`.
1559#[derive(Debug, Clone, PartialEq, Eq)]
1560pub struct ReturnDecl {
1561    pub name: String,
1562    pub type_name: String,
1563}
1564
1565// ---------------------------------------------------------------------------
1566// Views and Viewpoints (SysML v2 Clause 8.2.2.26)
1567// ---------------------------------------------------------------------------
1568
1569/// View definition: `view def` Identification ViewDefinitionBody.
1570#[derive(Debug, Clone, PartialEq, Eq)]
1571pub struct ViewDef {
1572    pub identification: Identification,
1573    pub body: ViewDefBody,
1574}
1575
1576#[derive(Debug, Clone, PartialEq, Eq)]
1577pub enum ViewDefBody {
1578    Semicolon,
1579    Brace {
1580        elements: Vec<Node<ViewDefBodyElement>>,
1581    },
1582}
1583
1584#[derive(Debug, Clone, PartialEq, Eq)]
1585pub enum ViewDefBodyElement {
1586    Error(Node<ParseErrorNode>),
1587    /// Unmodeled view-definition body element captured as raw text (used for library parsing).
1588    Other(String),
1589    Doc(Node<DocComment>),
1590    Filter(Node<FilterMember>),
1591    ViewRendering(Node<ViewRenderingUsage>),
1592}
1593
1594/// View rendering usage: `render` name `:` type (`;` or body).
1595#[derive(Debug, Clone, PartialEq, Eq)]
1596pub struct ViewRenderingUsage {
1597    pub name: String,
1598    pub type_name: Option<String>,
1599    pub body: ConnectBody,
1600}
1601
1602/// Viewpoint definition: `viewpoint def` Identification RequirementBody.
1603#[derive(Debug, Clone, PartialEq, Eq)]
1604pub struct ViewpointDef {
1605    pub identification: Identification,
1606    pub body: RequirementDefBody,
1607}
1608
1609/// Rendering definition: `rendering def` Definition.
1610#[derive(Debug, Clone, PartialEq, Eq)]
1611pub struct RenderingDef {
1612    pub identification: Identification,
1613    pub body: RenderingDefBody,
1614}
1615
1616#[derive(Debug, Clone, PartialEq, Eq)]
1617pub enum RenderingDefBody {
1618    Semicolon,
1619    Brace,
1620}
1621
1622/// View usage: `view` name `:` type? ViewBody.
1623#[derive(Debug, Clone, PartialEq, Eq)]
1624pub struct ViewUsage {
1625    pub name: String,
1626    pub type_name: Option<String>,
1627    pub body: ViewBody,
1628}
1629
1630#[derive(Debug, Clone, PartialEq, Eq)]
1631pub enum ViewBody {
1632    Semicolon,
1633    Brace {
1634        elements: Vec<Node<ViewBodyElement>>,
1635    },
1636}
1637
1638#[derive(Debug, Clone, PartialEq, Eq)]
1639pub enum ViewBodyElement {
1640    Error(Node<ParseErrorNode>),
1641    /// Unmodeled view body element captured as raw text (used for library parsing).
1642    Other(String),
1643    Doc(Node<DocComment>),
1644    Filter(Node<FilterMember>),
1645    ViewRendering(Node<ViewRenderingUsage>),
1646    Expose(Node<ExposeMember>),
1647    Satisfy(Node<SatisfyViewMember>),
1648}
1649
1650/// Expose in view body: `expose` (MembershipImport | NamespaceImport) RelationshipBody.
1651#[derive(Debug, Clone, PartialEq, Eq)]
1652pub struct ExposeMember {
1653    /// Full target path (e.g. vehicle, vehicle::*, vehicle::*::**, SystemModel::vehicle::**).
1654    pub target: String,
1655    pub body: ConnectBody,
1656}
1657
1658/// Satisfy in view body: `satisfy` QualifiedName RelationshipBody.
1659#[derive(Debug, Clone, PartialEq, Eq)]
1660pub struct SatisfyViewMember {
1661    pub viewpoint_ref: String,
1662    pub body: ConnectBody,
1663}
1664
1665/// Viewpoint usage: `viewpoint` ConstraintUsageDeclaration RequirementBody.
1666#[derive(Debug, Clone, PartialEq, Eq)]
1667pub struct ViewpointUsage {
1668    pub name: String,
1669    pub type_name: String,
1670    pub body: RequirementDefBody,
1671}
1672
1673/// Rendering usage: `rendering` Usage.
1674#[derive(Debug, Clone, PartialEq, Eq)]
1675pub struct RenderingUsage {
1676    pub name: String,
1677    pub type_name: Option<String>,
1678    pub body: ConnectBody,
1679}
1680
1681// ---------------------------------------------------------------------------
1682// Normalization for test comparison (strips optional spans so parsed == expected)
1683// ---------------------------------------------------------------------------
1684
1685impl RootNamespace {
1686    /// Returns a copy with all optional source spans set to `None` and all `Node` spans set to
1687    /// `Span::dummy()`. Use when comparing parser output to hand-built expected AST in tests.
1688    pub fn normalize_for_test_comparison(&self) -> Self {
1689        RootNamespace {
1690            elements: self
1691                .elements
1692                .iter()
1693                .map(normalize_root_element_node)
1694                .collect(),
1695        }
1696    }
1697}
1698
1699fn dummy_node<T: Clone>(_n: &Node<T>, value: T) -> Node<T> {
1700    Node::new(Span::dummy(), value)
1701}
1702
1703fn normalize_root_element_node(el: &Node<RootElement>) -> Node<RootElement> {
1704    let value = match &el.value {
1705        RootElement::Package(p) => RootElement::Package(dummy_node(p, normalize_package(&p.value))),
1706        RootElement::LibraryPackage(lp) => {
1707            RootElement::LibraryPackage(dummy_node(lp, normalize_library_package(&lp.value)))
1708        }
1709        RootElement::Namespace(n) => {
1710            RootElement::Namespace(dummy_node(n, normalize_namespace_decl(&n.value)))
1711        }
1712        RootElement::Import(n) => RootElement::Import(dummy_node(n, n.value.clone())),
1713    };
1714    dummy_node(el, value)
1715}
1716
1717fn normalize_library_package(lp: &LibraryPackage) -> LibraryPackage {
1718    LibraryPackage {
1719        is_standard: lp.is_standard,
1720        identification: lp.identification.clone(),
1721        body: normalize_package_body(&lp.body),
1722    }
1723}
1724
1725fn normalize_namespace_decl(n: &NamespaceDecl) -> NamespaceDecl {
1726    NamespaceDecl {
1727        identification: n.identification.clone(),
1728        body: normalize_package_body(&n.body),
1729    }
1730}
1731
1732fn normalize_package(p: &Package) -> Package {
1733    Package {
1734        identification: p.identification.clone(),
1735        body: normalize_package_body(&p.body),
1736    }
1737}
1738
1739fn normalize_package_body(b: &PackageBody) -> PackageBody {
1740    match b {
1741        PackageBody::Semicolon => PackageBody::Semicolon,
1742        PackageBody::Brace { elements } => PackageBody::Brace {
1743            elements: elements
1744                .iter()
1745                .map(normalize_package_body_element_node)
1746                .collect(),
1747        },
1748    }
1749}
1750
1751fn normalize_package_body_element_node(el: &Node<PackageBodyElement>) -> Node<PackageBodyElement> {
1752    let value = match &el.value {
1753        PackageBodyElement::Error(n) => PackageBodyElement::Error(dummy_node(n, n.value.clone())),
1754        PackageBodyElement::Doc(n) => PackageBodyElement::Doc(dummy_node(n, n.value.clone())),
1755        PackageBodyElement::Comment(n) => {
1756            PackageBodyElement::Comment(dummy_node(n, n.value.clone()))
1757        }
1758        PackageBodyElement::TextualRep(n) => {
1759            PackageBodyElement::TextualRep(dummy_node(n, n.value.clone()))
1760        }
1761        PackageBodyElement::Filter(n) => PackageBodyElement::Filter(dummy_node(n, n.value.clone())),
1762        PackageBodyElement::Package(n) => {
1763            PackageBodyElement::Package(dummy_node(n, normalize_package(&n.value)))
1764        }
1765        PackageBodyElement::LibraryPackage(n) => {
1766            PackageBodyElement::LibraryPackage(dummy_node(n, normalize_library_package(&n.value)))
1767        }
1768        PackageBodyElement::Import(n) => PackageBodyElement::Import(dummy_node(n, n.value.clone())),
1769        PackageBodyElement::PartDef(n) => {
1770            PackageBodyElement::PartDef(dummy_node(n, normalize_part_def(&n.value)))
1771        }
1772        PackageBodyElement::PartUsage(n) => {
1773            PackageBodyElement::PartUsage(dummy_node(n, normalize_part_usage(&n.value)))
1774        }
1775        PackageBodyElement::PortDef(n) => {
1776            PackageBodyElement::PortDef(dummy_node(n, normalize_port_def(&n.value)))
1777        }
1778        PackageBodyElement::InterfaceDef(n) => {
1779            PackageBodyElement::InterfaceDef(dummy_node(n, normalize_interface_def(&n.value)))
1780        }
1781        PackageBodyElement::ConnectionDef(n) => {
1782            PackageBodyElement::ConnectionDef(dummy_node(n, normalize_connection_def(&n.value)))
1783        }
1784        PackageBodyElement::MetadataDef(n) => {
1785            PackageBodyElement::MetadataDef(dummy_node(n, normalize_metadata_def(&n.value)))
1786        }
1787        PackageBodyElement::EnumDef(n) => {
1788            PackageBodyElement::EnumDef(dummy_node(n, normalize_enum_def(&n.value)))
1789        }
1790        PackageBodyElement::OccurrenceDef(n) => {
1791            PackageBodyElement::OccurrenceDef(dummy_node(n, normalize_occurrence_def(&n.value)))
1792        }
1793        PackageBodyElement::OccurrenceUsage(n) => {
1794            PackageBodyElement::OccurrenceUsage(dummy_node(n, n.value.clone()))
1795        }
1796        PackageBodyElement::AliasDef(n) => {
1797            PackageBodyElement::AliasDef(dummy_node(n, n.value.clone()))
1798        }
1799        PackageBodyElement::AttributeDef(n) => {
1800            PackageBodyElement::AttributeDef(dummy_node(n, normalize_attribute_def(&n.value)))
1801        }
1802        PackageBodyElement::ActionDef(n) => {
1803            PackageBodyElement::ActionDef(dummy_node(n, normalize_action_def(&n.value)))
1804        }
1805        PackageBodyElement::ActionUsage(n) => {
1806            PackageBodyElement::ActionUsage(dummy_node(n, normalize_action_usage(&n.value)))
1807        }
1808        PackageBodyElement::RequirementDef(n) => {
1809            PackageBodyElement::RequirementDef(dummy_node(n, n.value.clone()))
1810        }
1811        PackageBodyElement::RequirementUsage(n) => {
1812            PackageBodyElement::RequirementUsage(dummy_node(n, n.value.clone()))
1813        }
1814        PackageBodyElement::Satisfy(n) => {
1815            PackageBodyElement::Satisfy(dummy_node(n, n.value.clone()))
1816        }
1817        PackageBodyElement::UseCaseDef(n) => {
1818            PackageBodyElement::UseCaseDef(dummy_node(n, n.value.clone()))
1819        }
1820        PackageBodyElement::Actor(n) => PackageBodyElement::Actor(dummy_node(n, n.value.clone())),
1821        PackageBodyElement::StateDef(n) => {
1822            PackageBodyElement::StateDef(dummy_node(n, n.value.clone()))
1823        }
1824        PackageBodyElement::StateUsage(n) => {
1825            PackageBodyElement::StateUsage(dummy_node(n, n.value.clone()))
1826        }
1827        PackageBodyElement::ItemDef(n) => {
1828            PackageBodyElement::ItemDef(dummy_node(n, n.value.clone()))
1829        }
1830        PackageBodyElement::IndividualDef(n) => {
1831            PackageBodyElement::IndividualDef(dummy_node(n, n.value.clone()))
1832        }
1833        PackageBodyElement::ConstraintDef(n) => {
1834            PackageBodyElement::ConstraintDef(dummy_node(n, n.value.clone()))
1835        }
1836        PackageBodyElement::CalcDef(n) => {
1837            PackageBodyElement::CalcDef(dummy_node(n, n.value.clone()))
1838        }
1839        PackageBodyElement::ViewDef(n) => {
1840            PackageBodyElement::ViewDef(dummy_node(n, n.value.clone()))
1841        }
1842        PackageBodyElement::ViewpointDef(n) => {
1843            PackageBodyElement::ViewpointDef(dummy_node(n, n.value.clone()))
1844        }
1845        PackageBodyElement::RenderingDef(n) => {
1846            PackageBodyElement::RenderingDef(dummy_node(n, n.value.clone()))
1847        }
1848        PackageBodyElement::ViewUsage(n) => {
1849            PackageBodyElement::ViewUsage(dummy_node(n, n.value.clone()))
1850        }
1851        PackageBodyElement::ViewpointUsage(n) => {
1852            PackageBodyElement::ViewpointUsage(dummy_node(n, n.value.clone()))
1853        }
1854        PackageBodyElement::RenderingUsage(n) => {
1855            PackageBodyElement::RenderingUsage(dummy_node(n, n.value.clone()))
1856        }
1857        PackageBodyElement::Dependency(n) => {
1858            PackageBodyElement::Dependency(dummy_node(n, n.value.clone()))
1859        }
1860        PackageBodyElement::AllocationDef(n) => {
1861            PackageBodyElement::AllocationDef(dummy_node(n, n.value.clone()))
1862        }
1863        PackageBodyElement::AllocationUsage(n) => {
1864            PackageBodyElement::AllocationUsage(dummy_node(n, n.value.clone()))
1865        }
1866        PackageBodyElement::FlowDef(n) => {
1867            PackageBodyElement::FlowDef(dummy_node(n, n.value.clone()))
1868        }
1869        PackageBodyElement::FlowUsage(n) => {
1870            PackageBodyElement::FlowUsage(dummy_node(n, n.value.clone()))
1871        }
1872        PackageBodyElement::ConcernUsage(n) => {
1873            PackageBodyElement::ConcernUsage(dummy_node(n, n.value.clone()))
1874        }
1875        PackageBodyElement::CaseDef(n) => {
1876            PackageBodyElement::CaseDef(dummy_node(n, n.value.clone()))
1877        }
1878        PackageBodyElement::CaseUsage(n) => {
1879            PackageBodyElement::CaseUsage(dummy_node(n, n.value.clone()))
1880        }
1881        PackageBodyElement::AnalysisCaseDef(n) => {
1882            PackageBodyElement::AnalysisCaseDef(dummy_node(n, n.value.clone()))
1883        }
1884        PackageBodyElement::AnalysisCaseUsage(n) => {
1885            PackageBodyElement::AnalysisCaseUsage(dummy_node(n, n.value.clone()))
1886        }
1887        PackageBodyElement::VerificationCaseDef(n) => {
1888            PackageBodyElement::VerificationCaseDef(dummy_node(n, n.value.clone()))
1889        }
1890        PackageBodyElement::VerificationCaseUsage(n) => {
1891            PackageBodyElement::VerificationCaseUsage(dummy_node(n, n.value.clone()))
1892        }
1893        PackageBodyElement::UseCaseUsage(n) => {
1894            PackageBodyElement::UseCaseUsage(dummy_node(n, n.value.clone()))
1895        }
1896        PackageBodyElement::FeatureDecl(n) => {
1897            PackageBodyElement::FeatureDecl(dummy_node(n, n.value.clone()))
1898        }
1899        PackageBodyElement::ClassifierDecl(n) => {
1900            PackageBodyElement::ClassifierDecl(dummy_node(n, n.value.clone()))
1901        }
1902        PackageBodyElement::KermlSemanticDecl(n) => {
1903            PackageBodyElement::KermlSemanticDecl(dummy_node(n, n.value.clone()))
1904        }
1905        PackageBodyElement::KermlFeatureDecl(n) => {
1906            PackageBodyElement::KermlFeatureDecl(dummy_node(n, n.value.clone()))
1907        }
1908        PackageBodyElement::ExtendedLibraryDecl(n) => {
1909            PackageBodyElement::ExtendedLibraryDecl(dummy_node(n, n.value.clone()))
1910        }
1911    };
1912    dummy_node(el, value)
1913}
1914
1915fn normalize_attribute_def(a: &AttributeDef) -> AttributeDef {
1916    AttributeDef {
1917        name: a.name.clone(),
1918        typing: a.typing.clone(),
1919        value: a.value.clone(),
1920        body: a.body.clone(),
1921        name_span: None,
1922        typing_span: None,
1923    }
1924}
1925
1926fn normalize_part_def(p: &PartDef) -> PartDef {
1927    PartDef {
1928        definition_prefix: p.definition_prefix.clone(),
1929        is_individual: p.is_individual,
1930        identification: p.identification.clone(),
1931        specializes: p.specializes.clone(),
1932        specializes_span: None,
1933        body: normalize_part_def_body(&p.body),
1934    }
1935}
1936
1937fn normalize_part_def_body(b: &PartDefBody) -> PartDefBody {
1938    match b {
1939        PartDefBody::Semicolon => PartDefBody::Semicolon,
1940        PartDefBody::Brace { elements } => PartDefBody::Brace {
1941            elements: elements
1942                .iter()
1943                .map(normalize_part_def_body_element_node)
1944                .collect(),
1945        },
1946    }
1947}
1948
1949fn normalize_part_def_body_element_node(el: &Node<PartDefBodyElement>) -> Node<PartDefBodyElement> {
1950    let value = match &el.value {
1951        PartDefBodyElement::Error(n) => PartDefBodyElement::Error(dummy_node(n, n.value.clone())),
1952        PartDefBodyElement::Doc(n) => PartDefBodyElement::Doc(dummy_node(n, n.value.clone())),
1953        PartDefBodyElement::Comment(n) => {
1954            PartDefBodyElement::Comment(dummy_node(n, n.value.clone()))
1955        }
1956        PartDefBodyElement::Annotation(n) => {
1957            PartDefBodyElement::Annotation(dummy_node(n, n.value.clone()))
1958        }
1959        PartDefBodyElement::Other(text) => PartDefBodyElement::Other(text.clone()),
1960        PartDefBodyElement::AttributeDef(n) => {
1961            PartDefBodyElement::AttributeDef(dummy_node(n, normalize_attribute_def(&n.value)))
1962        }
1963        PartDefBodyElement::AttributeUsage(n) => {
1964            PartDefBodyElement::AttributeUsage(dummy_node(n, normalize_attribute_usage(&n.value)))
1965        }
1966        PartDefBodyElement::RequirementUsage(n) => {
1967            PartDefBodyElement::RequirementUsage(dummy_node(n, n.value.clone()))
1968        }
1969        PartDefBodyElement::Ref(n) => {
1970            PartDefBodyElement::Ref(dummy_node(n, normalize_ref_decl(&n.value)))
1971        }
1972        PartDefBodyElement::PortUsage(n) => {
1973            PartDefBodyElement::PortUsage(dummy_node(n, normalize_port_usage(&n.value)))
1974        }
1975        PartDefBodyElement::PartUsage(n) => {
1976            PartDefBodyElement::PartUsage(Box::new(dummy_node(n, normalize_part_usage(&n.value))))
1977        }
1978        PartDefBodyElement::OccurrenceUsage(n) => {
1979            PartDefBodyElement::OccurrenceUsage(Box::new(dummy_node(n, n.value.clone())))
1980        }
1981        PartDefBodyElement::InterfaceDef(n) => {
1982            PartDefBodyElement::InterfaceDef(dummy_node(n, normalize_interface_def(&n.value)))
1983        }
1984        PartDefBodyElement::InterfaceUsage(n) => {
1985            PartDefBodyElement::InterfaceUsage(dummy_node(n, n.value.clone()))
1986        }
1987        PartDefBodyElement::Connect(n) => {
1988            PartDefBodyElement::Connect(dummy_node(n, n.value.clone()))
1989        }
1990        PartDefBodyElement::Connection(n) => {
1991            PartDefBodyElement::Connection(dummy_node(n, n.value.clone()))
1992        }
1993        PartDefBodyElement::Perform(n) => {
1994            PartDefBodyElement::Perform(dummy_node(n, n.value.clone()))
1995        }
1996        PartDefBodyElement::Allocate(n) => {
1997            PartDefBodyElement::Allocate(dummy_node(n, n.value.clone()))
1998        }
1999        PartDefBodyElement::OpaqueMember(n) => {
2000            PartDefBodyElement::OpaqueMember(dummy_node(n, n.value.clone()))
2001        }
2002        PartDefBodyElement::ExhibitState(n) => {
2003            PartDefBodyElement::ExhibitState(dummy_node(n, n.value.clone()))
2004        }
2005    };
2006    dummy_node(el, value)
2007}
2008
2009fn normalize_attribute_usage(a: &AttributeUsage) -> AttributeUsage {
2010    AttributeUsage {
2011        name: a.name.clone(),
2012        typing: a.typing.clone(),
2013        redefines: a.redefines.clone(),
2014        value: a.value.clone(),
2015        body: a.body.clone(),
2016        name_span: None,
2017        typing_span: None,
2018        redefines_span: None,
2019    }
2020}
2021
2022fn normalize_part_usage(p: &PartUsage) -> PartUsage {
2023    PartUsage {
2024        is_individual: p.is_individual,
2025        name: p.name.clone(),
2026        type_name: p.type_name.clone(),
2027        multiplicity: p.multiplicity.clone(),
2028        ordered: p.ordered,
2029        subsets: p.subsets.clone(),
2030        redefines: p.redefines.clone(),
2031        value: p.value.clone(),
2032        body: normalize_part_usage_body(&p.body),
2033        name_span: None,
2034        type_ref_span: None,
2035    }
2036}
2037
2038fn normalize_part_usage_body(b: &PartUsageBody) -> PartUsageBody {
2039    match b {
2040        PartUsageBody::Semicolon => PartUsageBody::Semicolon,
2041        PartUsageBody::Brace { elements } => PartUsageBody::Brace {
2042            elements: elements
2043                .iter()
2044                .map(normalize_part_usage_body_element_node)
2045                .collect(),
2046        },
2047    }
2048}
2049
2050fn normalize_perform(p: &Perform) -> Perform {
2051    Perform {
2052        action_name: p.action_name.clone(),
2053        type_name: p.type_name.clone(),
2054        body: normalize_perform_body(&p.body),
2055    }
2056}
2057
2058fn normalize_perform_body(b: &PerformBody) -> PerformBody {
2059    match b {
2060        PerformBody::Semicolon => PerformBody::Semicolon,
2061        PerformBody::Brace { elements } => PerformBody::Brace {
2062            elements: elements
2063                .iter()
2064                .map(normalize_perform_body_element_node)
2065                .collect(),
2066        },
2067    }
2068}
2069
2070fn normalize_perform_body_element_node(el: &Node<PerformBodyElement>) -> Node<PerformBodyElement> {
2071    let value = match &el.value {
2072        PerformBodyElement::Doc(n) => PerformBodyElement::Doc(dummy_node(n, n.value.clone())),
2073        PerformBodyElement::InOut(n) => PerformBodyElement::InOut(dummy_node(
2074            n,
2075            PerformInOutBinding {
2076                direction: n.value.direction,
2077                name: n.value.name.clone(),
2078                value: normalize_expression_node(&n.value.value),
2079            },
2080        )),
2081    };
2082    dummy_node(el, value)
2083}
2084
2085fn normalize_expression_node(node: &Node<Expression>) -> Node<Expression> {
2086    let value = match &node.value {
2087        Expression::LiteralInteger(x) => Expression::LiteralInteger(*x),
2088        Expression::LiteralReal(s) => Expression::LiteralReal(s.clone()),
2089        Expression::LiteralString(s) => Expression::LiteralString(s.clone()),
2090        Expression::LiteralBoolean(b) => Expression::LiteralBoolean(*b),
2091        Expression::FeatureRef(s) => Expression::FeatureRef(s.clone()),
2092        Expression::MemberAccess(base, member) => {
2093            Expression::MemberAccess(Box::new(normalize_expression_node(base)), member.clone())
2094        }
2095        Expression::Index { base, index } => Expression::Index {
2096            base: Box::new(normalize_expression_node(base)),
2097            index: Box::new(normalize_expression_node(index)),
2098        },
2099        Expression::Bracket(inner) => {
2100            Expression::Bracket(Box::new(normalize_expression_node(inner)))
2101        }
2102        Expression::LiteralWithUnit { value: v, unit } => Expression::LiteralWithUnit {
2103            value: Box::new(normalize_expression_node(v)),
2104            unit: Box::new(normalize_expression_node(unit)),
2105        },
2106        Expression::BinaryOp { op, left, right } => Expression::BinaryOp {
2107            op: op.clone(),
2108            left: Box::new(normalize_expression_node(left)),
2109            right: Box::new(normalize_expression_node(right)),
2110        },
2111        Expression::UnaryOp { op, operand } => Expression::UnaryOp {
2112            op: op.clone(),
2113            operand: Box::new(normalize_expression_node(operand)),
2114        },
2115        Expression::Invocation { callee, args } => Expression::Invocation {
2116            callee: Box::new(normalize_expression_node(callee)),
2117            args: args.iter().map(normalize_expression_node).collect(),
2118        },
2119        Expression::Tuple(items) => {
2120            Expression::Tuple(items.iter().map(normalize_expression_node).collect())
2121        }
2122        Expression::Null => Expression::Null,
2123    };
2124    Node::new(Span::dummy(), value)
2125}
2126
2127fn normalize_part_usage_body_element_node(
2128    el: &Node<PartUsageBodyElement>,
2129) -> Node<PartUsageBodyElement> {
2130    let value = match &el.value {
2131        PartUsageBodyElement::Error(n) => {
2132            PartUsageBodyElement::Error(dummy_node(n, n.value.clone()))
2133        }
2134        PartUsageBodyElement::Doc(n) => PartUsageBodyElement::Doc(dummy_node(n, n.value.clone())),
2135        PartUsageBodyElement::Annotation(n) => {
2136            PartUsageBodyElement::Annotation(dummy_node(n, n.value.clone()))
2137        }
2138        PartUsageBodyElement::AttributeUsage(n) => {
2139            PartUsageBodyElement::AttributeUsage(dummy_node(n, normalize_attribute_usage(&n.value)))
2140        }
2141        PartUsageBodyElement::PartUsage(n) => {
2142            PartUsageBodyElement::PartUsage(Box::new(dummy_node(n, normalize_part_usage(&n.value))))
2143        }
2144        PartUsageBodyElement::OccurrenceUsage(n) => {
2145            PartUsageBodyElement::OccurrenceUsage(Box::new(dummy_node(n, n.value.clone())))
2146        }
2147        PartUsageBodyElement::PortUsage(n) => {
2148            PartUsageBodyElement::PortUsage(dummy_node(n, normalize_port_usage(&n.value)))
2149        }
2150        PartUsageBodyElement::Ref(n) => {
2151            PartUsageBodyElement::Ref(dummy_node(n, normalize_ref_decl(&n.value)))
2152        }
2153        PartUsageBodyElement::Bind(n) => PartUsageBodyElement::Bind(dummy_node(n, n.value.clone())),
2154        PartUsageBodyElement::InterfaceUsage(n) => {
2155            PartUsageBodyElement::InterfaceUsage(dummy_node(n, n.value.clone()))
2156        }
2157        PartUsageBodyElement::Connect(n) => {
2158            PartUsageBodyElement::Connect(dummy_node(n, n.value.clone()))
2159        }
2160        PartUsageBodyElement::Perform(n) => {
2161            PartUsageBodyElement::Perform(dummy_node(n, normalize_perform(&n.value)))
2162        }
2163        PartUsageBodyElement::Allocate(n) => {
2164            PartUsageBodyElement::Allocate(dummy_node(n, n.value.clone()))
2165        }
2166        PartUsageBodyElement::Satisfy(n) => {
2167            PartUsageBodyElement::Satisfy(dummy_node(n, n.value.clone()))
2168        }
2169        PartUsageBodyElement::StateUsage(n) => {
2170            PartUsageBodyElement::StateUsage(dummy_node(n, n.value.clone()))
2171        }
2172        PartUsageBodyElement::MetadataAnnotation(n) => {
2173            PartUsageBodyElement::MetadataAnnotation(dummy_node(n, n.value.clone()))
2174        }
2175    };
2176    dummy_node(el, value)
2177}
2178
2179fn normalize_port_usage(p: &PortUsage) -> PortUsage {
2180    PortUsage {
2181        name: p.name.clone(),
2182        type_name: p.type_name.clone(),
2183        multiplicity: p.multiplicity.clone(),
2184        subsets: p.subsets.clone(),
2185        redefines: p.redefines.clone(),
2186        body: normalize_port_body(&p.body),
2187        name_span: None,
2188        type_ref_span: None,
2189    }
2190}
2191
2192fn normalize_port_body(b: &PortBody) -> PortBody {
2193    match b {
2194        PortBody::Semicolon => PortBody::Semicolon,
2195        PortBody::Brace => PortBody::Brace,
2196        PortBody::BraceWithPorts { elements } => PortBody::BraceWithPorts {
2197            elements: elements
2198                .iter()
2199                .map(|n| dummy_node(n, normalize_port_usage(&n.value)))
2200                .collect(),
2201        },
2202    }
2203}
2204
2205fn normalize_port_def(p: &PortDef) -> PortDef {
2206    PortDef {
2207        identification: p.identification.clone(),
2208        specializes: p.specializes.clone(),
2209        body: normalize_port_def_body(&p.body),
2210    }
2211}
2212
2213fn normalize_port_def_body(b: &PortDefBody) -> PortDefBody {
2214    match b {
2215        PortDefBody::Semicolon => PortDefBody::Semicolon,
2216        PortDefBody::Brace { elements } => PortDefBody::Brace {
2217            elements: elements
2218                .iter()
2219                .map(normalize_port_def_body_element_node)
2220                .collect(),
2221        },
2222    }
2223}
2224
2225fn normalize_port_def_body_element_node(el: &Node<PortDefBodyElement>) -> Node<PortDefBodyElement> {
2226    let value = match &el.value {
2227        PortDefBodyElement::InOutDecl(n) => {
2228            PortDefBodyElement::InOutDecl(dummy_node(n, n.value.clone()))
2229        }
2230        PortDefBodyElement::Doc(n) => PortDefBodyElement::Doc(dummy_node(n, n.value.clone())),
2231        PortDefBodyElement::AttributeDef(n) => {
2232            PortDefBodyElement::AttributeDef(dummy_node(n, normalize_attribute_def(&n.value)))
2233        }
2234        PortDefBodyElement::AttributeUsage(n) => {
2235            PortDefBodyElement::AttributeUsage(dummy_node(n, normalize_attribute_usage(&n.value)))
2236        }
2237        PortDefBodyElement::PortUsage(n) => {
2238            PortDefBodyElement::PortUsage(dummy_node(n, normalize_port_usage(&n.value)))
2239        }
2240    };
2241    dummy_node(el, value)
2242}
2243
2244fn normalize_interface_def(i: &InterfaceDef) -> InterfaceDef {
2245    InterfaceDef {
2246        identification: i.identification.clone(),
2247        body: normalize_interface_def_body(&i.body),
2248    }
2249}
2250
2251fn normalize_connection_def(c: &ConnectionDef) -> ConnectionDef {
2252    ConnectionDef {
2253        annotation: c.annotation.clone(),
2254        identification: c.identification.clone(),
2255        body: normalize_connection_def_body(&c.body),
2256    }
2257}
2258
2259fn normalize_connection_def_body(b: &ConnectionDefBody) -> ConnectionDefBody {
2260    match b {
2261        ConnectionDefBody::Semicolon => ConnectionDefBody::Semicolon,
2262        ConnectionDefBody::Brace { elements } => ConnectionDefBody::Brace {
2263            elements: elements
2264                .iter()
2265                .map(normalize_connection_def_body_element_node)
2266                .collect(),
2267        },
2268    }
2269}
2270
2271fn normalize_connection_def_body_element_node(
2272    el: &Node<ConnectionDefBodyElement>,
2273) -> Node<ConnectionDefBodyElement> {
2274    let value = match &el.value {
2275        ConnectionDefBodyElement::EndDecl(n) => {
2276            ConnectionDefBodyElement::EndDecl(dummy_node(n, normalize_end_decl(&n.value)))
2277        }
2278        ConnectionDefBodyElement::RefDecl(n) => {
2279            ConnectionDefBodyElement::RefDecl(dummy_node(n, normalize_ref_decl(&n.value)))
2280        }
2281        ConnectionDefBodyElement::ConnectStmt(n) => {
2282            ConnectionDefBodyElement::ConnectStmt(dummy_node(n, n.value.clone()))
2283        }
2284    };
2285    dummy_node(el, value)
2286}
2287
2288fn normalize_metadata_def(m: &MetadataDef) -> MetadataDef {
2289    MetadataDef {
2290        is_abstract: m.is_abstract,
2291        identification: m.identification.clone(),
2292        body: m.body.clone(),
2293    }
2294}
2295
2296fn normalize_enum_def(e: &EnumDef) -> EnumDef {
2297    EnumDef {
2298        identification: e.identification.clone(),
2299        body: e.body.clone(),
2300    }
2301}
2302
2303fn normalize_occurrence_def(o: &OccurrenceDef) -> OccurrenceDef {
2304    OccurrenceDef {
2305        is_abstract: o.is_abstract,
2306        identification: o.identification.clone(),
2307        body: o.body.clone(),
2308    }
2309}
2310
2311fn normalize_interface_def_body(b: &InterfaceDefBody) -> InterfaceDefBody {
2312    match b {
2313        InterfaceDefBody::Semicolon => InterfaceDefBody::Semicolon,
2314        InterfaceDefBody::Brace { elements } => InterfaceDefBody::Brace {
2315            elements: elements
2316                .iter()
2317                .map(normalize_interface_def_body_element_node)
2318                .collect(),
2319        },
2320    }
2321}
2322
2323fn normalize_interface_def_body_element_node(
2324    el: &Node<InterfaceDefBodyElement>,
2325) -> Node<InterfaceDefBodyElement> {
2326    let value = match &el.value {
2327        InterfaceDefBodyElement::Doc(n) => {
2328            InterfaceDefBodyElement::Doc(dummy_node(n, n.value.clone()))
2329        }
2330        InterfaceDefBodyElement::EndDecl(n) => {
2331            InterfaceDefBodyElement::EndDecl(dummy_node(n, normalize_end_decl(&n.value)))
2332        }
2333        InterfaceDefBodyElement::RefDecl(n) => {
2334            InterfaceDefBodyElement::RefDecl(dummy_node(n, normalize_ref_decl(&n.value)))
2335        }
2336        InterfaceDefBodyElement::ConnectStmt(n) => {
2337            InterfaceDefBodyElement::ConnectStmt(dummy_node(n, n.value.clone()))
2338        }
2339    };
2340    dummy_node(el, value)
2341}
2342
2343fn normalize_end_decl(e: &EndDecl) -> EndDecl {
2344    EndDecl {
2345        name: e.name.clone(),
2346        type_name: e.type_name.clone(),
2347        uses_derived_syntax: e.uses_derived_syntax,
2348        name_span: None,
2349        type_ref_span: None,
2350    }
2351}
2352
2353fn normalize_ref_decl(r: &RefDecl) -> RefDecl {
2354    RefDecl {
2355        name: r.name.clone(),
2356        type_name: r.type_name.clone(),
2357        value: r.value.clone(),
2358        body: r.body.clone(),
2359        name_span: None,
2360        type_ref_span: None,
2361    }
2362}
2363
2364fn normalize_action_def(a: &ActionDef) -> ActionDef {
2365    ActionDef {
2366        identification: a.identification.clone(),
2367        body: normalize_action_def_body(&a.body),
2368    }
2369}
2370
2371fn normalize_action_def_body(b: &ActionDefBody) -> ActionDefBody {
2372    match b {
2373        ActionDefBody::Semicolon => ActionDefBody::Semicolon,
2374        ActionDefBody::Brace { elements } => ActionDefBody::Brace {
2375            elements: elements
2376                .iter()
2377                .map(normalize_action_def_body_element_node)
2378                .collect(),
2379        },
2380    }
2381}
2382
2383fn normalize_action_def_body_element_node(
2384    el: &Node<ActionDefBodyElement>,
2385) -> Node<ActionDefBodyElement> {
2386    let value = match &el.value {
2387        ActionDefBodyElement::Error(n) => {
2388            ActionDefBodyElement::Error(dummy_node(n, n.value.clone()))
2389        }
2390        ActionDefBodyElement::InOutDecl(n) => {
2391            ActionDefBodyElement::InOutDecl(dummy_node(n, n.value.clone()))
2392        }
2393        ActionDefBodyElement::Doc(n) => ActionDefBodyElement::Doc(dummy_node(n, n.value.clone())),
2394        ActionDefBodyElement::Annotation(n) => {
2395            ActionDefBodyElement::Annotation(dummy_node(n, n.value.clone()))
2396        }
2397        ActionDefBodyElement::RefDecl(n) => {
2398            ActionDefBodyElement::RefDecl(dummy_node(n, normalize_ref_decl(&n.value)))
2399        }
2400        ActionDefBodyElement::Perform(n) => {
2401            ActionDefBodyElement::Perform(dummy_node(n, normalize_perform(&n.value)))
2402        }
2403        ActionDefBodyElement::Bind(n) => ActionDefBodyElement::Bind(dummy_node(n, n.value.clone())),
2404        ActionDefBodyElement::Flow(n) => ActionDefBodyElement::Flow(dummy_node(n, n.value.clone())),
2405        ActionDefBodyElement::FirstStmt(n) => {
2406            ActionDefBodyElement::FirstStmt(dummy_node(n, n.value.clone()))
2407        }
2408        ActionDefBodyElement::MergeStmt(n) => {
2409            ActionDefBodyElement::MergeStmt(dummy_node(n, n.value.clone()))
2410        }
2411        ActionDefBodyElement::StateUsage(n) => {
2412            ActionDefBodyElement::StateUsage(dummy_node(n, n.value.clone()))
2413        }
2414        ActionDefBodyElement::ActionUsage(n) => ActionDefBodyElement::ActionUsage(Box::new(
2415            dummy_node(n, normalize_action_usage(&n.value)),
2416        )),
2417        ActionDefBodyElement::Assign(n) => {
2418            ActionDefBodyElement::Assign(dummy_node(n, n.value.clone()))
2419        }
2420        ActionDefBodyElement::ForLoop(n) => {
2421            ActionDefBodyElement::ForLoop(dummy_node(n, n.value.clone()))
2422        }
2423        ActionDefBodyElement::ThenAction(n) => {
2424            ActionDefBodyElement::ThenAction(dummy_node(n, n.value.clone()))
2425        }
2426        ActionDefBodyElement::Decl(n) => ActionDefBodyElement::Decl(dummy_node(n, n.value.clone())),
2427    };
2428    dummy_node(el, value)
2429}
2430
2431fn normalize_action_usage(a: &ActionUsage) -> ActionUsage {
2432    ActionUsage {
2433        name: a.name.clone(),
2434        type_name: a.type_name.clone(),
2435        accept: a.accept.clone(),
2436        body: normalize_action_usage_body(&a.body),
2437        name_span: None,
2438        type_ref_span: None,
2439    }
2440}
2441
2442fn normalize_action_usage_body(b: &ActionUsageBody) -> ActionUsageBody {
2443    match b {
2444        ActionUsageBody::Semicolon => ActionUsageBody::Semicolon,
2445        ActionUsageBody::Brace { elements } => ActionUsageBody::Brace {
2446            elements: elements
2447                .iter()
2448                .map(normalize_action_usage_body_element_node)
2449                .collect(),
2450        },
2451    }
2452}
2453
2454fn normalize_action_usage_body_element_node(
2455    el: &Node<ActionUsageBodyElement>,
2456) -> Node<ActionUsageBodyElement> {
2457    let value = match &el.value {
2458        ActionUsageBodyElement::Error(n) => {
2459            ActionUsageBodyElement::Error(dummy_node(n, n.value.clone()))
2460        }
2461        ActionUsageBodyElement::Doc(n) => {
2462            ActionUsageBodyElement::Doc(dummy_node(n, n.value.clone()))
2463        }
2464        ActionUsageBodyElement::Annotation(n) => {
2465            ActionUsageBodyElement::Annotation(dummy_node(n, n.value.clone()))
2466        }
2467        ActionUsageBodyElement::InOutDecl(n) => {
2468            ActionUsageBodyElement::InOutDecl(dummy_node(n, n.value.clone()))
2469        }
2470        ActionUsageBodyElement::RefDecl(n) => {
2471            ActionUsageBodyElement::RefDecl(dummy_node(n, normalize_ref_decl(&n.value)))
2472        }
2473        ActionUsageBodyElement::Bind(n) => {
2474            ActionUsageBodyElement::Bind(dummy_node(n, n.value.clone()))
2475        }
2476        ActionUsageBodyElement::Flow(n) => {
2477            ActionUsageBodyElement::Flow(dummy_node(n, n.value.clone()))
2478        }
2479        ActionUsageBodyElement::FirstStmt(n) => {
2480            ActionUsageBodyElement::FirstStmt(dummy_node(n, n.value.clone()))
2481        }
2482        ActionUsageBodyElement::MergeStmt(n) => {
2483            ActionUsageBodyElement::MergeStmt(dummy_node(n, n.value.clone()))
2484        }
2485        ActionUsageBodyElement::StateUsage(n) => {
2486            ActionUsageBodyElement::StateUsage(dummy_node(n, n.value.clone()))
2487        }
2488        ActionUsageBodyElement::ActionUsage(n) => ActionUsageBodyElement::ActionUsage(Box::new(
2489            dummy_node(n, normalize_action_usage(&n.value)),
2490        )),
2491        ActionUsageBodyElement::Assign(n) => {
2492            ActionUsageBodyElement::Assign(dummy_node(n, n.value.clone()))
2493        }
2494        ActionUsageBodyElement::ForLoop(n) => {
2495            ActionUsageBodyElement::ForLoop(dummy_node(n, n.value.clone()))
2496        }
2497        ActionUsageBodyElement::ThenAction(n) => {
2498            ActionUsageBodyElement::ThenAction(dummy_node(n, n.value.clone()))
2499        }
2500        ActionUsageBodyElement::Decl(n) => {
2501            ActionUsageBodyElement::Decl(dummy_node(n, n.value.clone()))
2502        }
2503    };
2504    dummy_node(el, value)
2505}