Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Type T_TRANS
- Event As String
- Next As String
- End Type
- Private Type T_STATE
- Name As String
- ParentName As String
- TransCount As Integer
- Trans(128) As T_TRANS
- End Type
- Sub PlantUML2Matrix()
- ' Config
- CodeRow = 1
- CodeCol = 1
- MtrRow = 3
- MtrCol = 2
- ' Variable
- Dim States(128) As T_STATE
- Dim Events(128) As String
- Dim Line As String
- Dim EventFound As Boolean
- ParentName = ""
- StateCount = 0
- Lines = Split(Cells(CodeRow, CodeCol), vbLf)
- LineMax = UBound(Lines)
- For i = 0 To LineMax
- Line = Lines(i)
- If InStr(Line, "*") > 0 Then
- ' Through Start/Exit
- ElseIf InStr(Line, "hidden") > 0 Then
- ' Through hidden
- ElseIf InStr(Line, "{") > 0 Then
- ' Parent State
- ParentName = MidStr(Line)
- ElseIf InStr(Line, "}") > 0 Then
- ' End Parent State
- ParentName = ""
- ElseIf InStr(Line, "state") > 0 Then
- ' Sub State
- States(StateCount).Name = MidStr(Line)
- States(StateCount).ParentName = ParentName
- StateCount = StateCount + 1
- ElseIf InStr(Line, ">") > 0 Then
- ' Transition
- TransSrc = MidTransSrc(Line)
- TransDsc = MidTransDst(Line)
- TransEvent = MidTransEvent(Line)
- ' Event Add
- EventFound = False
- For j = 0 To 128
- If Events(j) = "" Then
- Exit For
- ElseIf Events(j) = TransEvent Then
- EventFound = True
- End If
- Next j
- If EventFound = False Then
- Events(EventCount) = TransEvent
- EventCount = EventCount + 1
- End If
- ' Trans Add
- For j = 0 To 128
- If States(j).Name = "" Then
- Exit For
- ElseIf States(j).Name = TransSrc Or States(j).ParentName = TransSrc Then
- TransCount = States(j).TransCount
- States(j).Trans(TransCount).Event = TransEvent
- States(j).Trans(TransCount).Next = TransDsc
- States(j).TransCount = TransCount + 1
- End If
- Next j
- End If
- Next i
- StateCurrent = 0
- For i = 0 To EventCount
- ' Write Events
- EventName = Events(i)
- Cells(MtrRow, MtrCol + 2 + i).Value = EventName
- Next i
- ' Search Trans
- For j = 0 To StateCount
- ' 遷移先を探索
- TransFound = False
- For k = 0 To States(j).TransCount
- TransEvent = States(j).Trans(k).Event
- If TransEvent = "" Then
- Exit For
- Else
- ' 遷移先イベントがある場合はイベントを検索
- For i = 0 To EventCount
- EventName = Cells(MtrRow, MtrCol + 2 + i).Value
- If TransEvent = EventName Then
- Cells(MtrRow + 1 + StateCurrent, MtrCol + 0).Value = States(j).ParentName
- Cells(MtrRow + 1 + StateCurrent, MtrCol + 1).Value = States(j).Name
- Cells(MtrRow + 1 + StateCurrent, MtrCol + 2 + i).Value = States(j).Trans(k).Next
- TransFound = True
- End If
- Next i
- End If
- Next k
- ' 遷移先が見つかった場合はカウント
- If TransFound = True Then
- StateCurrent = StateCurrent + 1
- End If
- Next j
- End Sub
- Function MidStr(Str As String)
- If InStr(Line, "as") > 0 Then
- Sp = InStr(Str, """") + 1
- Ep = InStrRev(Str, """")
- Length = Ep - Sp
- Else
- Sp = InStr(Str, "state ") + 5
- If InStr(Str, "{") > 0 Then
- Ep = InStrRev(Str, "{")
- Else
- Ep = Len(Str) + 1
- End If
- Length = Ep - Sp
- End If
- MidStr = Trim(Mid(Str, Sp, Length))
- End Function
- Function MidTransSrc(Str As String)
- Sp = 1
- Ep = InStr(Str, "-")
- Length = Ep - Sp
- MidTransSrc = Trim(Mid(Str, Sp, Length))
- End Function
- Function MidTransDst(Str As String)
- Sp = InStr(Str, ">")
- Ep = InStr(Str, ":")
- Length = Ep - Sp
- MidTransDst = Trim(Mid(Str, Sp, Length))
- End Function
- Function MidTransEvent(Str As String)
- Sp = InStr(Str, ":") + 1
- Ep = Len(Str) + 1
- Length = Ep - Sp
- MidTransEvent = Trim(Mid(Str, Sp, Length))
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement