Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. Private Type T_TRANS
  2. Event As String
  3. Next As String
  4. End Type
  5.  
  6. Private Type T_STATE
  7. Name As String
  8. ParentName As String
  9. TransCount As Integer
  10. Trans(128) As T_TRANS
  11. End Type
  12.  
  13.  
  14.  
  15. Sub PlantUML2Matrix()
  16.  
  17. ' Config
  18. CodeRow = 1
  19. CodeCol = 1
  20.  
  21. MtrRow = 3
  22. MtrCol = 2
  23.  
  24. ' Variable
  25. Dim States(128) As T_STATE
  26. Dim Events(128) As String
  27. Dim Line As String
  28. Dim EventFound As Boolean
  29. ParentName = ""
  30. StateCount = 0
  31.  
  32. Lines = Split(Cells(CodeRow, CodeCol), vbLf)
  33. LineMax = UBound(Lines)
  34.  
  35.  
  36. For i = 0 To LineMax
  37.  
  38. Line = Lines(i)
  39.  
  40.  
  41. If InStr(Line, "*") > 0 Then
  42. ' Through Start/Exit
  43.  
  44. ElseIf InStr(Line, "hidden") > 0 Then
  45. ' Through hidden
  46.  
  47. ElseIf InStr(Line, "{") > 0 Then
  48.  
  49. ' Parent State
  50. ParentName = MidStr(Line)
  51.  
  52. ElseIf InStr(Line, "}") > 0 Then
  53.  
  54. ' End Parent State
  55. ParentName = ""
  56.  
  57. ElseIf InStr(Line, "state") > 0 Then
  58.  
  59. ' Sub State
  60. States(StateCount).Name = MidStr(Line)
  61. States(StateCount).ParentName = ParentName
  62. StateCount = StateCount + 1
  63.  
  64. ElseIf InStr(Line, ">") > 0 Then
  65. ' Transition
  66. TransSrc = MidTransSrc(Line)
  67. TransDsc = MidTransDst(Line)
  68. TransEvent = MidTransEvent(Line)
  69.  
  70. ' Event Add
  71. EventFound = False
  72. For j = 0 To 128
  73.  
  74. If Events(j) = "" Then
  75. Exit For
  76.  
  77. ElseIf Events(j) = TransEvent Then
  78. EventFound = True
  79.  
  80. End If
  81. Next j
  82.  
  83. If EventFound = False Then
  84. Events(EventCount) = TransEvent
  85. EventCount = EventCount + 1
  86. End If
  87.  
  88. ' Trans Add
  89. For j = 0 To 128
  90. If States(j).Name = "" Then
  91. Exit For
  92.  
  93. ElseIf States(j).Name = TransSrc Or States(j).ParentName = TransSrc Then
  94. TransCount = States(j).TransCount
  95. States(j).Trans(TransCount).Event = TransEvent
  96. States(j).Trans(TransCount).Next = TransDsc
  97. States(j).TransCount = TransCount + 1
  98. End If
  99. Next j
  100.  
  101. End If
  102.  
  103. Next i
  104.  
  105.  
  106. StateCurrent = 0
  107. For i = 0 To EventCount
  108.  
  109. ' Write Events
  110. EventName = Events(i)
  111. Cells(MtrRow, MtrCol + 2 + i).Value = EventName
  112. Next i
  113.  
  114. ' Search Trans
  115. For j = 0 To StateCount
  116.  
  117. ' 遷移先を探索
  118. TransFound = False
  119.  
  120. For k = 0 To States(j).TransCount
  121.  
  122. TransEvent = States(j).Trans(k).Event
  123.  
  124. If TransEvent = "" Then
  125. Exit For
  126.  
  127. Else
  128.  
  129. ' 遷移先イベントがある場合はイベントを検索
  130.  
  131. For i = 0 To EventCount
  132.  
  133. EventName = Cells(MtrRow, MtrCol + 2 + i).Value
  134.  
  135. If TransEvent = EventName Then
  136.  
  137. Cells(MtrRow + 1 + StateCurrent, MtrCol + 0).Value = States(j).ParentName
  138. Cells(MtrRow + 1 + StateCurrent, MtrCol + 1).Value = States(j).Name
  139. Cells(MtrRow + 1 + StateCurrent, MtrCol + 2 + i).Value = States(j).Trans(k).Next
  140.  
  141. TransFound = True
  142. End If
  143. Next i
  144.  
  145.  
  146.  
  147. End If
  148. Next k
  149.  
  150. ' 遷移先が見つかった場合はカウント
  151. If TransFound = True Then
  152. StateCurrent = StateCurrent + 1
  153. End If
  154. Next j
  155.  
  156. End Sub
  157.  
  158.  
  159. Function MidStr(Str As String)
  160.  
  161. If InStr(Line, "as") > 0 Then
  162.  
  163. Sp = InStr(Str, """") + 1
  164. Ep = InStrRev(Str, """")
  165. Length = Ep - Sp
  166.  
  167. Else
  168. Sp = InStr(Str, "state ") + 5
  169. If InStr(Str, "{") > 0 Then
  170. Ep = InStrRev(Str, "{")
  171. Else
  172. Ep = Len(Str) + 1
  173. End If
  174. Length = Ep - Sp
  175. End If
  176. MidStr = Trim(Mid(Str, Sp, Length))
  177.  
  178. End Function
  179.  
  180. Function MidTransSrc(Str As String)
  181.  
  182. Sp = 1
  183. Ep = InStr(Str, "-")
  184. Length = Ep - Sp
  185. MidTransSrc = Trim(Mid(Str, Sp, Length))
  186.  
  187. End Function
  188.  
  189. Function MidTransDst(Str As String)
  190.  
  191. Sp = InStr(Str, ">")
  192. Ep = InStr(Str, ":")
  193. Length = Ep - Sp
  194. MidTransDst = Trim(Mid(Str, Sp, Length))
  195.  
  196. End Function
  197.  
  198. Function MidTransEvent(Str As String)
  199.  
  200. Sp = InStr(Str, ":") + 1
  201. Ep = Len(Str) + 1
  202. Length = Ep - Sp
  203. MidTransEvent = Trim(Mid(Str, Sp, Length))
  204.  
  205. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement