pione 0.4.2 → 0.5.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (306) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +1 -1
  3. data/History.txt +6 -0
  4. data/example/ActionError/ActionError.action.md +11 -0
  5. data/example/ActionError/ActionError.pione +6 -3
  6. data/example/ActionError/ActionError.pnml +86 -0
  7. data/example/ActionError/Package.pione +2 -0
  8. data/example/ActionError/pione-package.json +5 -1
  9. data/example/CTFCorrection/CTFCorrection.action.md +46 -0
  10. data/example/CTFCorrection/CTFCorrection.pione +19 -41
  11. data/example/CTFCorrection/CTFCorrection.pnml +839 -0
  12. data/example/CTFCorrection/Package.pione +1 -0
  13. data/example/CTFCorrection/Params.pione +21 -0
  14. data/example/CTFCorrection/pione-package.json +20 -0
  15. data/example/ChildPackage/ChildPackage.pione +8 -0
  16. data/example/ChildPackage/pione-package.json +20 -0
  17. data/example/CountChar/CountChar.pione +31 -0
  18. data/example/CountChar/CountChar.pnml +239 -0
  19. data/example/CountChar/Main.pione +6 -26
  20. data/example/CountChar/Main.pnml +32 -100
  21. data/example/CountChar/Package.pione +1 -0
  22. data/example/CountChar/pione-package.json +3 -1
  23. data/example/DeferredChoice/DeferredChoice.action.md +46 -0
  24. data/example/DeferredChoice/DeferredChoice.pione +2 -7
  25. data/example/DeferredChoice/DeferredChoice.pnml +371 -0
  26. data/example/DeferredChoice/Package.pione +4 -0
  27. data/example/DeferredChoice/pione-package.json +7 -3
  28. data/example/DeferredChoiceWithPage/DeferredChoiceWithPage.action.md +34 -0
  29. data/example/DeferredChoiceWithPage/DefferredChoiceWithPage.pnml +371 -0
  30. data/example/DeferredChoiceWithPage/Package.pione +2 -0
  31. data/example/FeatureExample/FeatureExample.action.md +7 -0
  32. data/example/FeatureExample/FeatureExample.pione +7 -4
  33. data/example/FeatureExample/FeatureExample.pnml +86 -0
  34. data/example/FeatureExample/Package.pione +1 -0
  35. data/example/FeatureExample/pione-package.json +4 -0
  36. data/example/Fib/Fib.action.md +33 -0
  37. data/example/Fib/Fib.pnml +208 -0
  38. data/example/Fib/FibN.pnml +807 -0
  39. data/example/Fib/Package.pione +6 -0
  40. data/example/HelloWorld/HelloWorld.action.md +7 -0
  41. data/example/HelloWorld/HelloWorld.pione +6 -2
  42. data/example/HelloWorld/HelloWorld.pnml +86 -0
  43. data/example/HelloWorld/Package.pione +2 -0
  44. data/example/HelloWorld/pione-package.json +5 -1
  45. data/example/Interaction/Interaction.action.md +21 -0
  46. data/example/Interaction/Interaction.pnml +89 -0
  47. data/example/Interaction/Package.pione +2 -0
  48. data/example/LoopByTouch/LoopByTouch.pione +32 -12
  49. data/example/LoopByTouch/LoopByTouch.pnml +575 -0
  50. data/example/LoopByTouch/Package.pione +3 -0
  51. data/example/LoopByTouch/PairLoop.pione +6 -7
  52. data/example/LoopByTouch/PairLoop.pnml +188 -0
  53. data/example/LoopByTouch/SingleLoop.pione +6 -0
  54. data/example/LoopByTouch/SingleLoop.pnml +86 -0
  55. data/example/LoopByTouch/TripletLoop.pione +12 -13
  56. data/example/LoopByTouch/TripletLoop.pnml +239 -0
  57. data/example/LoopByTouch/pione-package.json +7 -3
  58. data/example/LucasNumber/LucasNumber.action.md +25 -0
  59. data/example/LucasNumber/LucasNumber.pnml +244 -0
  60. data/example/LucasNumber/LucasNumberN.pnml +1719 -0
  61. data/example/LucasNumber/Package.pione +2 -0
  62. data/example/MakePair/MakePair.pione +8 -10
  63. data/example/MakePair/MakePair.pnml +1141 -0
  64. data/example/MakePair/Package.pione +2 -0
  65. data/example/MakePair/pione-package.json +7 -3
  66. data/example/MakePair/scenario/case1/pione-scenario.json +30 -30
  67. data/example/MakePair/scenario/case2/pione-scenario.json +10 -10
  68. data/example/MakePair/scenario/case3/pione-scenario.json +28 -28
  69. data/example/OddSelector/OddSelector.pione +8 -8
  70. data/example/OddSelector/OddSelector.pnml +401 -0
  71. data/example/OddSelector/Package.pione +2 -0
  72. data/example/OddSelector/pione-package.json +4 -0
  73. data/example/OddSelector/scenario/pione-scenario.json +8 -8
  74. data/example/ParentPackage/ParentPackage.pione +13 -0
  75. data/example/ParentPackage/pione-package.json +18 -0
  76. data/example/PegasusWMS/Merge/Package.pione +2 -0
  77. data/example/PegasusWMS/Merge/PegasusWMSMerge.action.md +17 -0
  78. data/example/PegasusWMS/Merge/{Merge.pione → PegasusWMSMerge.pione} +9 -10
  79. data/example/PegasusWMS/Merge/PegasusWMSMerge.pnml +217 -0
  80. data/example/PegasusWMS/Merge/pione-package.json +6 -2
  81. data/example/PegasusWMS/Pipeline/Package.pione +2 -0
  82. data/example/PegasusWMS/Pipeline/PegasusWMSPipeline.action.md +17 -0
  83. data/example/PegasusWMS/Pipeline/{Pipeline.pione → PegasusWMSPipeline.pione} +7 -9
  84. data/example/PegasusWMS/Pipeline/PegasusWMSPipeline.pnml +137 -0
  85. data/example/PegasusWMS/Pipeline/pione-package.json +6 -2
  86. data/example/PegasusWMS/Split/Package.pione +2 -0
  87. data/example/PegasusWMS/Split/PegasusWMSSplit.action.md +19 -0
  88. data/example/PegasusWMS/Split/{Split.pione → PegasusWMSSplit.pione} +9 -10
  89. data/example/PegasusWMS/Split/PegasusWMSSplit.pnml +293 -0
  90. data/example/PegasusWMS/Split/pione-package.json +6 -2
  91. data/example/ScoreAggregation/Package.pione +2 -0
  92. data/example/ScoreAggregation/ScoreAggregation.action.md +56 -0
  93. data/example/ScoreAggregation/ScoreAggregation.pione +37 -76
  94. data/example/ScoreAggregation/ScoreAggregation.pnml +1221 -0
  95. data/example/ScoreAggregation/pione-package.json +6 -2
  96. data/example/ScoreAggregation/scenario/case1/pione-scenario.json +21 -21
  97. data/example/SelectRuleByParam/Package.pione +2 -0
  98. data/example/SelectRuleByParam/SelectRuleByParam.action.md +19 -0
  99. data/example/SelectRuleByParam/SelectRuleByParam.pnml +388 -0
  100. data/example/SequentialParameter/Package.pione +2 -0
  101. data/example/SequentialParameter/SequentialParameter.pione +9 -3
  102. data/example/SequentialParameter/SequentialParameter.pnml +140 -0
  103. data/example/SequentialParameter/pione-package.json +19 -0
  104. data/example/SerialProcessing/A.pione +25 -0
  105. data/example/SerialProcessing/A.pnml +395 -0
  106. data/example/SerialProcessing/B.pione +25 -0
  107. data/example/SerialProcessing/B.pnml +395 -0
  108. data/example/SerialProcessing/Package.pione +2 -0
  109. data/example/SerialProcessing/SerialProcessing.pione +9 -60
  110. data/example/SerialProcessing/SerialProcessing.pnml +160 -0
  111. data/example/SerialProcessing/pione-package.json +7 -1
  112. data/example/SieveOfEratosthenes/CreateUndeterminedNumbers.pnml +157 -0
  113. data/example/SieveOfEratosthenes/Package.pione +4 -0
  114. data/example/SieveOfEratosthenes/Sieve.pnml +1493 -0
  115. data/example/SieveOfEratosthenes/SieveOfEratosthenes.pnml +174 -0
  116. data/example/SingleParticlesWithRef/Create3dinfo.pnml +342 -0
  117. data/example/SingleParticlesWithRef/Package.pione +42 -0
  118. data/example/SingleParticlesWithRef/SingleParticlesWithRef.action.md +34 -0
  119. data/example/SingleParticlesWithRef/SingleParticlesWithRef.pnml +404 -0
  120. data/example/SingleParticlesWithRef/{Makefile → misc/Makefile} +0 -0
  121. data/example/SingleParticlesWithRef/{SingleParticlesWithRef.Display2.pione → misc/SingleParticlesWithRef.Display2.pione} +0 -0
  122. data/example/SingleParticlesWithRef/{SingleParticlesWithRef.Makefile → misc/SingleParticlesWithRef.Makefile} +0 -0
  123. data/example/SingleParticlesWithRef/{SingleParticlesWithRefFull.pione → misc/SingleParticlesWithRefFull.pione} +0 -0
  124. data/example/Sum/CalcEachLine.pione +30 -0
  125. data/example/Sum/CalcEachLine.pnml +327 -0
  126. data/example/Sum/Package.pione +2 -0
  127. data/example/Sum/Sum.action.md +35 -0
  128. data/example/Sum/Sum.pione +9 -35
  129. data/example/Sum/Sum.pnml +191 -0
  130. data/example/Sum/pione-package.json +5 -0
  131. data/example/Touch/Package.pione +2 -0
  132. data/example/Touch/Touch.pione +8 -2
  133. data/example/Touch/Touch.pnml +89 -0
  134. data/example/Touch/pione-package.json +4 -0
  135. data/example/WorkflowPatterns/01_Sequence/Package.pione +2 -0
  136. data/example/WorkflowPatterns/01_Sequence/Sequence.pione +9 -9
  137. data/example/WorkflowPatterns/01_Sequence/Sequence.pnml +191 -0
  138. data/example/WorkflowPatterns/01_Sequence/pione-package.json +19 -0
  139. data/example/WorkflowPatterns/02_PrallelSplit/Package.pione +2 -0
  140. data/example/WorkflowPatterns/02_PrallelSplit/ParallelSplit.pione +12 -12
  141. data/example/WorkflowPatterns/02_PrallelSplit/ParallelSplit.pnml +265 -0
  142. data/example/WorkflowPatterns/02_PrallelSplit/pione-package.json +19 -0
  143. data/example/WorkflowPatterns/03_Synchronization/Package.pione +2 -0
  144. data/example/WorkflowPatterns/03_Synchronization/Synchronization.pione +12 -13
  145. data/example/WorkflowPatterns/03_Synchronization/Synchronization.pnml +273 -0
  146. data/example/WorkflowPatterns/03_Synchronization/pione-package.json +19 -0
  147. data/example/WorkflowPatterns/04_ExclusiveChoice/ExclusiveChoice.pione +15 -22
  148. data/example/WorkflowPatterns/04_ExclusiveChoice/ExclusiveChoice.pnml +533 -0
  149. data/example/WorkflowPatterns/04_ExclusiveChoice/Package.pione +4 -0
  150. data/example/WorkflowPatterns/04_ExclusiveChoice/pione-package.json +19 -0
  151. data/example/WorkflowPatterns/05_SimpleMerge/Package.pione +4 -0
  152. data/example/WorkflowPatterns/05_SimpleMerge/SimpleMerge.pione +10 -18
  153. data/example/WorkflowPatterns/05_SimpleMerge/SimpleMerge.pnml +431 -0
  154. data/example/WorkflowPatterns/05_SimpleMerge/pione-package.json +19 -0
  155. data/example/WorkflowPatterns/06_MultiChoice/MultiChoice.pione +20 -28
  156. data/example/WorkflowPatterns/06_MultiChoice/MultiChoice.pnml +797 -0
  157. data/example/WorkflowPatterns/06_MultiChoice/Package.pione +5 -0
  158. data/example/WorkflowPatterns/06_MultiChoice/pione-package.json +19 -0
  159. data/example/WorkflowPatterns/07_StructuredSynchronizingMerge/Package.pione +5 -0
  160. data/example/WorkflowPatterns/07_StructuredSynchronizingMerge/StructuredSynchronizingMerge.pnml +668 -0
  161. data/example/WorkflowPatterns/08_MultiMerge/MultiMerge.pione +9 -20
  162. data/example/WorkflowPatterns/08_MultiMerge/MultiMerge.pnml +551 -0
  163. data/example/WorkflowPatterns/08_MultiMerge/Package.pione +4 -0
  164. data/example/WorkflowPatterns/08_MultiMerge/pione-package.json +19 -0
  165. data/example/WorkflowPatterns/11_ImplicitTermination/ImplicitTermination.pione +9 -17
  166. data/example/WorkflowPatterns/11_ImplicitTermination/ImplicitTermination.pnml +188 -0
  167. data/example/WorkflowPatterns/11_ImplicitTermination/Package.pione +2 -0
  168. data/example/WorkflowPatterns/11_ImplicitTermination/pione-package.json +19 -0
  169. data/example/WorkflowPatterns/12_MultipleInstancesWithoutSynchronization/MultipleInstancesWithoutSynchronization.pione +11 -11
  170. data/example/WorkflowPatterns/12_MultipleInstancesWithoutSynchronization/MultipleInstancesWithoutSynchronization.pnml +319 -0
  171. data/example/WorkflowPatterns/12_MultipleInstancesWithoutSynchronization/Package.pione +4 -0
  172. data/example/WorkflowPatterns/12_MultipleInstancesWithoutSynchronization/pione-package.json +19 -0
  173. data/example/WorkflowPatterns/13_MultipleInstancesWithDesignTimeKnowledge/MultipleInstancesWithDesignTimeKnowledge.pione +11 -11
  174. data/example/WorkflowPatterns/13_MultipleInstancesWithDesignTimeKnowledge/MultipleInstancesWithDesignTimeKnowledge.pnml +319 -0
  175. data/example/WorkflowPatterns/13_MultipleInstancesWithDesignTimeKnowledge/Package.pione +2 -0
  176. data/example/WorkflowPatterns/13_MultipleInstancesWithDesignTimeKnowledge/pione-package.json +19 -0
  177. data/example/WorkflowPatterns/14_MultipleInstancesWithRunTimeKnowledge/MultipleInstancesWithRunTimeKnowledge.pione +14 -17
  178. data/example/WorkflowPatterns/14_MultipleInstancesWithRunTimeKnowledge/MultipleInstancesWithRunTimeKnowledge.pnml +355 -0
  179. data/example/WorkflowPatterns/14_MultipleInstancesWithRunTimeKnowledge/Package.pione +4 -0
  180. data/example/WorkflowPatterns/14_MultipleInstancesWithRunTimeKnowledge/pione-package.json +19 -0
  181. data/example/WorkflowPatterns/33_GeneralizedANDJoin/GeneralizedANDJoin.pione +9 -10
  182. data/example/WorkflowPatterns/33_GeneralizedANDJoin/GeneralizedANDJoin.pnml +409 -0
  183. data/example/WorkflowPatterns/33_GeneralizedANDJoin/Package.pione +2 -0
  184. data/example/WorkflowPatterns/33_GeneralizedANDJoin/pione-package.json +19 -0
  185. data/example/WorkflowPatterns/37_LocalSynchronizingMerge/A.pione +34 -0
  186. data/example/WorkflowPatterns/37_LocalSynchronizingMerge/A.pnml +570 -0
  187. data/example/WorkflowPatterns/37_LocalSynchronizingMerge/LocalSynchronizingMerge.pione +36 -70
  188. data/example/WorkflowPatterns/37_LocalSynchronizingMerge/LocalSynchronizingMerge.pnml +854 -0
  189. data/example/WorkflowPatterns/37_LocalSynchronizingMerge/Package.pione +5 -0
  190. data/example/WorkflowPatterns/37_LocalSynchronizingMerge/pione-package.json +20 -0
  191. data/example/WorkflowPatterns/38_GeneralSynchronizingMerge/GeneralSynchronizingMerge.pnml +1003 -0
  192. data/example/WorkflowPatterns/38_GeneralSynchronizingMerge/Package.pione +6 -0
  193. data/example/WorkflowPatterns/41_ThreadMerge/A.pnml +429 -0
  194. data/example/WorkflowPatterns/41_ThreadMerge/A1.pnml +141 -0
  195. data/example/WorkflowPatterns/41_ThreadMerge/Package.pione +2 -0
  196. data/example/WorkflowPatterns/41_ThreadMerge/ThreadMerge.pnml +205 -0
  197. data/example/WorkflowPatterns/42_ThreadSplit/Package.pione +2 -0
  198. data/example/WorkflowPatterns/42_ThreadSplit/ThreadSplit.pnml +217 -0
  199. data/lib/pione/agent/job-manager.rb +4 -3
  200. data/lib/pione/agent/task-worker.rb +2 -7
  201. data/lib/pione/command.rb +1 -0
  202. data/lib/pione/command/basic-command.rb +3 -1
  203. data/lib/pione/command/command-exception.rb +14 -0
  204. data/lib/pione/command/pione-action-exec.rb +4 -1
  205. data/lib/pione/command/pione-clean.rb +13 -6
  206. data/lib/pione/command/pione-client.rb +5 -5
  207. data/lib/pione/command/pione-compile.rb +1 -1
  208. data/lib/pione/command/pione-log-format.rb +1 -1
  209. data/lib/pione/command/pione-package-add.rb +1 -1
  210. data/lib/pione/command/pione-package-build.rb +87 -32
  211. data/lib/pione/command/pione-package-remove.rb +117 -0
  212. data/lib/pione/command/pione-package.rb +1 -0
  213. data/lib/pione/command/spawner.rb +12 -3
  214. data/lib/pione/lang/boolean.rb +1 -1
  215. data/lib/pione/lang/common-parser.rb +5 -3
  216. data/lib/pione/lang/context-parser.rb +8 -2
  217. data/lib/pione/lang/context-transformer.rb +13 -3
  218. data/lib/pione/lang/context.rb +20 -2
  219. data/lib/pione/lang/data-expr.rb +1 -1
  220. data/lib/pione/lang/declaration-parser.rb +18 -4
  221. data/lib/pione/lang/declaration-transformer.rb +1 -1
  222. data/lib/pione/lang/declaration.rb +5 -3
  223. data/lib/pione/lang/definition.rb +1 -0
  224. data/lib/pione/lang/environment.rb +37 -2
  225. data/lib/pione/lang/expr.rb +10 -12
  226. data/lib/pione/lang/feature-expr.rb +1 -1
  227. data/lib/pione/lang/float.rb +1 -1
  228. data/lib/pione/lang/integer.rb +1 -1
  229. data/lib/pione/lang/keyed-sequence.rb +5 -5
  230. data/lib/pione/lang/lang-exception.rb +9 -5
  231. data/lib/pione/lang/literal-parser.rb +2 -2
  232. data/lib/pione/lang/literal-transformer.rb +3 -0
  233. data/lib/pione/lang/message.rb +3 -3
  234. data/lib/pione/lang/ordinal-sequence.rb +1 -1
  235. data/lib/pione/lang/package-expr.rb +1 -1
  236. data/lib/pione/lang/parameters.rb +1 -1
  237. data/lib/pione/lang/pione-method.rb +16 -16
  238. data/lib/pione/lang/rule-expr.rb +6 -1
  239. data/lib/pione/lang/sequence.rb +8 -3
  240. data/lib/pione/lang/string.rb +1 -1
  241. data/lib/pione/lang/ticket-expr.rb +1 -1
  242. data/lib/pione/lang/type.rb +17 -8
  243. data/lib/pione/lang/variable.rb +4 -1
  244. data/lib/pione/literate-action.rb +1 -2
  245. data/lib/pione/literate-action/document.rb +1 -1
  246. data/lib/pione/literate-action/handler.rb +22 -7
  247. data/lib/pione/literate-action/{parser.rb → markdown-parser.rb} +2 -1
  248. data/lib/pione/log/domain-log.rb +1 -1
  249. data/lib/pione/model/task-worker-broker-model.rb +1 -1
  250. data/lib/pione/package/package-database.rb +16 -2
  251. data/lib/pione/package/package-exception.rb +1 -1
  252. data/lib/pione/package/package-handler.rb +11 -7
  253. data/lib/pione/package/package-info.rb +13 -7
  254. data/lib/pione/package/package-scanner.rb +1 -1
  255. data/lib/pione/package/scenario-info.rb +2 -2
  256. data/lib/pione/pnml.rb +6 -0
  257. data/lib/pione/pnml/compiler.rb +329 -95
  258. data/lib/pione/pnml/declaration-extractor.rb +90 -0
  259. data/lib/pione/pnml/input-merge-complement.rb +17 -11
  260. data/lib/pione/pnml/input-parallelization-complement.rb +10 -6
  261. data/lib/pione/pnml/input-reduction.rb +5 -5
  262. data/lib/pione/pnml/invalid-arc-elimination.rb +2 -2
  263. data/lib/pione/pnml/io-expansion.rb +9 -5
  264. data/lib/pione/pnml/isolated-element-elimination.rb +2 -2
  265. data/lib/pione/pnml/label-extractor.rb +258 -0
  266. data/lib/pione/pnml/net-rewriter.rb +6 -4
  267. data/lib/pione/pnml/output-decomposition-complement.rb +12 -7
  268. data/lib/pione/pnml/output-reduction.rb +11 -5
  269. data/lib/pione/pnml/output-synchronization-complement.rb +11 -7
  270. data/lib/pione/pnml/parser.rb +106 -0
  271. data/lib/pione/pnml/pione-model.rb +685 -230
  272. data/lib/pione/pnml/pnml-model.rb +73 -41
  273. data/lib/pione/pnml/ticket-instantiation.rb +42 -0
  274. data/lib/pione/rule-engine/action-handler.rb +212 -135
  275. data/lib/pione/rule-engine/basic-handler.rb +29 -3
  276. data/lib/pione/rule-engine/engine-exception.rb +10 -6
  277. data/lib/pione/system/status.rb +12 -6
  278. data/lib/pione/version.rb +1 -1
  279. data/lib/rootage/help.md.erb +45 -0
  280. data/lib/rootage/help.rb +1 -0
  281. data/lib/rootage/scenario.rb +20 -2
  282. data/misc/pione-completion.bash +15 -5
  283. data/misc/pione-completion.zsh +16 -6
  284. data/test/command/spec_pione-client.rb +60 -60
  285. data/test/lang/data/context-parser.yml +12 -1
  286. data/test/lang/spec_pione-method.rb +7 -6
  287. data/test/literate-action/spec_handler.rb +19 -13
  288. data/test/literate-action/{spec_parser.rb → spec_markdown-parser.rb} +3 -3
  289. data/test/log/spec_message-log-receiver.rb +1 -1
  290. data/test/package/spec_package-info.rb +1 -1
  291. data/test/pnml/spec_input-merge-complement.rb +4 -2
  292. data/test/pnml/spec_input-parallelization-complement.rb +4 -2
  293. data/test/pnml/spec_input-reduction.rb +8 -4
  294. data/test/pnml/spec_invalid-arc-elimination.rb +2 -1
  295. data/test/pnml/spec_io-expansion.rb +4 -2
  296. data/test/pnml/spec_isolated-element-elimination.rb +2 -1
  297. data/test/pnml/spec_label-extractor.rb +100 -0
  298. data/test/pnml/spec_output-decomposition-complement.rb +4 -2
  299. data/test/pnml/spec_output-reduction.rb +8 -4
  300. data/test/pnml/spec_output-synchronization-complement.rb +4 -2
  301. data/test/pnml/spec_pione-element.rb +116 -37
  302. data/test/pnml/spec_pnml-element.rb +32 -8
  303. data/test/rule-engine/spec_action-handler.rb +12 -20
  304. metadata +159 -16
  305. data/example/CTFCorrection/package.yml +0 -1
  306. data/example/DeferredChoice/bin/ui.xml +0 -28
@@ -0,0 +1,90 @@
1
+ module Pione
2
+ module PNML
3
+ # DeclarationExtractor extracts declarations from net.
4
+ class DeclarationExtractor
5
+ def initialize(env, net, option={})
6
+ @env = env
7
+ @net = net
8
+ @declarations = ExtractedDeclarations.new
9
+ end
10
+
11
+ def extract
12
+ extract_params
13
+ extract_variable_bindings
14
+ extract_features
15
+
16
+ return @declarations
17
+ end
18
+
19
+ private
20
+
21
+ # Extract net parameters.
22
+ def extract_params
23
+ @net.transitions.each_with_object([]) do |transition, sentences|
24
+ if Perspective.param_transition?(@env, transition)
25
+ # evaluate the sentence for updating language environment
26
+ Perspective.eval_param_sentence(@env, transition)
27
+ @declarations.add_param(transition.name)
28
+ end
29
+ end
30
+ end
31
+
32
+ # Extract net variable bindings.
33
+ def extract_variable_bindings
34
+ @net.transitions.each do |transition|
35
+ if Perspective.variable_binding_transition?(@env, transition)
36
+ @declarations.add_variable_binding(transition.name)
37
+ end
38
+ end
39
+ end
40
+
41
+ # Extract net features.
42
+ def extract_features
43
+ @net.transitions.each_with_object([]) do |transition, sentences|
44
+ if Perspective.feature_transition?(@env, transition)
45
+ @declarations.add_feature(transition.name)
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ # ExtractedDeclarations is a store of declarations.
52
+ class ExtractedDeclarations
53
+ attr_reader :params
54
+ attr_reader :variable_bindings
55
+ attr_reader :features
56
+
57
+ def initialize
58
+ @params = []
59
+ @variable_bindings = []
60
+ @features = []
61
+ end
62
+
63
+ # Add the parameter.
64
+ #
65
+ # @param param [String]
66
+ # a string of parameter
67
+ def add_param(param)
68
+ @params << Perspective.normalize_declaration(param)
69
+ end
70
+
71
+ # Add the variable binding.
72
+ #
73
+ # @param variable_binding [String]
74
+ # a string of variable binding
75
+ def add_variable_binding(variable_binding)
76
+ @variable_bindings <<
77
+ Perspective.normalize_declaration(variable_binding)
78
+ end
79
+
80
+ # Add the feature.
81
+ #
82
+ # @param variable_binding [String]
83
+ # a string of feature
84
+ def add_feature(feature)
85
+ @features <<
86
+ Perspective.normalize_declaration(feature)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -16,7 +16,6 @@ module Pione
16
16
  # 'p2' --> empty transition --+--> 'p1' or 'p2' or 'p3' -> A
17
17
  # |
18
18
  # 'p3' --> empty transition --+
19
- #
20
19
  module InputMergeComplement
21
20
  # Find subjects(source transitions and target palce) of this rule from the
22
21
  # net. The conditions are followings:
@@ -28,19 +27,21 @@ module Pione
28
27
  #
29
28
  # @param net [PNML::Net]
30
29
  # rewriting target net
30
+ # @param env [Lang::Environment]
31
+ # language environment
31
32
  # @return [Array]
32
33
  # source transitions and target place
33
- def self.find_subjects(net)
34
+ def self.find_subjects(net, env)
34
35
  net.places.each do |place|
35
- # target place should have no names
36
- next unless place.empty_name?
36
+ # target place should be empty
37
+ next unless Perspective.empty_place?(env, place)
37
38
 
38
39
  # collect transitions
39
40
  transitions = net.find_all_transitions_by_target_id(place.id).select do |transition|
40
41
  arcs = net.find_all_arcs_by_target_id(transition.id)
41
42
  if arcs.size == 1
42
43
  _place = net.find_place(arcs.first.source_id)
43
- transition.empty_name? and Perspective.file?(_place)
44
+ Perspective.empty_transition?(env, transition) and Perspective.data_place?(env, _place)
44
45
  end
45
46
  end
46
47
 
@@ -59,19 +60,24 @@ module Pione
59
60
  # rewriting target net
60
61
  # @param subjects [Array]
61
62
  # source transitions and target place
63
+ # @param env [Lang::Environment]
64
+ # language environment
62
65
  # @return [void]
63
- def self.rewrite(net, subjects)
66
+ def self.rewrite(net, subjects, env)
64
67
  transitions, place = subjects
65
68
 
69
+ source_places = transitions.map do |transition|
70
+ net.find_all_places_by_target_id(transition.id)
71
+ end.flatten
72
+
66
73
  # build a new name
67
- new_name = transitions.map do |transition|
68
- arcs = net.find_all_arcs_by_target_id(transition.id)
69
- _place = net.find_place(arcs.first.source_id)
70
- Perspective.normalize_data_name(_place.name)
74
+ new_name = source_places.map do |source_place|
75
+ LabelExtractor.extract_data_expr(source_place.name)
71
76
  end.sort.join(" or ")
72
77
 
73
78
  # update the place name
74
- place.name = "%s%s" % [Perspective.modifier(place.name), new_name]
79
+ modifier = Perspective.data_modifier(env, place) || ""
80
+ place.name = modifier + new_name
75
81
  end
76
82
  end
77
83
  end
@@ -29,22 +29,24 @@ module Pione
29
29
  #
30
30
  # @param net [PNML::Net]
31
31
  # rewriting target net
32
+ # @param env [Lang::Environment]
33
+ # language environment
32
34
  # @return [Array]
33
35
  # input place and target places
34
- def self.find_subjects(net)
36
+ def self.find_subjects(net, env)
35
37
  net.transitions.each do |transition|
36
38
  # source transition should have no names
37
- next unless transition.empty_name?
39
+ next unless Perspective.empty_transition?(env, transition)
38
40
 
39
41
  # transition should have only one named input
40
42
  input_places = net.find_all_places_by_target_id(transition.id)
41
- unless input_places.size == 1 and Perspective.file?(input_places.first)
43
+ unless input_places.size == 1 and Perspective.data_place?(env, input_places.first)
42
44
  next
43
45
  end
44
46
 
45
47
  # collect places
46
48
  output_places = net.find_all_places_by_source_id(transition.id)
47
- next unless output_places.all? {|output_place| output_place.empty_name?}
49
+ next unless output_places.all? {|output_place| Perspective.empty_place?(env, output_place)}
48
50
 
49
51
  # there should be more than 2 places
50
52
  next unless output_places.size > 1
@@ -61,13 +63,15 @@ module Pione
61
63
  # rewriting target net
62
64
  # @param subjects [Array]
63
65
  # input place and target places
66
+ # @param env [Lang::Environment]
67
+ # language environment
64
68
  # @return [void]
65
- def self.rewrite(net, subjects)
69
+ def self.rewrite(net, subjects, env)
66
70
  input_place, target_places = subjects
67
71
 
68
72
  # rewrite names of target places
69
73
  target_places.each do |place|
70
- place.name = Perspective.normalize_data_name(input_place.name)
74
+ place.name = LabelExtractor.extract_data_expr(input_place.name)
71
75
  end
72
76
  end
73
77
  end
@@ -17,15 +17,15 @@ module Pione
17
17
  # - There is an empty source transition.
18
18
  # - There is an empty target place. It is an input of named transition.
19
19
  # - There is an arc that connects the source and the target.
20
- def self.find_subjects(net)
20
+ def self.find_subjects(net, env)
21
21
  net.transitions.each do |rule|
22
22
  # rule has its name
23
- next unless Perspective.named?(rule)
23
+ next if Perspective.empty?(env, rule)
24
24
 
25
25
  # find source places
26
26
  net.find_all_places_by_target_id(rule.id).each do |place|
27
27
  # the source place has empty name
28
- next unless Perspective.empty?(place)
28
+ next unless Perspective.empty?(env, place)
29
29
 
30
30
  # find transtions that generates the source place
31
31
  transitions = net.find_all_transitions_by_target_id(place.id)
@@ -37,7 +37,7 @@ module Pione
37
37
  # the transition is connected to only one place at target side
38
38
  if net.find_all_places_by_source_id(transition.id).size == 1
39
39
  # the transition has empty name
40
- if Perspective.empty?(transition)
40
+ if Perspective.empty?(env, transition)
41
41
  return [transition, place, net.find_arc(transition.id, place.id)]
42
42
  end
43
43
  end
@@ -54,7 +54,7 @@ module Pione
54
54
  # - Remove the subject transition.
55
55
  # - Remove the subject and related arcs.
56
56
  # - Connect discontinuous nodes by new arcs.
57
- def self.rewrite(net, subjects)
57
+ def self.rewrite(net, subjects, env)
58
58
  transition, place, arc = subjects
59
59
 
60
60
  # remove subjects from the net
@@ -8,7 +8,7 @@ module Pione
8
8
  # - There is a arc.
9
9
  # - It should connect source place and target transition, or source
10
10
  # transition and target place.
11
- def self.find_subjects(net)
11
+ def self.find_subjects(net, env)
12
12
  net.arcs.each do |arc|
13
13
  source_transition = net.find_transition(arc.source_id)
14
14
  source_place = net.find_place(arc.source_id)
@@ -30,7 +30,7 @@ module Pione
30
30
  end
31
31
 
32
32
  # Rewrite the net by eliminating isolated node.
33
- def self.rewrite(net, subjects)
33
+ def self.rewrite(net, subjects, env)
34
34
  arc = subjects.first
35
35
 
36
36
  # eliminate
@@ -20,22 +20,24 @@ module Pione
20
20
  #
21
21
  # @param net [PNML::Net]
22
22
  # rewriting target net
23
+ # @param env [Lang::Environment]
24
+ # language environment
23
25
  # @return [Array]
24
26
  # sandwiched place and target side arcs
25
- def self.find_subjects(net)
27
+ def self.find_subjects(net, env)
26
28
  net.transitions.each do |transition|
27
29
  # transition should be a rule
28
- next unless Perspective.rule?(transition)
30
+ next unless Perspective.rule_transition?(env, transition)
29
31
 
30
32
  net.find_all_places_by_source_id(transition.id).each do |place|
31
33
  # place should be a file
32
- next unless Perspective.file?(place)
34
+ next unless Perspective.data_place?(env, place)
33
35
 
34
36
  # collect target side arcs
35
37
  all_target_arcs = net.find_all_arcs_by_source_id(place.id)
36
38
  target_arcs = all_target_arcs.select do |arc|
37
39
  transition = net.find_transition(arc.target_id)
38
- transition and Perspective.rule?(transition)
40
+ transition and Perspective.rule_transition?(env, transition)
39
41
  end
40
42
  next unless target_arcs.size > 0
41
43
 
@@ -57,8 +59,10 @@ module Pione
57
59
  # rewriting target net
58
60
  # @param subjects [Array]
59
61
  # sandwiched place and target side arcs
62
+ # @param env [Lang::Environment]
63
+ # language environment
60
64
  # @return [void]
61
- def self.rewrite(net, subjects)
65
+ def self.rewrite(net, subjects, env)
62
66
  place, target_arcs = subjects
63
67
 
64
68
  # remove arcs
@@ -7,7 +7,7 @@ module Pione
7
7
  #
8
8
  # - There is a place or transition.
9
9
  # - It has no arcs.
10
- def self.find_subjects(net)
10
+ def self.find_subjects(net, env)
11
11
  (net.places + net.transitions).each do |node|
12
12
  input_arcs = net.find_all_arcs_by_source_id(node.id)
13
13
  output_arcs = net.find_all_arcs_by_target_id(node.id)
@@ -20,7 +20,7 @@ module Pione
20
20
  end
21
21
 
22
22
  # Rewrite the net by eliminating isolated node.
23
- def self.rewrite(net, subjects)
23
+ def self.rewrite(net, subjects, env)
24
24
  subjects.each do |node|
25
25
  # eliminate the node
26
26
  net.transitions.delete(node)
