#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Span {
pub offset: usize,
pub line: u32,
pub column: usize,
pub len: usize,
}
impl Span {
pub fn dummy() -> Self {
Self {
offset: 0,
line: 1,
column: 1,
len: 0,
}
}
pub fn to_lsp_range(&self) -> (u32, u32, u32, u32) {
let start_line = self.line.saturating_sub(1);
let start_char = self.column.saturating_sub(1);
let end_char = start_char.saturating_add(self.len);
(start_line, start_char as u32, start_line, end_char as u32)
}
}
#[cfg(test)]
mod tests {
use super::Span;
#[test]
fn span_dummy() {
let s = Span::dummy();
assert_eq!(s.offset, 0);
assert_eq!(s.line, 1);
assert_eq!(s.column, 1);
assert_eq!(s.len, 0);
}
}
#[derive(Debug, Clone)]
pub struct Node<T> {
pub span: Span,
pub value: T,
}
impl<T: PartialEq> PartialEq for Node<T> {
fn eq(&self, other: &Self) -> bool {
self.value == other.value
}
}
impl<T: Eq> Eq for Node<T> {}
impl<T> Node<T> {
pub fn new(span: Span, value: T) -> Self {
Self { span, value }
}
}
impl<T> std::ops::Deref for Node<T> {
type Target = T;
fn deref(&self) -> &T {
&self.value
}
}
pub trait AstNode {
fn span(&self) -> Span;
}
impl<T> AstNode for Node<T> {
fn span(&self) -> Span {
self.span.clone()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Expression {
LiteralInteger(i64),
LiteralReal(String),
LiteralString(String),
LiteralBoolean(bool),
FeatureRef(String),
MemberAccess(Box<Node<Expression>>, String),
Index {
base: Box<Node<Expression>>,
index: Box<Node<Expression>>,
},
Bracket(Box<Node<Expression>>),
LiteralWithUnit {
value: Box<Node<Expression>>,
unit: Box<Node<Expression>>,
},
BinaryOp {
op: String,
left: Box<Node<Expression>>,
right: Box<Node<Expression>>,
},
UnaryOp {
op: String,
operand: Box<Node<Expression>>,
},
Invocation {
callee: Box<Node<Expression>>,
args: Vec<Node<Expression>>,
},
Tuple(Vec<Node<Expression>>),
Null,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RootElement {
Package(Node<Package>),
LibraryPackage(Node<LibraryPackage>),
Namespace(Node<NamespaceDecl>),
Import(Node<Import>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NamespaceDecl {
pub identification: Identification,
pub body: PackageBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RootNamespace {
pub elements: Vec<Node<RootElement>>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FilterMember {
pub visibility: Option<Visibility>,
pub condition: Node<Expression>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseErrorNode {
pub message: String,
pub code: String,
pub expected: Option<String>,
pub found: Option<String>,
pub suggestion: Option<String>,
pub category: Option<crate::error::DiagnosticCategory>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct KermlSemanticDecl {
pub bnf_production: String,
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct KermlFeatureDecl {
pub bnf_production: String,
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FeatureDecl {
pub keyword: String,
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ClassifierDecl {
pub keyword: String,
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExtendedLibraryDecl {
pub bnf_production: String,
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PackageBodyElement {
Error(Node<ParseErrorNode>),
Doc(Node<DocComment>),
Comment(Node<CommentAnnotation>),
TextualRep(Node<TextualRepresentation>),
Filter(Node<FilterMember>),
Package(Node<Package>),
LibraryPackage(Node<LibraryPackage>),
Import(Node<Import>),
PartDef(Node<PartDef>),
PartUsage(Node<PartUsage>),
PortDef(Node<PortDef>),
InterfaceDef(Node<InterfaceDef>),
AliasDef(Node<AliasDef>),
AttributeDef(Node<AttributeDef>),
ActionDef(Node<ActionDef>),
ActionUsage(Node<ActionUsage>),
RequirementDef(Node<RequirementDef>),
RequirementUsage(Node<RequirementUsage>),
Satisfy(Node<Satisfy>),
UseCaseDef(Node<UseCaseDef>),
Actor(Node<ActorDecl>),
StateDef(Node<StateDef>),
StateUsage(Node<StateUsage>),
ItemDef(Node<ItemDef>),
IndividualDef(Node<IndividualDef>),
ConstraintDef(Node<ConstraintDef>),
CalcDef(Node<CalcDef>),
ViewDef(Node<ViewDef>),
ViewpointDef(Node<ViewpointDef>),
RenderingDef(Node<RenderingDef>),
ViewUsage(Node<ViewUsage>),
ViewpointUsage(Node<ViewpointUsage>),
RenderingUsage(Node<RenderingUsage>),
ConnectionDef(Node<ConnectionDef>),
MetadataDef(Node<MetadataDef>),
EnumDef(Node<EnumDef>),
OccurrenceDef(Node<OccurrenceDef>),
OccurrenceUsage(Node<OccurrenceUsage>),
Dependency(Node<Dependency>),
AllocationDef(Node<AllocationDef>),
AllocationUsage(Node<AllocationUsage>),
FlowDef(Node<FlowDef>),
FlowUsage(Node<FlowUsage>),
ConcernUsage(Node<ConcernUsage>),
CaseDef(Node<CaseDef>),
CaseUsage(Node<CaseUsage>),
AnalysisCaseDef(Node<AnalysisCaseDef>),
AnalysisCaseUsage(Node<AnalysisCaseUsage>),
VerificationCaseDef(Node<VerificationCaseDef>),
VerificationCaseUsage(Node<VerificationCaseUsage>),
UseCaseUsage(Node<UseCaseUsage>),
FeatureDecl(Node<FeatureDecl>),
ClassifierDecl(Node<ClassifierDecl>),
KermlSemanticDecl(Node<KermlSemanticDecl>),
KermlFeatureDecl(Node<KermlFeatureDecl>),
ExtendedLibraryDecl(Node<ExtendedLibraryDecl>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Package {
pub identification: Identification,
pub body: PackageBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Identification {
pub short_name: Option<String>,
pub name: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PackageBody {
Semicolon,
Brace {
elements: Vec<Node<PackageBodyElement>>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Visibility {
Public,
Private,
Protected,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FilterPackageMember {
pub expression: Node<Expression>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Import {
pub visibility: Option<Visibility>,
pub is_import_all: bool,
pub target: String,
pub is_recursive: bool,
pub filter_members: Option<Vec<Node<FilterPackageMember>>>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PartDef {
pub definition_prefix: Option<DefinitionPrefix>,
pub is_individual: bool,
pub identification: Identification,
pub specializes: Option<String>,
pub specializes_span: Option<Span>,
pub body: PartDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DefinitionPrefix {
Abstract,
Variation,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PartDefBody {
Semicolon,
Brace {
elements: Vec<Node<PartDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PartDefBodyElement {
Error(Node<ParseErrorNode>),
Doc(Node<DocComment>),
Comment(Node<CommentAnnotation>),
Annotation(Node<Annotation>),
Other(String),
AttributeDef(Node<AttributeDef>),
AttributeUsage(Node<AttributeUsage>),
RequirementUsage(Node<RequirementUsage>),
Ref(Node<RefDecl>),
PortUsage(Node<PortUsage>),
PartUsage(Box<Node<PartUsage>>),
OccurrenceUsage(Box<Node<OccurrenceUsage>>),
InterfaceDef(Node<InterfaceDef>),
InterfaceUsage(Node<InterfaceUsage>),
Connect(Node<Connect>),
Connection(Node<ConnectionUsageMember>),
Perform(Node<Perform>),
Allocate(Node<Allocate>),
OpaqueMember(Node<OpaqueMemberDecl>),
ExhibitState(Node<ExhibitState>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OpaqueMemberDecl {
pub keyword: String,
pub name: String,
pub text: String,
pub body: AttributeBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConnectionUsageMember {
pub name: Option<String>,
pub type_name: Option<String>,
pub body: ConnectionDefBody,
pub subsets: Option<String>,
pub redefines: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExhibitState {
pub name: String,
pub type_name: Option<String>,
pub redefines: Option<String>,
pub body: StateDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AttributeDef {
pub name: String,
pub typing: Option<String>,
pub value: Option<Node<Expression>>,
pub body: AttributeBody,
pub name_span: Option<Span>,
pub typing_span: Option<Span>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AttributeBody {
Semicolon,
Brace,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ItemDef {
pub identification: Identification,
pub body: AttributeBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IndividualDef {
pub identification: Identification,
pub specializes: Option<String>,
pub body: AttributeBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PartUsage {
pub is_individual: bool,
pub name: String,
pub type_name: String,
pub multiplicity: Option<String>,
pub ordered: bool,
pub subsets: Option<(String, Option<Node<Expression>>)>,
pub redefines: Option<String>,
pub value: Option<Node<Expression>>,
pub body: PartUsageBody,
pub name_span: Option<Span>,
pub type_ref_span: Option<Span>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PartUsageBody {
Semicolon,
Brace {
elements: Vec<Node<PartUsageBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MetadataAnnotation {
pub name: String,
pub type_name: Option<String>,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Annotation {
pub sigil: String,
pub head: String,
pub type_name: Option<String>,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PartUsageBodyElement {
Error(Node<ParseErrorNode>),
Doc(Node<DocComment>),
Annotation(Node<Annotation>),
AttributeUsage(Node<AttributeUsage>),
PartUsage(Box<Node<PartUsage>>),
OccurrenceUsage(Box<Node<OccurrenceUsage>>),
PortUsage(Node<PortUsage>),
Bind(Node<Bind>),
Ref(Node<RefDecl>),
InterfaceUsage(Node<InterfaceUsage>),
Connect(Node<Connect>),
Perform(Node<Perform>),
Allocate(Node<Allocate>),
Satisfy(Node<Satisfy>),
StateUsage(Node<StateUsage>),
MetadataAnnotation(Node<MetadataAnnotation>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Perform {
pub action_name: String,
pub type_name: Option<String>,
pub body: PerformBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PerformBody {
Semicolon,
Brace {
elements: Vec<Node<PerformBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PerformBodyElement {
Doc(Node<DocComment>),
InOut(Node<PerformInOutBinding>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PerformInOutBinding {
pub direction: InOut,
pub name: String,
pub value: Node<Expression>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AttributeUsage {
pub name: String,
pub typing: Option<String>,
pub redefines: Option<String>,
pub value: Option<Node<Expression>>,
pub body: AttributeBody,
pub name_span: Option<Span>,
pub typing_span: Option<Span>,
pub redefines_span: Option<Span>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PortDef {
pub identification: Identification,
pub specializes: Option<String>,
pub body: PortDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PortDefBody {
Semicolon,
Brace {
elements: Vec<Node<PortDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PortDefBodyElement {
InOutDecl(Node<InOutDecl>),
Doc(Node<DocComment>),
AttributeDef(Node<AttributeDef>),
AttributeUsage(Node<AttributeUsage>),
PortUsage(Node<PortUsage>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PortUsage {
pub name: String,
pub type_name: Option<String>,
pub multiplicity: Option<String>,
pub subsets: Option<(String, Option<Node<Expression>>)>,
pub redefines: Option<String>,
pub body: PortBody,
pub name_span: Option<Span>,
pub type_ref_span: Option<Span>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PortBody {
Semicolon,
Brace,
BraceWithPorts {
elements: Vec<Node<PortUsage>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InterfaceDef {
pub identification: Identification,
pub body: InterfaceDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum InterfaceDefBody {
Semicolon,
Brace {
elements: Vec<Node<InterfaceDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum InterfaceDefBodyElement {
Doc(Node<DocComment>),
EndDecl(Node<EndDecl>),
RefDecl(Node<RefDecl>),
ConnectStmt(Node<ConnectStmt>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EndDecl {
pub name: String,
pub type_name: String,
pub uses_derived_syntax: bool,
pub name_span: Option<Span>,
pub type_ref_span: Option<Span>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RefDecl {
pub name: String,
pub type_name: String,
pub value: Option<Node<Expression>>,
pub body: RefBody,
pub name_span: Option<Span>,
pub type_ref_span: Option<Span>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RefBody {
Semicolon,
Brace,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConnectionDef {
pub annotation: Option<String>,
pub identification: Identification,
pub body: ConnectionDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConnectionDefBody {
Semicolon,
Brace {
elements: Vec<Node<ConnectionDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConnectionDefBodyElement {
EndDecl(Node<EndDecl>),
RefDecl(Node<RefDecl>),
ConnectStmt(Node<ConnectStmt>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MetadataDef {
pub is_abstract: bool,
pub identification: Identification,
pub body: DefinitionBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EnumDef {
pub identification: Identification,
pub body: EnumerationBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EnumerationBody {
Semicolon,
Brace { values: Vec<String> },
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OccurrenceDef {
pub is_abstract: bool,
pub identification: Identification,
pub body: DefinitionBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OccurrenceUsage {
pub is_individual: bool,
pub is_then: bool,
pub portion_kind: Option<String>,
pub name: String,
pub type_name: Option<String>,
pub subsets: Option<String>,
pub redefines: Option<String>,
pub body: OccurrenceUsageBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OccurrenceUsageBody {
Semicolon,
Brace {
elements: Vec<Node<OccurrenceBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AssertConstraintMember {
pub body: ConstraintDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OccurrenceBodyElement {
Error(Node<ParseErrorNode>),
Doc(Node<DocComment>),
Annotation(Node<Annotation>),
AssertConstraint(Node<AssertConstraintMember>),
Other(String),
AttributeUsage(Node<AttributeUsage>),
PartUsage(Box<Node<PartUsage>>),
OccurrenceUsage(Box<Node<OccurrenceUsage>>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LibraryPackage {
pub is_standard: bool,
pub identification: Identification,
pub body: PackageBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DefinitionBody {
Semicolon,
Brace,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConnectStmt {
pub from: Node<Expression>,
pub to: Node<Expression>,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConnectBody {
Semicolon,
Brace,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Bind {
pub left: Node<Expression>,
pub right: Node<Expression>,
pub body: Option<ConnectBody>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum InterfaceUsage {
TypedConnect {
interface_type: Option<String>,
from: Node<Expression>,
to: Node<Expression>,
body: ConnectBody,
body_elements: Vec<Node<InterfaceUsageBodyElement>>,
},
Connection {
from: Node<Expression>,
to: Node<Expression>,
body_elements: Vec<Node<InterfaceUsageBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum InterfaceUsageBodyElement {
RefRedef {
name: String,
value: Node<Expression>,
body: RefBody,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Connect {
pub from: Node<Expression>,
pub to: Node<Expression>,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AliasDef {
pub identification: Identification,
pub target: String,
pub body: AliasBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AliasBody {
Semicolon,
Brace,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActionDef {
pub identification: Identification,
pub body: ActionDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ActionDefBody {
Semicolon,
Brace {
elements: Vec<Node<ActionDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ActionDefBodyElement {
Error(Node<ParseErrorNode>),
InOutDecl(Node<InOutDecl>),
Doc(Node<DocComment>),
Annotation(Node<Annotation>),
RefDecl(Node<RefDecl>),
Perform(Node<Perform>),
Bind(Node<Bind>),
Flow(Node<Flow>),
FirstStmt(Node<FirstStmt>),
MergeStmt(Node<MergeStmt>),
StateUsage(Node<StateUsage>),
ActionUsage(Box<Node<ActionUsage>>),
Assign(Node<AssignStmt>),
ForLoop(Node<ForLoop>),
ThenAction(Node<ThenAction>),
Decl(Node<ActionBodyDecl>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AssignStmt {
pub is_then: bool,
pub lhs: String,
pub rhs: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ForLoop {
pub var: String,
pub range: String,
pub body: ActionDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ThenAction {
pub action: Node<ActionUsage>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InOutDecl {
pub direction: InOut,
pub name: String,
pub type_name: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InOut {
In,
Out,
InOut,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActionUsage {
pub name: String,
pub type_name: String,
pub accept: Option<(String, String)>,
pub body: ActionUsageBody,
pub name_span: Option<Span>,
pub type_ref_span: Option<Span>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ActionUsageBody {
Semicolon,
Brace {
elements: Vec<Node<ActionUsageBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ActionUsageBodyElement {
Error(Node<ParseErrorNode>),
Doc(Node<DocComment>),
Annotation(Node<Annotation>),
InOutDecl(Node<InOutDecl>),
RefDecl(Node<RefDecl>),
Bind(Node<Bind>),
Flow(Node<Flow>),
FirstStmt(Node<FirstStmt>),
MergeStmt(Node<MergeStmt>),
StateUsage(Node<StateUsage>),
ActionUsage(Box<Node<ActionUsage>>),
Assign(Node<AssignStmt>),
ForLoop(Node<ForLoop>),
ThenAction(Node<ThenAction>),
Decl(Node<ActionBodyDecl>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActionBodyDecl {
pub keyword: String,
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Flow {
pub from: Node<Expression>,
pub to: Node<Expression>,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FlowDef {
pub identification: Identification,
pub body: DefinitionBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FlowUsage {
pub name: String,
pub type_name: Option<String>,
pub from: Option<Node<Expression>>,
pub to: Option<Node<Expression>>,
pub body: DefinitionBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FirstStmt {
pub first: Node<Expression>,
pub then: Node<Expression>,
pub body: FirstMergeBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MergeStmt {
pub merge: Node<Expression>,
pub body: FirstMergeBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FirstMergeBody {
Semicolon,
Brace,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Allocate {
pub source: Node<Expression>,
pub target: Node<Expression>,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AllocationDef {
pub identification: Identification,
pub body: DefinitionBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AllocationUsage {
pub name: String,
pub type_name: Option<String>,
pub source: Option<Node<Expression>>,
pub target: Option<Node<Expression>>,
pub body: DefinitionBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RequirementDef {
pub identification: Identification,
pub body: RequirementDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RequirementDefBody {
Semicolon,
Brace {
elements: Vec<Node<RequirementDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RequirementDefBodyElement {
Error(Node<ParseErrorNode>),
Other(String),
Annotation(Node<Annotation>),
Import(Node<Import>),
SubjectDecl(Node<SubjectDecl>),
AttributeDef(Node<AttributeDef>),
AttributeUsage(Node<AttributeUsage>),
VerifyRequirement(Node<VerifyRequirementMember>),
RequireConstraint(Node<RequireConstraint>),
Frame(Node<FrameMember>),
Doc(Node<DocComment>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SubjectDecl {
pub name: String,
pub type_name: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RequireConstraint {
pub body: RequireConstraintBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VerifyRequirementMember {
pub explicit_requirement_keyword: bool,
pub requirement: Option<Node<RequirementUsage>>,
pub target: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RequireConstraintBody {
Semicolon,
Brace {
elements: Vec<Node<ConstraintDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Satisfy {
pub source: Node<Expression>,
pub target: Node<Expression>,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RequirementUsage {
pub name: String,
pub type_name: Option<String>,
pub subsets: Option<String>,
pub body: RequirementDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Dependency {
pub identification: Option<Identification>,
pub clients: Vec<String>,
pub suppliers: Vec<String>,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FrameMember {
pub name: String,
pub body: RequirementDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConcernUsage {
pub name: String,
pub type_name: Option<String>,
pub body: RequirementDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CaseDef {
pub identification: Identification,
pub body: UseCaseDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CaseUsage {
pub name: String,
pub type_name: Option<String>,
pub body: UseCaseDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AnalysisCaseDef {
pub identification: Identification,
pub body: UseCaseDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AnalysisCaseUsage {
pub name: String,
pub type_name: Option<String>,
pub body: UseCaseDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VerificationCaseDef {
pub identification: Identification,
pub body: UseCaseDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VerificationCaseUsage {
pub name: String,
pub type_name: Option<String>,
pub body: UseCaseDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UseCaseUsage {
pub name: String,
pub type_name: Option<String>,
pub body: UseCaseDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActorDecl {
pub identification: Identification,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UseCaseDef {
pub identification: Identification,
pub body: UseCaseDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum UseCaseDefBody {
Semicolon,
Brace {
elements: Vec<Node<UseCaseDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FirstSuccession {
pub target: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ThenDone {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IncludeUseCase {
pub name: String,
pub multiplicity: Option<String>,
pub body: UseCaseDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ThenIncludeUseCase {
pub include: Node<IncludeUseCase>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ThenUseCaseUsage {
pub use_case: Node<UseCaseUsage>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SubjectRef {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActorRedefinitionAssignment {
pub name: String,
pub rhs: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RefRedefinition {
pub name: String,
pub body: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReturnRef {
pub name: String,
pub multiplicity: Option<String>,
pub body: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum UseCaseDefBodyElement {
Error(Node<ParseErrorNode>),
Other(String),
AttributeDef(Node<AttributeDef>),
Doc(Node<DocComment>),
SubjectDecl(Node<SubjectDecl>),
SubjectRef(Node<SubjectRef>),
ActorUsage(Node<ActorUsage>),
ActorRedefinitionAssignment(Node<ActorRedefinitionAssignment>),
Objective(Node<Objective>),
FirstSuccession(Node<FirstSuccession>),
ThenIncludeUseCase(Node<ThenIncludeUseCase>),
ThenUseCaseUsage(Node<ThenUseCaseUsage>),
ThenDone(Node<ThenDone>),
IncludeUseCase(Node<IncludeUseCase>),
RefRedefinition(Node<RefRedefinition>),
ReturnRef(Node<ReturnRef>),
Assign(Node<AssignStmt>),
ForLoop(Node<ForLoop>),
ThenAction(Node<ThenAction>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActorUsage {
pub name: String,
pub type_name: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Objective {
pub visibility: Option<Visibility>,
pub requirement: Node<RequirementUsage>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StateDef {
pub identification: Identification,
pub body: StateDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StateDefBody {
Semicolon,
Brace {
elements: Vec<Node<StateDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StateDefBodyElement {
Error(Node<ParseErrorNode>),
Doc(Node<DocComment>),
Annotation(Node<Annotation>),
Other(String),
Entry(Node<EntryAction>),
Then(Node<ThenStmt>),
Ref(Node<RefDecl>),
RequirementUsage(Node<RequirementUsage>),
StateUsage(Node<StateUsage>),
Transition(Node<Transition>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EntryAction {
pub action_name: Option<String>,
pub body: StateDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ThenStmt {
pub state_name: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StateUsage {
pub name: String,
pub type_name: Option<String>,
pub body: StateDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Transition {
pub name: Option<String>,
pub source: Option<Node<Expression>>,
pub guard: Option<Node<Expression>>,
pub effect: Option<Node<Expression>>,
pub target: Node<Expression>,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConstraintDef {
pub identification: Identification,
pub body: ConstraintDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConstraintDefBody {
Semicolon,
Brace {
elements: Vec<Node<ConstraintDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConstraintDefBodyElement {
Error(Node<ParseErrorNode>),
Doc(Node<DocComment>),
InOutDecl(Node<InOutDecl>),
Expression(Node<Expression>), Other(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConstraintBody {
Semicolon,
Brace, }
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DocComment {
pub identification: Option<Identification>,
pub locale: Option<String>,
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommentAnnotation {
pub identification: Option<Identification>,
pub locale: Option<String>,
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TextualRepresentation {
pub rep_identification: Option<Identification>,
pub language: String,
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CalcDef {
pub identification: Identification,
pub body: CalcDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CalcDefBody {
Semicolon,
Brace {
elements: Vec<Node<CalcDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CalcDefBodyElement {
Error(Node<ParseErrorNode>),
Doc(Node<DocComment>),
InOutDecl(Node<InOutDecl>),
ReturnDecl(Node<ReturnDecl>),
Expression(Node<Expression>), Other(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReturnDecl {
pub name: String,
pub type_name: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ViewDef {
pub identification: Identification,
pub body: ViewDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ViewDefBody {
Semicolon,
Brace {
elements: Vec<Node<ViewDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ViewDefBodyElement {
Error(Node<ParseErrorNode>),
Other(String),
Doc(Node<DocComment>),
Filter(Node<FilterMember>),
ViewRendering(Node<ViewRenderingUsage>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ViewRenderingUsage {
pub name: String,
pub type_name: Option<String>,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ViewpointDef {
pub identification: Identification,
pub body: RequirementDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RenderingDef {
pub identification: Identification,
pub body: RenderingDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RenderingDefBody {
Semicolon,
Brace,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ViewUsage {
pub name: String,
pub type_name: Option<String>,
pub body: ViewBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ViewBody {
Semicolon,
Brace {
elements: Vec<Node<ViewBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ViewBodyElement {
Error(Node<ParseErrorNode>),
Other(String),
Doc(Node<DocComment>),
Filter(Node<FilterMember>),
ViewRendering(Node<ViewRenderingUsage>),
Expose(Node<ExposeMember>),
Satisfy(Node<SatisfyViewMember>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExposeMember {
pub target: String,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SatisfyViewMember {
pub viewpoint_ref: String,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ViewpointUsage {
pub name: String,
pub type_name: String,
pub body: RequirementDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RenderingUsage {
pub name: String,
pub type_name: Option<String>,
pub body: ConnectBody,
}
impl RootNamespace {
pub fn normalize_for_test_comparison(&self) -> Self {
RootNamespace {
elements: self
.elements
.iter()
.map(normalize_root_element_node)
.collect(),
}
}
}
fn dummy_node<T: Clone>(_n: &Node<T>, value: T) -> Node<T> {
Node::new(Span::dummy(), value)
}
fn normalize_root_element_node(el: &Node<RootElement>) -> Node<RootElement> {
let value = match &el.value {
RootElement::Package(p) => RootElement::Package(dummy_node(p, normalize_package(&p.value))),
RootElement::LibraryPackage(lp) => {
RootElement::LibraryPackage(dummy_node(lp, normalize_library_package(&lp.value)))
}
RootElement::Namespace(n) => {
RootElement::Namespace(dummy_node(n, normalize_namespace_decl(&n.value)))
}
RootElement::Import(n) => RootElement::Import(dummy_node(n, n.value.clone())),
};
dummy_node(el, value)
}
fn normalize_library_package(lp: &LibraryPackage) -> LibraryPackage {
LibraryPackage {
is_standard: lp.is_standard,
identification: lp.identification.clone(),
body: normalize_package_body(&lp.body),
}
}
fn normalize_namespace_decl(n: &NamespaceDecl) -> NamespaceDecl {
NamespaceDecl {
identification: n.identification.clone(),
body: normalize_package_body(&n.body),
}
}
fn normalize_package(p: &Package) -> Package {
Package {
identification: p.identification.clone(),
body: normalize_package_body(&p.body),
}
}
fn normalize_package_body(b: &PackageBody) -> PackageBody {
match b {
PackageBody::Semicolon => PackageBody::Semicolon,
PackageBody::Brace { elements } => PackageBody::Brace {
elements: elements
.iter()
.map(normalize_package_body_element_node)
.collect(),
},
}
}
fn normalize_package_body_element_node(el: &Node<PackageBodyElement>) -> Node<PackageBodyElement> {
let value = match &el.value {
PackageBodyElement::Error(n) => PackageBodyElement::Error(dummy_node(n, n.value.clone())),
PackageBodyElement::Doc(n) => PackageBodyElement::Doc(dummy_node(n, n.value.clone())),
PackageBodyElement::Comment(n) => {
PackageBodyElement::Comment(dummy_node(n, n.value.clone()))
}
PackageBodyElement::TextualRep(n) => {
PackageBodyElement::TextualRep(dummy_node(n, n.value.clone()))
}
PackageBodyElement::Filter(n) => PackageBodyElement::Filter(dummy_node(n, n.value.clone())),
PackageBodyElement::Package(n) => {
PackageBodyElement::Package(dummy_node(n, normalize_package(&n.value)))
}
PackageBodyElement::LibraryPackage(n) => {
PackageBodyElement::LibraryPackage(dummy_node(n, normalize_library_package(&n.value)))
}
PackageBodyElement::Import(n) => PackageBodyElement::Import(dummy_node(n, n.value.clone())),
PackageBodyElement::PartDef(n) => {
PackageBodyElement::PartDef(dummy_node(n, normalize_part_def(&n.value)))
}
PackageBodyElement::PartUsage(n) => {
PackageBodyElement::PartUsage(dummy_node(n, normalize_part_usage(&n.value)))
}
PackageBodyElement::PortDef(n) => {
PackageBodyElement::PortDef(dummy_node(n, normalize_port_def(&n.value)))
}
PackageBodyElement::InterfaceDef(n) => {
PackageBodyElement::InterfaceDef(dummy_node(n, normalize_interface_def(&n.value)))
}
PackageBodyElement::ConnectionDef(n) => {
PackageBodyElement::ConnectionDef(dummy_node(n, normalize_connection_def(&n.value)))
}
PackageBodyElement::MetadataDef(n) => {
PackageBodyElement::MetadataDef(dummy_node(n, normalize_metadata_def(&n.value)))
}
PackageBodyElement::EnumDef(n) => {
PackageBodyElement::EnumDef(dummy_node(n, normalize_enum_def(&n.value)))
}
PackageBodyElement::OccurrenceDef(n) => {
PackageBodyElement::OccurrenceDef(dummy_node(n, normalize_occurrence_def(&n.value)))
}
PackageBodyElement::OccurrenceUsage(n) => {
PackageBodyElement::OccurrenceUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::AliasDef(n) => {
PackageBodyElement::AliasDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::AttributeDef(n) => {
PackageBodyElement::AttributeDef(dummy_node(n, normalize_attribute_def(&n.value)))
}
PackageBodyElement::ActionDef(n) => {
PackageBodyElement::ActionDef(dummy_node(n, normalize_action_def(&n.value)))
}
PackageBodyElement::ActionUsage(n) => {
PackageBodyElement::ActionUsage(dummy_node(n, normalize_action_usage(&n.value)))
}
PackageBodyElement::RequirementDef(n) => {
PackageBodyElement::RequirementDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::RequirementUsage(n) => {
PackageBodyElement::RequirementUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::Satisfy(n) => {
PackageBodyElement::Satisfy(dummy_node(n, n.value.clone()))
}
PackageBodyElement::UseCaseDef(n) => {
PackageBodyElement::UseCaseDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::Actor(n) => PackageBodyElement::Actor(dummy_node(n, n.value.clone())),
PackageBodyElement::StateDef(n) => {
PackageBodyElement::StateDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::StateUsage(n) => {
PackageBodyElement::StateUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::ItemDef(n) => {
PackageBodyElement::ItemDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::IndividualDef(n) => {
PackageBodyElement::IndividualDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::ConstraintDef(n) => {
PackageBodyElement::ConstraintDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::CalcDef(n) => {
PackageBodyElement::CalcDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::ViewDef(n) => {
PackageBodyElement::ViewDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::ViewpointDef(n) => {
PackageBodyElement::ViewpointDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::RenderingDef(n) => {
PackageBodyElement::RenderingDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::ViewUsage(n) => {
PackageBodyElement::ViewUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::ViewpointUsage(n) => {
PackageBodyElement::ViewpointUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::RenderingUsage(n) => {
PackageBodyElement::RenderingUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::Dependency(n) => {
PackageBodyElement::Dependency(dummy_node(n, n.value.clone()))
}
PackageBodyElement::AllocationDef(n) => {
PackageBodyElement::AllocationDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::AllocationUsage(n) => {
PackageBodyElement::AllocationUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::FlowDef(n) => {
PackageBodyElement::FlowDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::FlowUsage(n) => {
PackageBodyElement::FlowUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::ConcernUsage(n) => {
PackageBodyElement::ConcernUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::CaseDef(n) => {
PackageBodyElement::CaseDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::CaseUsage(n) => {
PackageBodyElement::CaseUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::AnalysisCaseDef(n) => {
PackageBodyElement::AnalysisCaseDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::AnalysisCaseUsage(n) => {
PackageBodyElement::AnalysisCaseUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::VerificationCaseDef(n) => {
PackageBodyElement::VerificationCaseDef(dummy_node(n, n.value.clone()))
}
PackageBodyElement::VerificationCaseUsage(n) => {
PackageBodyElement::VerificationCaseUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::UseCaseUsage(n) => {
PackageBodyElement::UseCaseUsage(dummy_node(n, n.value.clone()))
}
PackageBodyElement::FeatureDecl(n) => {
PackageBodyElement::FeatureDecl(dummy_node(n, n.value.clone()))
}
PackageBodyElement::ClassifierDecl(n) => {
PackageBodyElement::ClassifierDecl(dummy_node(n, n.value.clone()))
}
PackageBodyElement::KermlSemanticDecl(n) => {
PackageBodyElement::KermlSemanticDecl(dummy_node(n, n.value.clone()))
}
PackageBodyElement::KermlFeatureDecl(n) => {
PackageBodyElement::KermlFeatureDecl(dummy_node(n, n.value.clone()))
}
PackageBodyElement::ExtendedLibraryDecl(n) => {
PackageBodyElement::ExtendedLibraryDecl(dummy_node(n, n.value.clone()))
}
};
dummy_node(el, value)
}
fn normalize_attribute_def(a: &AttributeDef) -> AttributeDef {
AttributeDef {
name: a.name.clone(),
typing: a.typing.clone(),
value: a.value.clone(),
body: a.body.clone(),
name_span: None,
typing_span: None,
}
}
fn normalize_part_def(p: &PartDef) -> PartDef {
PartDef {
definition_prefix: p.definition_prefix.clone(),
is_individual: p.is_individual,
identification: p.identification.clone(),
specializes: p.specializes.clone(),
specializes_span: None,
body: normalize_part_def_body(&p.body),
}
}
fn normalize_part_def_body(b: &PartDefBody) -> PartDefBody {
match b {
PartDefBody::Semicolon => PartDefBody::Semicolon,
PartDefBody::Brace { elements } => PartDefBody::Brace {
elements: elements
.iter()
.map(normalize_part_def_body_element_node)
.collect(),
},
}
}
fn normalize_part_def_body_element_node(el: &Node<PartDefBodyElement>) -> Node<PartDefBodyElement> {
let value = match &el.value {
PartDefBodyElement::Error(n) => PartDefBodyElement::Error(dummy_node(n, n.value.clone())),
PartDefBodyElement::Doc(n) => PartDefBodyElement::Doc(dummy_node(n, n.value.clone())),
PartDefBodyElement::Comment(n) => {
PartDefBodyElement::Comment(dummy_node(n, n.value.clone()))
}
PartDefBodyElement::Annotation(n) => {
PartDefBodyElement::Annotation(dummy_node(n, n.value.clone()))
}
PartDefBodyElement::Other(text) => PartDefBodyElement::Other(text.clone()),
PartDefBodyElement::AttributeDef(n) => {
PartDefBodyElement::AttributeDef(dummy_node(n, normalize_attribute_def(&n.value)))
}
PartDefBodyElement::AttributeUsage(n) => {
PartDefBodyElement::AttributeUsage(dummy_node(n, normalize_attribute_usage(&n.value)))
}
PartDefBodyElement::RequirementUsage(n) => {
PartDefBodyElement::RequirementUsage(dummy_node(n, n.value.clone()))
}
PartDefBodyElement::Ref(n) => {
PartDefBodyElement::Ref(dummy_node(n, normalize_ref_decl(&n.value)))
}
PartDefBodyElement::PortUsage(n) => {
PartDefBodyElement::PortUsage(dummy_node(n, normalize_port_usage(&n.value)))
}
PartDefBodyElement::PartUsage(n) => {
PartDefBodyElement::PartUsage(Box::new(dummy_node(n, normalize_part_usage(&n.value))))
}
PartDefBodyElement::OccurrenceUsage(n) => {
PartDefBodyElement::OccurrenceUsage(Box::new(dummy_node(n, n.value.clone())))
}
PartDefBodyElement::InterfaceDef(n) => {
PartDefBodyElement::InterfaceDef(dummy_node(n, normalize_interface_def(&n.value)))
}
PartDefBodyElement::InterfaceUsage(n) => {
PartDefBodyElement::InterfaceUsage(dummy_node(n, n.value.clone()))
}
PartDefBodyElement::Connect(n) => {
PartDefBodyElement::Connect(dummy_node(n, n.value.clone()))
}
PartDefBodyElement::Connection(n) => {
PartDefBodyElement::Connection(dummy_node(n, n.value.clone()))
}
PartDefBodyElement::Perform(n) => {
PartDefBodyElement::Perform(dummy_node(n, n.value.clone()))
}
PartDefBodyElement::Allocate(n) => {
PartDefBodyElement::Allocate(dummy_node(n, n.value.clone()))
}
PartDefBodyElement::OpaqueMember(n) => {
PartDefBodyElement::OpaqueMember(dummy_node(n, n.value.clone()))
}
PartDefBodyElement::ExhibitState(n) => {
PartDefBodyElement::ExhibitState(dummy_node(n, n.value.clone()))
}
};
dummy_node(el, value)
}
fn normalize_attribute_usage(a: &AttributeUsage) -> AttributeUsage {
AttributeUsage {
name: a.name.clone(),
typing: a.typing.clone(),
redefines: a.redefines.clone(),
value: a.value.clone(),
body: a.body.clone(),
name_span: None,
typing_span: None,
redefines_span: None,
}
}
fn normalize_part_usage(p: &PartUsage) -> PartUsage {
PartUsage {
is_individual: p.is_individual,
name: p.name.clone(),
type_name: p.type_name.clone(),
multiplicity: p.multiplicity.clone(),
ordered: p.ordered,
subsets: p.subsets.clone(),
redefines: p.redefines.clone(),
value: p.value.clone(),
body: normalize_part_usage_body(&p.body),
name_span: None,
type_ref_span: None,
}
}
fn normalize_part_usage_body(b: &PartUsageBody) -> PartUsageBody {
match b {
PartUsageBody::Semicolon => PartUsageBody::Semicolon,
PartUsageBody::Brace { elements } => PartUsageBody::Brace {
elements: elements
.iter()
.map(normalize_part_usage_body_element_node)
.collect(),
},
}
}
fn normalize_perform(p: &Perform) -> Perform {
Perform {
action_name: p.action_name.clone(),
type_name: p.type_name.clone(),
body: normalize_perform_body(&p.body),
}
}
fn normalize_perform_body(b: &PerformBody) -> PerformBody {
match b {
PerformBody::Semicolon => PerformBody::Semicolon,
PerformBody::Brace { elements } => PerformBody::Brace {
elements: elements
.iter()
.map(normalize_perform_body_element_node)
.collect(),
},
}
}
fn normalize_perform_body_element_node(el: &Node<PerformBodyElement>) -> Node<PerformBodyElement> {
let value = match &el.value {
PerformBodyElement::Doc(n) => PerformBodyElement::Doc(dummy_node(n, n.value.clone())),
PerformBodyElement::InOut(n) => PerformBodyElement::InOut(dummy_node(
n,
PerformInOutBinding {
direction: n.value.direction,
name: n.value.name.clone(),
value: normalize_expression_node(&n.value.value),
},
)),
};
dummy_node(el, value)
}
fn normalize_expression_node(node: &Node<Expression>) -> Node<Expression> {
let value = match &node.value {
Expression::LiteralInteger(x) => Expression::LiteralInteger(*x),
Expression::LiteralReal(s) => Expression::LiteralReal(s.clone()),
Expression::LiteralString(s) => Expression::LiteralString(s.clone()),
Expression::LiteralBoolean(b) => Expression::LiteralBoolean(*b),
Expression::FeatureRef(s) => Expression::FeatureRef(s.clone()),
Expression::MemberAccess(base, member) => {
Expression::MemberAccess(Box::new(normalize_expression_node(base)), member.clone())
}
Expression::Index { base, index } => Expression::Index {
base: Box::new(normalize_expression_node(base)),
index: Box::new(normalize_expression_node(index)),
},
Expression::Bracket(inner) => {
Expression::Bracket(Box::new(normalize_expression_node(inner)))
}
Expression::LiteralWithUnit { value: v, unit } => Expression::LiteralWithUnit {
value: Box::new(normalize_expression_node(v)),
unit: Box::new(normalize_expression_node(unit)),
},
Expression::BinaryOp { op, left, right } => Expression::BinaryOp {
op: op.clone(),
left: Box::new(normalize_expression_node(left)),
right: Box::new(normalize_expression_node(right)),
},
Expression::UnaryOp { op, operand } => Expression::UnaryOp {
op: op.clone(),
operand: Box::new(normalize_expression_node(operand)),
},
Expression::Invocation { callee, args } => Expression::Invocation {
callee: Box::new(normalize_expression_node(callee)),
args: args.iter().map(normalize_expression_node).collect(),
},
Expression::Tuple(items) => {
Expression::Tuple(items.iter().map(normalize_expression_node).collect())
}
Expression::Null => Expression::Null,
};
Node::new(Span::dummy(), value)
}
fn normalize_part_usage_body_element_node(
el: &Node<PartUsageBodyElement>,
) -> Node<PartUsageBodyElement> {
let value = match &el.value {
PartUsageBodyElement::Error(n) => {
PartUsageBodyElement::Error(dummy_node(n, n.value.clone()))
}
PartUsageBodyElement::Doc(n) => PartUsageBodyElement::Doc(dummy_node(n, n.value.clone())),
PartUsageBodyElement::Annotation(n) => {
PartUsageBodyElement::Annotation(dummy_node(n, n.value.clone()))
}
PartUsageBodyElement::AttributeUsage(n) => {
PartUsageBodyElement::AttributeUsage(dummy_node(n, normalize_attribute_usage(&n.value)))
}
PartUsageBodyElement::PartUsage(n) => {
PartUsageBodyElement::PartUsage(Box::new(dummy_node(n, normalize_part_usage(&n.value))))
}
PartUsageBodyElement::OccurrenceUsage(n) => {
PartUsageBodyElement::OccurrenceUsage(Box::new(dummy_node(n, n.value.clone())))
}
PartUsageBodyElement::PortUsage(n) => {
PartUsageBodyElement::PortUsage(dummy_node(n, normalize_port_usage(&n.value)))
}
PartUsageBodyElement::Ref(n) => {
PartUsageBodyElement::Ref(dummy_node(n, normalize_ref_decl(&n.value)))
}
PartUsageBodyElement::Bind(n) => PartUsageBodyElement::Bind(dummy_node(n, n.value.clone())),
PartUsageBodyElement::InterfaceUsage(n) => {
PartUsageBodyElement::InterfaceUsage(dummy_node(n, n.value.clone()))
}
PartUsageBodyElement::Connect(n) => {
PartUsageBodyElement::Connect(dummy_node(n, n.value.clone()))
}
PartUsageBodyElement::Perform(n) => {
PartUsageBodyElement::Perform(dummy_node(n, normalize_perform(&n.value)))
}
PartUsageBodyElement::Allocate(n) => {
PartUsageBodyElement::Allocate(dummy_node(n, n.value.clone()))
}
PartUsageBodyElement::Satisfy(n) => {
PartUsageBodyElement::Satisfy(dummy_node(n, n.value.clone()))
}
PartUsageBodyElement::StateUsage(n) => {
PartUsageBodyElement::StateUsage(dummy_node(n, n.value.clone()))
}
PartUsageBodyElement::MetadataAnnotation(n) => {
PartUsageBodyElement::MetadataAnnotation(dummy_node(n, n.value.clone()))
}
};
dummy_node(el, value)
}
fn normalize_port_usage(p: &PortUsage) -> PortUsage {
PortUsage {
name: p.name.clone(),
type_name: p.type_name.clone(),
multiplicity: p.multiplicity.clone(),
subsets: p.subsets.clone(),
redefines: p.redefines.clone(),
body: normalize_port_body(&p.body),
name_span: None,
type_ref_span: None,
}
}
fn normalize_port_body(b: &PortBody) -> PortBody {
match b {
PortBody::Semicolon => PortBody::Semicolon,
PortBody::Brace => PortBody::Brace,
PortBody::BraceWithPorts { elements } => PortBody::BraceWithPorts {
elements: elements
.iter()
.map(|n| dummy_node(n, normalize_port_usage(&n.value)))
.collect(),
},
}
}
fn normalize_port_def(p: &PortDef) -> PortDef {
PortDef {
identification: p.identification.clone(),
specializes: p.specializes.clone(),
body: normalize_port_def_body(&p.body),
}
}
fn normalize_port_def_body(b: &PortDefBody) -> PortDefBody {
match b {
PortDefBody::Semicolon => PortDefBody::Semicolon,
PortDefBody::Brace { elements } => PortDefBody::Brace {
elements: elements
.iter()
.map(normalize_port_def_body_element_node)
.collect(),
},
}
}
fn normalize_port_def_body_element_node(el: &Node<PortDefBodyElement>) -> Node<PortDefBodyElement> {
let value = match &el.value {
PortDefBodyElement::InOutDecl(n) => {
PortDefBodyElement::InOutDecl(dummy_node(n, n.value.clone()))
}
PortDefBodyElement::Doc(n) => PortDefBodyElement::Doc(dummy_node(n, n.value.clone())),
PortDefBodyElement::AttributeDef(n) => {
PortDefBodyElement::AttributeDef(dummy_node(n, normalize_attribute_def(&n.value)))
}
PortDefBodyElement::AttributeUsage(n) => {
PortDefBodyElement::AttributeUsage(dummy_node(n, normalize_attribute_usage(&n.value)))
}
PortDefBodyElement::PortUsage(n) => {
PortDefBodyElement::PortUsage(dummy_node(n, normalize_port_usage(&n.value)))
}
};
dummy_node(el, value)
}
fn normalize_interface_def(i: &InterfaceDef) -> InterfaceDef {
InterfaceDef {
identification: i.identification.clone(),
body: normalize_interface_def_body(&i.body),
}
}
fn normalize_connection_def(c: &ConnectionDef) -> ConnectionDef {
ConnectionDef {
annotation: c.annotation.clone(),
identification: c.identification.clone(),
body: normalize_connection_def_body(&c.body),
}
}
fn normalize_connection_def_body(b: &ConnectionDefBody) -> ConnectionDefBody {
match b {
ConnectionDefBody::Semicolon => ConnectionDefBody::Semicolon,
ConnectionDefBody::Brace { elements } => ConnectionDefBody::Brace {
elements: elements
.iter()
.map(normalize_connection_def_body_element_node)
.collect(),
},
}
}
fn normalize_connection_def_body_element_node(
el: &Node<ConnectionDefBodyElement>,
) -> Node<ConnectionDefBodyElement> {
let value = match &el.value {
ConnectionDefBodyElement::EndDecl(n) => {
ConnectionDefBodyElement::EndDecl(dummy_node(n, normalize_end_decl(&n.value)))
}
ConnectionDefBodyElement::RefDecl(n) => {
ConnectionDefBodyElement::RefDecl(dummy_node(n, normalize_ref_decl(&n.value)))
}
ConnectionDefBodyElement::ConnectStmt(n) => {
ConnectionDefBodyElement::ConnectStmt(dummy_node(n, n.value.clone()))
}
};
dummy_node(el, value)
}
fn normalize_metadata_def(m: &MetadataDef) -> MetadataDef {
MetadataDef {
is_abstract: m.is_abstract,
identification: m.identification.clone(),
body: m.body.clone(),
}
}
fn normalize_enum_def(e: &EnumDef) -> EnumDef {
EnumDef {
identification: e.identification.clone(),
body: e.body.clone(),
}
}
fn normalize_occurrence_def(o: &OccurrenceDef) -> OccurrenceDef {
OccurrenceDef {
is_abstract: o.is_abstract,
identification: o.identification.clone(),
body: o.body.clone(),
}
}
fn normalize_interface_def_body(b: &InterfaceDefBody) -> InterfaceDefBody {
match b {
InterfaceDefBody::Semicolon => InterfaceDefBody::Semicolon,
InterfaceDefBody::Brace { elements } => InterfaceDefBody::Brace {
elements: elements
.iter()
.map(normalize_interface_def_body_element_node)
.collect(),
},
}
}
fn normalize_interface_def_body_element_node(
el: &Node<InterfaceDefBodyElement>,
) -> Node<InterfaceDefBodyElement> {
let value = match &el.value {
InterfaceDefBodyElement::Doc(n) => {
InterfaceDefBodyElement::Doc(dummy_node(n, n.value.clone()))
}
InterfaceDefBodyElement::EndDecl(n) => {
InterfaceDefBodyElement::EndDecl(dummy_node(n, normalize_end_decl(&n.value)))
}
InterfaceDefBodyElement::RefDecl(n) => {
InterfaceDefBodyElement::RefDecl(dummy_node(n, normalize_ref_decl(&n.value)))
}
InterfaceDefBodyElement::ConnectStmt(n) => {
InterfaceDefBodyElement::ConnectStmt(dummy_node(n, n.value.clone()))
}
};
dummy_node(el, value)
}
fn normalize_end_decl(e: &EndDecl) -> EndDecl {
EndDecl {
name: e.name.clone(),
type_name: e.type_name.clone(),
uses_derived_syntax: e.uses_derived_syntax,
name_span: None,
type_ref_span: None,
}
}
fn normalize_ref_decl(r: &RefDecl) -> RefDecl {
RefDecl {
name: r.name.clone(),
type_name: r.type_name.clone(),
value: r.value.clone(),
body: r.body.clone(),
name_span: None,
type_ref_span: None,
}
}
fn normalize_action_def(a: &ActionDef) -> ActionDef {
ActionDef {
identification: a.identification.clone(),
body: normalize_action_def_body(&a.body),
}
}
fn normalize_action_def_body(b: &ActionDefBody) -> ActionDefBody {
match b {
ActionDefBody::Semicolon => ActionDefBody::Semicolon,
ActionDefBody::Brace { elements } => ActionDefBody::Brace {
elements: elements
.iter()
.map(normalize_action_def_body_element_node)
.collect(),
},
}
}
fn normalize_action_def_body_element_node(
el: &Node<ActionDefBodyElement>,
) -> Node<ActionDefBodyElement> {
let value = match &el.value {
ActionDefBodyElement::Error(n) => {
ActionDefBodyElement::Error(dummy_node(n, n.value.clone()))
}
ActionDefBodyElement::InOutDecl(n) => {
ActionDefBodyElement::InOutDecl(dummy_node(n, n.value.clone()))
}
ActionDefBodyElement::Doc(n) => ActionDefBodyElement::Doc(dummy_node(n, n.value.clone())),
ActionDefBodyElement::Annotation(n) => {
ActionDefBodyElement::Annotation(dummy_node(n, n.value.clone()))
}
ActionDefBodyElement::RefDecl(n) => {
ActionDefBodyElement::RefDecl(dummy_node(n, normalize_ref_decl(&n.value)))
}
ActionDefBodyElement::Perform(n) => {
ActionDefBodyElement::Perform(dummy_node(n, normalize_perform(&n.value)))
}
ActionDefBodyElement::Bind(n) => ActionDefBodyElement::Bind(dummy_node(n, n.value.clone())),
ActionDefBodyElement::Flow(n) => ActionDefBodyElement::Flow(dummy_node(n, n.value.clone())),
ActionDefBodyElement::FirstStmt(n) => {
ActionDefBodyElement::FirstStmt(dummy_node(n, n.value.clone()))
}
ActionDefBodyElement::MergeStmt(n) => {
ActionDefBodyElement::MergeStmt(dummy_node(n, n.value.clone()))
}
ActionDefBodyElement::StateUsage(n) => {
ActionDefBodyElement::StateUsage(dummy_node(n, n.value.clone()))
}
ActionDefBodyElement::ActionUsage(n) => ActionDefBodyElement::ActionUsage(Box::new(
dummy_node(n, normalize_action_usage(&n.value)),
)),
ActionDefBodyElement::Assign(n) => {
ActionDefBodyElement::Assign(dummy_node(n, n.value.clone()))
}
ActionDefBodyElement::ForLoop(n) => {
ActionDefBodyElement::ForLoop(dummy_node(n, n.value.clone()))
}
ActionDefBodyElement::ThenAction(n) => {
ActionDefBodyElement::ThenAction(dummy_node(n, n.value.clone()))
}
ActionDefBodyElement::Decl(n) => ActionDefBodyElement::Decl(dummy_node(n, n.value.clone())),
};
dummy_node(el, value)
}
fn normalize_action_usage(a: &ActionUsage) -> ActionUsage {
ActionUsage {
name: a.name.clone(),
type_name: a.type_name.clone(),
accept: a.accept.clone(),
body: normalize_action_usage_body(&a.body),
name_span: None,
type_ref_span: None,
}
}
fn normalize_action_usage_body(b: &ActionUsageBody) -> ActionUsageBody {
match b {
ActionUsageBody::Semicolon => ActionUsageBody::Semicolon,
ActionUsageBody::Brace { elements } => ActionUsageBody::Brace {
elements: elements
.iter()
.map(normalize_action_usage_body_element_node)
.collect(),
},
}
}
fn normalize_action_usage_body_element_node(
el: &Node<ActionUsageBodyElement>,
) -> Node<ActionUsageBodyElement> {
let value = match &el.value {
ActionUsageBodyElement::Error(n) => {
ActionUsageBodyElement::Error(dummy_node(n, n.value.clone()))
}
ActionUsageBodyElement::Doc(n) => {
ActionUsageBodyElement::Doc(dummy_node(n, n.value.clone()))
}
ActionUsageBodyElement::Annotation(n) => {
ActionUsageBodyElement::Annotation(dummy_node(n, n.value.clone()))
}
ActionUsageBodyElement::InOutDecl(n) => {
ActionUsageBodyElement::InOutDecl(dummy_node(n, n.value.clone()))
}
ActionUsageBodyElement::RefDecl(n) => {
ActionUsageBodyElement::RefDecl(dummy_node(n, normalize_ref_decl(&n.value)))
}
ActionUsageBodyElement::Bind(n) => {
ActionUsageBodyElement::Bind(dummy_node(n, n.value.clone()))
}
ActionUsageBodyElement::Flow(n) => {
ActionUsageBodyElement::Flow(dummy_node(n, n.value.clone()))
}
ActionUsageBodyElement::FirstStmt(n) => {
ActionUsageBodyElement::FirstStmt(dummy_node(n, n.value.clone()))
}
ActionUsageBodyElement::MergeStmt(n) => {
ActionUsageBodyElement::MergeStmt(dummy_node(n, n.value.clone()))
}
ActionUsageBodyElement::StateUsage(n) => {
ActionUsageBodyElement::StateUsage(dummy_node(n, n.value.clone()))
}
ActionUsageBodyElement::ActionUsage(n) => ActionUsageBodyElement::ActionUsage(Box::new(
dummy_node(n, normalize_action_usage(&n.value)),
)),
ActionUsageBodyElement::Assign(n) => {
ActionUsageBodyElement::Assign(dummy_node(n, n.value.clone()))
}
ActionUsageBodyElement::ForLoop(n) => {
ActionUsageBodyElement::ForLoop(dummy_node(n, n.value.clone()))
}
ActionUsageBodyElement::ThenAction(n) => {
ActionUsageBodyElement::ThenAction(dummy_node(n, n.value.clone()))
}
ActionUsageBodyElement::Decl(n) => {
ActionUsageBodyElement::Decl(dummy_node(n, n.value.clone()))
}
};
dummy_node(el, value)
}