// BPMN diagram AST structures package ast // BPMNDiagram represents a BPMN (Business Process Model and Notation) diagram type BPMNDiagram struct { Elements []*BPMNElement `json:"elements"` Flows []*BPMNFlow `json:"flows"` Pools []*BPMNPool `json:"pools,omitempty"` Lanes []*BPMNLane `json:"lanes,omitempty"` Title *string `json:"title,omitempty"` Config map[string]any `json:"config,omitempty"` } type BPMNElement struct { ID string `json:"id"` Name string `json:"name"` Type BPMNElementType `json:"type"` SubType *string `json:"subType,omitempty"` Pool *string `json:"pool,omitempty"` Lane *string `json:"lane,omitempty"` Properties map[string]any `json:"properties,omitempty"` CssClasses []string `json:"cssClasses,omitempty"` } type BPMNElementType string const ( // Events BPMNElementStartEvent BPMNElementType = "startEvent" BPMNElementEndEvent BPMNElementType = "endEvent" BPMNElementIntermediateEvent BPMNElementType = "intermediateEvent" // Activities BPMNElementTask BPMNElementType = "task" BPMNElementUserTask BPMNElementType = "userTask" BPMNElementServiceTask BPMNElementType = "serviceTask" BPMNElementSubProcess BPMNElementType = "subProcess" // Gateways BPMNElementExclusiveGateway BPMNElementType = "exclusiveGateway" BPMNElementParallelGateway BPMNElementType = "parallelGateway" BPMNElementInclusiveGateway BPMNElementType = "inclusiveGateway" BPMNElementEventGateway BPMNElementType = "eventGateway" // Data BPMNElementDataObject BPMNElementType = "dataObject" BPMNElementDataStore BPMNElementType = "dataStore" // Artifacts BPMNElementTextAnnotation BPMNElementType = "textAnnotation" BPMNElementGroup BPMNElementType = "group" ) type BPMNFlow struct { ID string `json:"id"` Name *string `json:"name,omitempty"` From string `json:"from"` To string `json:"to"` Type BPMNFlowType `json:"type"` Condition *string `json:"condition,omitempty"` IsDefault bool `json:"isDefault,omitempty"` Properties map[string]any `json:"properties,omitempty"` } type BPMNFlowType string const ( BPMNFlowSequence BPMNFlowType = "sequenceFlow" BPMNFlowMessage BPMNFlowType = "messageFlow" BPMNFlowAssociation BPMNFlowType = "association" ) type BPMNPool struct { ID string `json:"id"` Name string `json:"name"` Participant *string `json:"participant,omitempty"` Lanes []string `json:"lanes,omitempty"` } type BPMNLane struct { ID string `json:"id"` Name string `json:"name"` Pool string `json:"pool"` Elements []string `json:"elements,omitempty"` } // Type returns the diagram type func (b *BPMNDiagram) Type() DiagramType { return DiagramTypeBPMN } // Validate checks if the BPMN diagram is valid func (b *BPMNDiagram) Validate() error { // Create element map for validation elementMap := make(map[string]bool) for _, element := range b.Elements { elementMap[element.ID] = true } // Validate flows reference valid elements for _, flow := range b.Flows { if !elementMap[flow.From] { return NewValidationError("flow references non-existent element: " + flow.From) } if !elementMap[flow.To] { return NewValidationError("flow references non-existent element: " + flow.To) } } return nil } // NewBPMNDiagram creates a new BPMN diagram func NewBPMNDiagram() *BPMNDiagram { return &BPMNDiagram{ Elements: make([]*BPMNElement, 0), Flows: make([]*BPMNFlow, 0), Pools: make([]*BPMNPool, 0), Lanes: make([]*BPMNLane, 0), Config: make(map[string]any), } } // AddElement adds an element to the BPMN diagram func (b *BPMNDiagram) AddElement(element *BPMNElement) { b.Elements = append(b.Elements, element) } // AddFlow adds a flow to the BPMN diagram func (b *BPMNDiagram) AddFlow(flow *BPMNFlow) { b.Flows = append(b.Flows, flow) } // FindElement finds an element by ID func (b *BPMNDiagram) FindElement(id string) *BPMNElement { for _, element := range b.Elements { if element.ID == id { return element } } return nil }