@@ -0,0 +1,258 @@
1
+ module Pione
2
+ module PNML
3
+ # LabelExtractor extracts PIONE string from node label.
4
+ module LabelExtractor
5
+ class << self
6
+ # Extract a rule expression.
7
+ #
8
+ # @param label [String]
9
+ # node label
10
+ # @return [String]
11
+ # rule expression without modifier and comment
12
+ def extract_rule_expr(label)
13
+ extract_string(label, :rule_transition, :expr)
14
+ end
15
+
16
+ # Extract a data expression.
17
+ #
18
+ # @param label [String]
19
+ # node label
20
+ # @return [String]
21
+ # data expression without modifier and comment
22
+ def extract_data_expr(label)
23
+ extract_string(label, :data_place, :expr)
24
+ end
25
+
26
+ # Extract a param set.
27
+ #
28
+ # @param name [String]
29
+ # node label
30
+ # @return [String]
31
+ # parameter set string without modifier and comment
32
+ def extract_param_set(label)
33
+ extract_string(label, :expr_place, :expr)
34
+ end
35
+
36
+ # Extract a ticket.
37
+ #
38
+ # @param label [String]
39
+ # node label
40
+ # @return [String]
41
+ # ticket string without modifier and comment
42
+ def extract_ticket(label)
43
+ extract_string(label, :expr_place, :expr)
44
+ end
45
+
46
+ # Extract a feature.
47
+ #
48
+ # @param label [String]
49
+ # node label
50
+ # @return [String]
51
+ # feature string without modifier and comment
52
+ def extract_feature(label)
53
+ extract_string(label, :expr_place, :expr)
54
+ end
55
+
56
+ # Extract a param sentence.
57
+ #
58
+ # @param label [String]
59
+ # node label
60
+ # @return [String]
61
+ # data expression without modifier and comment
62
+ def extract_param_sentence(label)
63
+ extract_string(label, :param_sentence, :param_sentence)
64
+ end
65
+
66
+ # Extract a feature sentence.
67
+ #
68
+ # @param label [String]
69
+ # node label
70
+ # @return [String]
71
+ # feature sentence string without modifier and comment
72
+ def extract_feature_sentence(label)
73
+ extract_string(label, :feature_sentence, :feature_sentence)
74
+ end
75
+
76
+ # Extract a variable binding sentence.
77
+ #
78
+ # @param label [String]
79
+ # node label
80
+ # @return [String]
81
+ # variable binding sentence string without modifier and comment
82
+ def extract_variable_binding(label)
83
+ extract_string(label, :variable_binding_sentence, :variable_binding_sentence)
84
+ end
85
+
86
+ # Extract priority.
87
+ #
88
+ # @param label [String]
89
+ # node label
90
+ # @return [Integer]
91
+ # priority
92
+ def extract_priority(label)
93
+ matched = Parser.new.data_priority.parse(label)
94
+ return matched[:priority].to_i
95
+ rescue Parslet::ParseFailed
96
+ return nil
97
+ end
98
+
99
+ # Extract key and value pairs from parameter set string.
100
+ #
101
+ # @param label [String]
102
+ # node label
103
+ # @return [Hash]
104
+ # key and value pairs
105
+ def extract_data_from_param_set(label)
106
+ param_set = LabelExtractor.extract_param_set(label)
107
+
108
+ parsed = Parser.new.expr_place.parse(param_set)
109
+ tail_offset = parsed[:tail] ? parsed[:tail].offset : label.size
110
+
111
+ keys = []
112
+ values = []
113
+
114
+ found = find_all_by_tree_names(parsed, [:key, :value, :separator, :footer])
115
+ found.each_with_index do |item, index|
116
+ if index % 3 == 0
117
+ keys << item.to_s
118
+ end
119
+
120
+ if index % 3 == 1
121
+ offset = find_head_character_position(item)
122
+ separator_offset = found[index + 1] ? found[index + 1].offset : tail_offset
123
+ values << label[offset, separator_offset - offset]
124
+ end
125
+ end
126
+
127
+ return Hash[keys.zip(values)]
128
+ end
129
+
130
+ # Extract key and value pairs from parameter set string.
131
+ #
132
+ # @param label [String]
133
+ # node label
134
+ # @return [Hash]
135
+ # key and value pairs
136
+ def extract_data_from_param_sentence(label)
137
+ param_sentence = LabelExtractor.extract_param_sentence(label)
138
+ parsed = Parser.new.param_sentence.parse(param_sentence)
139
+
140
+ # variable
141
+ var = parsed[:param_sentence][:expr1][:expr][:variable][:name].to_s
142
+
143
+ # value
144
+ expr2 = parsed[:param_sentence][:expr2]
145
+ expr2_offset = find_head_character_position(expr2)
146
+ tail_offset = offset_of(parsed[:tail]) || label.size
147
+ value = label[expr2_offset, tail_offset - expr2_offset]
148
+
149
+ return {var => value}
150
+ end
151
+
152
+ private
153
+
154
+ # Extract the string of expression.
155
+ #
156
+ # @param label [String]
157
+ # node label
158
+ # @param paser_name [Symbol]
159
+ # parser name
160
+ # @param tree_name [Symbol]
161
+ # tree name
162
+ # @return [String]
163
+ # expression without modifier and comment
164
+ def extract_string(label, parser_name, tree_name)
165
+ return nil if label.nil?
166
+
167
+ parsed = Parser.new.send(parser_name).parse(label)
168
+ offset = find_head_character_position(parsed[tree_name])
169
+ tail_offset = offset_of(find_parsed_element(parsed, :tail)) || label.size
170
+ return label[offset, tail_offset - offset]
171
+ end
172
+
173
+ # Find position of head character of parsed tree.
174
+ #
175
+ # @param parsed [Hash]
176
+ # parsed tree
177
+ # @return [Integer]
178
+ # position of head character or nil
179
+ def find_head_character_position(parsed)
180
+ return nil if parsed.nil?
181
+
182
+ pos = nil
183
+ parsed.values.each do |value|
184
+ if value.kind_of?(Hash)
185
+ if _pos = find_head_character_position(value)
186
+ if pos.nil? or pos > _pos
187
+ pos = _pos
188
+ end
189
+ end
190
+ else
191
+ if value.kind_of?(Parslet::Slice) and (pos.nil? or pos > value.offset)
192
+ pos = value.offset
193
+ end
194
+ end
195
+ end
196
+ return pos
197
+ end
198
+
199
+ def offset_of(value)
200
+ if value.kind_of?(Parslet::Slice)
201
+ value.offset
202
+ end
203
+ end
204
+
205
+ # Find a parsed element by the name.
206
+ #
207
+ # @param parsed [Hash]
208
+ # parsed tree
209
+ # @param name [Symbol]
210
+ # element name
211
+ # @return [Object]
212
+ # parsed element
213
+ def find_parsed_element(parsed, name)
214
+ return nil if parsed.nil?
215
+
216
+ parsed.each do |key, value|
217
+ if key == name
218
+ return value
219
+ else
220
+ if value.kind_of?(Hash)
221
+ if elt = find_parsed_element(value, name)
222
+ return elt
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ return nil
229
+ end
230
+
231
+ def find_all_by_tree_names(parsed, names)
232
+ list = []
233
+ return list if parsed.nil?
234
+
235
+ parsed.each do |key, value|
236
+ if names.include?(key)
237
+ list << value
238
+ else
239
+ if value.kind_of?(Hash)
240
+ list += find_all_by_tree_names(value, names)
241
+ end
242
+
243
+ if value.kind_of?(Array)
244
+ value.each do |elt|
245
+ if elt.kind_of?(Hash)
246
+ list += find_all_by_tree_names(elt, names)
247
+ end
248
+ end
249
+ end
250
+ end
251
+ end
252
+
253
+ return list
254
+ end
255
+ end
256
+ end
257
+ end
258
+ end