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
@@ -22,11 +22,13 @@ module Pione
22
22
  #
23
23
  # @param net [PNML::Net]
24
24
  # a net that is a target of this transformation
25
+ # @param env [Lang::Environment]
26
+ # language environment
25
27
  # @return [void]
26
- def rewrite(net)
28
+ def rewrite(net, env)
27
29
  # find rewriting subjects
28
30
  rule, subjects = @rules.inject(nil) do |res, _rule|
29
- if res.nil? and _subjects = _rule.find_subjects(net)
31
+ if res.nil? and _subjects = _rule.find_subjects(net, env)
30
32
  [_rule, _subjects]
31
33
  else
32
34
  res
@@ -35,8 +37,8 @@ module Pione
35
37
 
36
38
  # rewrite the net with subjects and go next
37
39
  if subjects
38
- rule.rewrite(net, subjects)
39
- rewrite(net)
40
+ rule.rewrite(net, subjects, env)
41
+ rewrite(net, env)
40
42
  end
41
43
  end
42
44
  end
@@ -29,24 +29,26 @@ 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
  # source place and component places
34
- def self.find_subjects(net)
36
+ def self.find_subjects(net, env)
35
37
  net.places.each do |place|
36
38
  # source place should be empty
37
- next unless place.empty_name?
39
+ next unless Perspective.empty_place?(env, place)
38
40
 
39
41
  # there should be more than 2 target transitions
40
42
  transitions = net.find_all_transitions_by_source_id(place.id)
41
43
  next unless transitions.size > 1
42
- next unless transitions.all? {|transition| transition.empty_name?}
44
+ next unless transitions.all? {|transition| Perspective.empty_transition?(env, transition)}
43
45
 
44
46
  # each transition has only one output named place
45
47
  component_places = []
46
48
  next unless transitions.all? do |transition|
47
49
  _places = net.find_all_places_by_source_id(transition.id)
48
50
  component_places.concat(_places)
49
- _places.size == 1 and not(_places.first.empty_name?)
51
+ _places.size == 1 and not(Perspective.empty_place?(env, _places.first))
50
52
  end
51
53
 
52
54
  return [place, component_places]
@@ -61,16 +63,19 @@ module Pione
61
63
  # rewriting target net
62
64
  # @param subjects [Array]
63
65
  # source place and component 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
  place, component_places = subjects
67
71
 
68
72
  # component places' names
69
73
  names = component_places.map do |component_place|
70
- Perspective.normalize_data_name(component_place.name)
74
+ LabelExtractor.extract_data_expr(component_place.name)
71
75
  end
72
76
 
73
- place.name = "%s%s" % [Perspective.modifier(place.name), names.sort.join(" or ")]
77
+ modifier = Perspective.data_modifier(env, place) || ""
78
+ place.name = modifier + names.sort.join(" or ")
74
79
  end
75
80
  end
76
81
  end
@@ -19,16 +19,18 @@ module Pione
19
19
  #
20
20
  # @param net [PNML::Net]
21
21
  # rewriting target net
22
+ # @param env [Lang::Environment]
23
+ # language environment
22
24
  # @return [Array]
23
25
  # source place, target transition, and the arc
24
- def self.find_subjects(net)
26
+ def self.find_subjects(net, env)
25
27
  net.places.each do |place|
26
28
  # source place should be empty
27
- next unless Perspective.empty?(place)
29
+ next unless Perspective.empty_place?(env, place)
28
30
 
29
31
  # source place should be an output of named transition
30
32
  next if net.find_all_transitions_by_target_id(place.id).map do |transition|
31
- Perspective.named?(transition)
33
+ not(Perspective.empty_transition?(env, transition))
32
34
  end.empty?
33
35
 
34
36
  transitions = net.find_all_transitions_by_source_id(place.id)
@@ -40,7 +42,7 @@ module Pione
40
42
  # the transtion is connected to only one place at source side
41
43
  if net.find_all_places_by_target_id(transition.id).size == 1
42
44
  # target transition should be empty
43
- next unless Perspective.empty?(transition)
45
+ next unless Perspective.empty?(env, transition)
44
46
 
45
47
  return [place, transition, net.find_arc(place.id, transition.id)]
46
48
  end
@@ -59,8 +61,12 @@ module Pione
59
61
  #
60
62
  # @param net [PNML::Net]
61
63
  # rewriting target net
64
+ # @param subjects [Array]
65
+ # source transitions and target place
66
+ # @param env [Lang::Environment]
67
+ # language environment
62
68
  # @return [void]
63
- def self.rewrite(net, subjects)
69
+ def self.rewrite(net, subjects, env)
64
70
  place, transition, arc = subjects
65
71
 
66
72
  # remove subjects from the net
@@ -29,23 +29,25 @@ 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
  # source places and synchronized place
34
- def self.find_subjects(net)
36
+ def self.find_subjects(net, env)
35
37
  net.transitions.each do |transition|
36
38
  # target transition should be empty
37
- next unless transition.empty_name?
39
+ next unless Perspective.empty_transition?(env, transition)
38
40
 
39
41
  # the transition should have only one output place
40
42
  synchronized_places = net.find_all_places_by_source_id(transition.id).select do |place|
41
- Perspective.file?(place)
43
+ Perspective.data_place?(env, place)
42
44
  end
43
45
  next unless synchronized_places.size == 1
44
46
 
45
47
  # collect source places
46
48
  source_places = net.find_all_places_by_target_id(transition.id)
47
49
  next unless source_places.size > 1
48
- next unless source_places.any? {|place| place.empty_name?}
50
+ next unless source_places.any? {|place| Perspective.empty_place?(env, place)}
49
51
 
50
52
  # return subjects
51
53
  return [source_places, synchronized_places.first]
@@ -60,15 +62,17 @@ module Pione
60
62
  # rewriting target net
61
63
  # @param subjects [Array]
62
64
  # source places and synchronized place
65
+ # @param env [Lang::Environment]
66
+ # language environment
63
67
  # @return [void]
64
- def self.rewrite(net, subjects)
68
+ def self.rewrite(net, subjects, env)
65
69
  source_places, synchronized_place = subjects
66
70
 
67
71
  # rewrite names of empty source places
68
72
  source_places.each do |place|
69
73
  # rewrite name only if it is empty
70
- if place.empty_name?
71
- place.name = synchronized_place.name
74
+ if Perspective.empty_place?(env, place)
75
+ place.name = LabelExtractor.extract_data_expr(synchronized_place.name)
72
76
  end
73
77
  end
74
78
  end
@@ -0,0 +1,106 @@
1
+ module Pione
2
+ module PNML
3
+ class Parser < Parslet::Parser
4
+ include Util::ParsletParserExtension
5
+ include Lang::CommonParser
6
+ include Lang::LiteralParser
7
+ include Lang::ExprParser
8
+ include Lang::ContextParser
9
+ include Lang::ConditionalBranchParser
10
+ include Lang::DeclarationParser
11
+
12
+ #
13
+ # symbols and keywords
14
+ #
15
+
16
+ rule(:symbol_net_input_data) { str("<") }
17
+ rule(:symbol_net_output_data) { str(">") }
18
+
19
+ rule(:keyword_then) { str("then") }
20
+ rule(:keyword_extern) { str("extern") }
21
+
22
+ rule(:transition_keyword) {
23
+ keyword_if |
24
+ keyword_else |
25
+ keyword_then |
26
+ keyword_case |
27
+ keyword_when |
28
+ keyword_constraint |
29
+ keyword_extern
30
+ }
31
+
32
+ #
33
+ # transtion syntax
34
+ #
35
+
36
+ rule(:empty_transition) { space?.as(:tail) }
37
+
38
+ rule(:keyword_transition) {
39
+ space? >> transition_keyword >> space?.as(:tail)
40
+ }
41
+
42
+ rule(:if_transition) {space? >> keyword_if >> space?.as(:tail)}
43
+ rule(:else_transition) {space? >> keyword_else >> space?.as(:tail)}
44
+ rule(:then_transition) {space? >> keyword_then >> space?.as(:tail)}
45
+ rule(:case_transition) {space? >> keyword_case >> space?.as(:tail)}
46
+ rule(:when_transition) {space? >> keyword_when >> space?.as(:tail)}
47
+ rule(:constraint_transition) {space? >> keyword_constraint >> space?.as(:tail)}
48
+
49
+ rule(:rule_transition) {
50
+ external_rule_transition | internal_rule_transition
51
+ }
52
+
53
+ rule(:external_rule_transition) {
54
+ space? >> keyword_extern.as(:modifier) >> space? >>
55
+ expr.or_error("it should be rule exprssion") >>
56
+ space?.as(:tail)
57
+ }
58
+
59
+ rule(:internal_rule_transition) {
60
+ space? >>
61
+ (keyword_transition >> identifier_tail_character.absent?).absent? >>
62
+ expr >>
63
+ space?.as(:tail)
64
+ }
65
+
66
+ #
67
+ # place syntax
68
+ #
69
+
70
+ rule(:data_modifier) {
71
+ (symbol_net_input_data | symbol_net_output_data).as(:modifier)
72
+ }
73
+
74
+ rule(:empty_place) {
75
+ (space? >> data_modifier >> space?.as(:tail)) | space?.as(:tail)
76
+ }
77
+
78
+ rule(:data_place) {
79
+ (space? >> data_modifier >> expr_place) | expr_place
80
+ }
81
+
82
+ rule(:expr_place) {
83
+ space? >> expr >> space?.as(:tail)
84
+ }
85
+
86
+ #
87
+ # others
88
+ #
89
+
90
+ rule(:net_input_symbol) {
91
+ space? >> symbol_net_input_data >> space?
92
+ }
93
+
94
+ rule(:net_output_symbol) {
95
+ space? >> symbol_net_output_data >> space?
96
+ }
97
+
98
+ rule(:data_priority) {
99
+ space? >>
100
+ expr >>
101
+ space_char.repeat(0) >>
102
+ str("#") >> space? >> digit.repeat(1).as(:priority) >> space?
103
+ }
104
+ end
105
+ end
106
+ end
@@ -2,168 +2,490 @@ module Pione
2
2
  module PNML
3
3
  # `Perspective` is a meta class for PIONE's concepts overlayed in PNML.
4
4
  class Perspective
5
- # Eliminate comments from the string. This implementation is temporary, we
6
- # should fix this.
7
- def self.eliminate_comment(str)
8
- # FIXME
9
- str.sub(/#.*$/, "")
10
- end
5
+ TRANSFORMER_OPT = {package_name: "", editor: "", tag: "", filename: ""}
6
+
7
+ class << self
8
+ # Return true if the node is empty.
9
+ #
10
+ # @param env [Lang::Environment]
11
+ # language environment
12
+ # @param node [PNML::Node]
13
+ # the node
14
+ # @return [Boolean]
15
+ # true if the node is empty
16
+ def empty?(env, node)
17
+ empty_place?(env, node) or empty_transition?(env, node)
18
+ end
11
19
 
12
- # Return true if the node is empty in PIONE model.
13
- #
14
- # @return [Boolean]
15
- # true if the node is empty
16
- def self.empty?(node)
17
- # node should be a place or transition
18
- return false unless node.is_a?(Place) or node.is_a?(Transition)
20
+ # Return true if the node is an empty place.
21
+ #
22
+ # @param env [Lang::Environment]
23
+ # language environment
24
+ # @param node [PNML::Node]
25
+ # the node
26
+ # @return [Boolean]
27
+ # true if the node is an empty place
28
+ def empty_place?(env, node)
29
+ match_place_parser?(env, node, :empty_place)
30
+ end
19
31
 
20
- return true if node.name.nil?
21
- return true if /^[<>]?\s*$/.match(eliminate_comment(node.name.strip))
22
- end
32
+ # Return true if the node is an empty transition.
33
+ #
34
+ # @param env [Lang::Environment]
35
+ # language environment
36
+ # @param node [PNML::Node]
37
+ # the node
38
+ # @return [Boolean]
39
+ # true if the node is an empty transition
40
+ def empty_transition?(env, node)
41
+ match_transition_parser?(env, node, :empty_transition)
42
+ end
23
43
 
24
- # Return true if the node is named in PIONE model.
25
- #
26
- # @return [Boolean]
27
- # true if the node is named
28
- def self.named?(node)
29
- not(empty?(node))
30
- end
44
+ # Return true if the node is an expression place.
45
+ #
46
+ # @param env [Lang::Environment]
47
+ # language environment
48
+ # @param node [PNML::Node]
49
+ # the node
50
+ # @return [Boolean]
51
+ # true if the node is an exression place
52
+ def expr_place?(env, node)
53
+ match_place_parser?(node, :expr_place)
54
+ end
31
55
 
32
- # Return true if the node is a file in PIONE model.
33
- #
34
- # @return [Boolean]
35
- # true if the node is a file
36
- def self.file?(node)
37
- # files should be represented as a place
38
- return false unless node.is_a?(Place)
39
- return false if node.name.nil?
56
+ # Return true if the node is a data place.
57
+ #
58
+ # @param env [Lang::Environment]
59
+ # language environment
60
+ # @param node [PNML::Node]
61
+ # the node
62
+ # @return [Boolean]
63
+ # true if the node is a data place
64
+ def data_place?(env, node)
65
+ match_place_parser_with_type?(env, node, :data_place, :expr, Lang::TypeDataExpr)
66
+ end
40
67
 
41
- # normalize
42
- name = node.name.strip
43
- if name.size > 0 and "<>".include?(name[0])
44
- name = name.sub(/[<>]/, "")
68
+ # Return true if the node is a net input data place.
69
+ #
70
+ # @param env [Lang::Environment]
71
+ # language environment
72
+ # @param node [PNML::Node]
73
+ # the node
74
+ # @return [Boolean]
75
+ # true if the node is a net input data place
76
+ def net_input_data_place?(env, node)
77
+ if data_place?(env, node)
78
+ return net_input_data_symbol?(data_modifier(env, node))
79
+ else
80
+ return false
81
+ end
45
82
  end
46
83
 
47
- # test
48
- return (name.size > 0 and name[0] == "'")
49
- end
84
+ # Return true if the node is a net output data place.
85
+ #
86
+ # @param env [Lang::Environment]
87
+ # language environment
88
+ # @param node [PNML::Node]
89
+ # the node
90
+ # @return [Boolean]
91
+ # true if the node is a net output data place
92
+ def net_output_data_place?(env, node)
93
+ if data_place?(env, node)
94
+ return net_output_data_symbol?(data_modifier(node))
95
+ else
96
+ return false
97
+ end
98
+ end
50
99
 
51
- # Return true if the node is a ticket in PIONE model.
52
- #
53
- # @return [Boolean]
54
- # true if the node is a ticket
55
- def self.ticket?(node)
56
- # tickets should be represented as a place
57
- return false unless node.is_a?(Place)
100
+ # Return true if the node is a parameter.
101
+ #
102
+ # @param env [Lang::Environment]
103
+ # language environment
104
+ # @param node [PNML::Node]
105
+ # the node
106
+ # @return [Boolean]
107
+ # true if the node is a parameter
108
+ def param_place?(env, node)
109
+ match_place_parser_with_type?(env, node, :expr_place, :expr, Lang::TypeParameterSet)
110
+ end
58
111
 
59
- # try parsing as a ticket expression
60
- Lang::Parser.ticket_expr.parse(node.name)
112
+ # Return true if the node is a parameter sentence transition.
113
+ #
114
+ # @param env [Lang::Environment]
115
+ # language environment
116
+ # @param node [PNML::Node]
117
+ # PNML's node
118
+ # @return [Boolean]
119
+ # true if the node is a parameter sentence transition
120
+ def param_transition?(env, node)
121
+ match_transition_parser?(env, node, :param_sentence)
122
+ end
61
123
 
62
- # the node is a ticket
63
- return true
64
- rescue Parslet::ParseFailed => e
65
- # the node is not a ticket
66
- return false
67
- end
124
+ # Evaluate the node as a parameter sentence.
125
+ #
126
+ # @param env [Lang::Environment]
127
+ # language environment
128
+ # @param node [PNML::Node]
129
+ # PNML's node
130
+ # @return [Object]
131
+ # evaluated result
132
+ def eval_param_sentence(env, node)
133
+ eval_transition(env, node, :param_sentence, :param_sentence)
134
+ end
68
135
 
69
- # Return true if the node is a parameter in PIONE model.
70
- #
71
- # @return [Boolean]
72
- # true if the node is a parameter
73
- def self.param?(node)
74
- # parameter node should be represented as a place
75
- return false unless node.is_a?(Place)
76
-
77
- # parameter node should be parsed as param sentence
78
- begin
79
- Lang::DocumentParser.new.param_sentence.parse(name)
80
- return true
81
- rescue
82
- return false
136
+ # Return true if the node is a ticket place.
137
+ #
138
+ # @param env [Lang::Environment]
139
+ # language environment
140
+ # @param node [PNML::Node]
141
+ # the node
142
+ # @return [Boolean]
143
+ # true if the node is a ticket place
144
+ def ticket_place?(env, node)
145
+ match_place_parser_with_type?(env, node, :expr_place, :expr, Lang::TypeTicketExpr)
83
146
  end
84
- end
85
147
 
86
- # Return true if the node is a rule.
87
- #
88
- # @param node [PNML::Node]
89
- # the node
90
- # @return [Boolean]
91
- # true if the node is a rule.
92
- def self.rule?(node)
93
- return false unless node.is_a?(Transition)
94
- return false unless not(node.name.nil?)
148
+ # Return true if the node is a feature place.
149
+ #
150
+ # @param env [Lang::Environment]
151
+ # language environment
152
+ # @param node [PNML::Node]
153
+ # the node
154
+ # @return [Boolean]
155
+ # true if the node is a feature place
156
+ def feature_place?(env, node)
157
+ match_place_parser_with_type?(env, node, :expr_place, :expr, Lang::TypeFeature)
158
+ end
95
159
 
96
- name = node.name.strip
160
+ # Return true if the node is a feature transition.
161
+ #
162
+ # @param env [Lang::Environment]
163
+ # language environment
164
+ # @param node [PNML::Node]
165
+ # the node
166
+ # @return [Boolean]
167
+ # true if the node is a feature transition
168
+ def feature_transition?(env, node)
169
+ match_place_parser?(env, node, :feature_sentence)
170
+ end
97
171
 
98
- # keywords
99
- if ["if", "else", "then"].include?(name)
100
- return false
172
+ # Return true if the node is a variable binding transition.
173
+ #
174
+ # @param env [Lang::Environment]
175
+ # language environment
176
+ # @param node [PNML::Node]
177
+ # the node
178
+ # @return [Boolean]
179
+ # true if the node is a variable binding transition
180
+ def variable_binding_transition?(env, node)
181
+ match_transition_parser?(env, node, :variable_binding_sentence)
101
182
  end
102
183
 
103
- return name.size > 0
104
- end
184
+ # Return true if the node is a rule.
185
+ #
186
+ # @param env [Lang::Environment]
187
+ # language environment
188
+ # @param node [PNML::Node]
189
+ # the node
190
+ # @return [Boolean]
191
+ # true if the node is a rule.
192
+ def rule_transition?(env, node)
193
+ match_transition_parser?(env, node, :rule_transition)
194
+ end
105
195
 
106
- # Return ture if the node is a flow rule.
107
- def self.flow_rule?(node)
108
- rule?(node) and node.name.strip.start_with?("&")
109
- end
196
+ # Return ture if the node is an internal rule.
197
+ #
198
+ # @param env [Lang::Environment]
199
+ # language environment
200
+ # @param [PNML::Node] node
201
+ # PNML node
202
+ # @return [Boolean]
203
+ # true if the node is an internal rule
204
+ def internal_rule_transition?(env, node)
205
+ match_transition_parser?(env, node, :internal_rule_transition)
206
+ end
110
207
 
111
- def self.action_rule?(node)
112
- rule?(node) and not(flow_rule?(node))
113
- end
208
+ # Return ture if the node is an external rule.
209
+ #
210
+ # @param env [Lang::Environment]
211
+ # language environment
212
+ # @param [PNML::Node] node
213
+ # PNML node
214
+ # @return [Boolean]
215
+ # true if the node is an external rule
216
+ def external_rule_transition?(env, node)
217
+ match_transition_parser?(env, node, :external_rule_transition)
218
+ end
114
219
 
115
- def self.normalize_data_name(name)
116
- return nil if name.nil?
220
+ # Return the modifier of node name.
221
+ #
222
+ # @param env [Lang::Environment]
223
+ # language environment
224
+ # @param node [PNML::Node]
225
+ # the node
226
+ # @return [String]
227
+ # modifier or nil
228
+ def data_modifier(env, node)
229
+ if node.kind_of?(Place) and not(node.name.nil?)
230
+ begin
231
+ parsed = Parser.new.data_place.parse(node.name)
232
+ if parsed.kind_of?(Hash)
233
+ return parsed[:modifier].to_s
234
+ end
235
+ rescue Parslet::ParseFailed
236
+ begin
237
+ parsed = Parser.new.empty_place.parse(node.name)
238
+ if parsed.kind_of?(Hash)
239
+ return parsed[:modifier].to_s
240
+ end
241
+ rescue Parslet::ParseFailed
242
+ end
243
+ end
244
+ end
245
+ return nil
246
+ end
117
247
 
118
- name = name.strip
119
- name = remove_comment(name)
120
- if name.size > 0 and name[0] == "<" or name[0] == ">"
121
- name[1..-1].strip
122
- else
123
- name
248
+ # Return true if the node is a transition with keyword.
249
+ #
250
+ # @param env [Lang::Environment]
251
+ # language environment
252
+ # @param node [PNML::Node]
253
+ # PNML's node
254
+ # @return [Boolean]
255
+ # true if the node is a transition with keyword
256
+ def keyword_transition?(env, node)
257
+ match_transition_parser?(env, node, :keyword_transition)
124
258
  end
125
- end
126
259
 
127
- def self.compact(name)
128
- remove_comment(name)
129
- end
260
+ # Return true if the node is a transition with keyword "if".
261
+ #
262
+ # @param env [Lang::Environment]
263
+ # language environment
264
+ # @param node [PNML::Node]
265
+ # PNML's node
266
+ # @return [Boolean]
267
+ # true if the node is a transition with keyword "if"
268
+ def if_transition?(env, node)
269
+ match_transition_parser?(env, node, :if_transition)
270
+ end
130
271
 
131
- def self.remove_comment(name)
132
- name.sub(/#\s*$/, "").strip
133
- end
272
+ # Return true if the node is a transition with keyword "then".
273
+ #
274
+ # @param env [Lang::Environment]
275
+ # language environment
276
+ # @param node [PNML::Node]
277
+ # PNML's node
278
+ # @return [Boolean]
279
+ # true if the node is a transition with keyword "then"
280
+ def then_transition?(env, node)
281
+ match_transition_parser?(env, node, :then_transition)
282
+ end
134
283
 
135
- # Return true if the node is a net's input.
136
- #
137
- # @param node [PNML::Node]
138
- # the node
139
- # @return [Boolean]
140
- # true if the node is a net's input.
141
- def self.net_input?(node)
142
- node.name and compact(node.name)[0] == "<"
143
- end
284
+ # Return true if the node is a transition with keyword "else".
285
+ #
286
+ # @param env [Lang::Environment]
287
+ # language environment
288
+ # @param node [PNML::Node]
289
+ # PNML's node
290
+ # @return [Boolean]
291
+ # true if the node is a transition with keyword "else"
292
+ def else_transition?(env, node)
293
+ match_transition_parser?(env, node, :else_transition)
294
+ end
144
295
 
145
- # Return true if the node is a net's output.
146
- #
147
- # @param node [PNML::Node]
148
- # the node
149
- # @return [Boolean]
150
- # true if the node is a net's output.
151
- def self.net_output?(node)
152
- node.name and compact(node.name)[0] == ">"
153
- end
296
+ # Return true if the node is a transition with keyword "case".
297
+ #
298
+ # @param env [Lang::Environment]
299
+ # language environment
300
+ # @param node [PNML::Node]
301
+ # PNML's node
302
+ # @return [Boolean]
303
+ # true if the node is a transition with keyword "case"
304
+ def case_transition?(env, node)
305
+ match_transition_parser?(env, node, :case_transition)
306
+ end
154
307
 
155
- def self.modifier(name)
156
- if name.size > 0 and name.strip[0] == "<"
157
- return "<"
308
+ # Return true if the node is a transition with keyword "when".
309
+ #
310
+ # @param env [Lang::Environment]
311
+ # language environment
312
+ # @param node [PNML::Node]
313
+ # PNML's node
314
+ # @return [Boolean]
315
+ # true if the node is a transition with keyword "when"
316
+ def when_transition?(env, node)
317
+ match_transition_parser?(env, node, :when_transition)
158
318
  end
159
- if name.size > 0 and name.strip[0] == ">"
160
- return ">"
319
+
320
+ # Return true if the node is a transition with keyword "constraint".
321
+ #
322
+ # @param env [Lang::Environment]
323
+ # language environment
324
+ # @param node [PNML::Node]
325
+ # PNML's node
326
+ # @return [Boolean]
327
+ # true if the node is a transition with keyword "constraint"
328
+ def constraint_transition?(env, node)
329
+ match_transition_parser?(env, node, :constraint_transition)
161
330
  end
162
- return ""
163
- end
164
331
 
165
- private
332
+ private
333
+
334
+ # Return true if the string is net input data symbol.
335
+ #
336
+ # @param [String]
337
+ # string
338
+ # @return [Boolean]
339
+ # true if the string is net input data symbol
340
+ def net_input_data_symbol?(str)
341
+ return false if str.nil?
342
+
343
+ Parser.new.net_input_symbol.parse(str)
344
+ return true
345
+ rescue Parslet::ParseFailed
346
+ return false
347
+ end
348
+
349
+ # Return true if the string is net output data symbol.
350
+ #
351
+ # @param [String]
352
+ # string
353
+ # @return [Boolean]
354
+ # true if the string is net output data symbol
355
+ def net_output_data_symbol?(str)
356
+ return false if str.nil?
357
+
358
+ Parser.new.net_output_symbol.parse(str)
359
+ return true
360
+ rescue Parslet::ParseFailed
361
+ return false
362
+ end
363
+
364
+ # Return true if the node matches the place parser.
365
+ #
366
+ # @param env [Lang::Environment]
367
+ # language environment
368
+ # @param node [PNML::Node]
369
+ # PNML's node
370
+ # @param parser_name [String]
371
+ # place parser name
372
+ # @return [Boolean]
373
+ # true if the node is the place parser
374
+ def parse_place(env, node, parser_name)
375
+ if node.kind_of?(Place) and not(node.name.nil?)
376
+ begin
377
+ return Parser.new.send(parser_name).parse(node.name)
378
+ rescue Parslet::ParseFailed
379
+ end
380
+ end
381
+ end
382
+
383
+ # Return true if the node matches the place parser.
384
+ #
385
+ # @param env [Lang::Environment]
386
+ # language environment
387
+ # @param node [PNML::Node]
388
+ # PNML's node
389
+ # @param parser_name [String]
390
+ # place parser name
391
+ # @return [Boolean]
392
+ # true if the node is the place parser
393
+ def match_place_parser?(env, node, parser_name)
394
+ parsed = parse_place(env, node, parser_name)
395
+ if not(parsed.nil?)
396
+ if block_given?
397
+ return yield parsed
398
+ else
399
+ return true
400
+ end
401
+ else
402
+ return false
403
+ end
404
+ end
405
+
406
+ # Return true if the node matches the place parser and expected type.
407
+ #
408
+ # @param env [Lang::Environment]
409
+ # language environment
410
+ # @param node [PNML::Node]
411
+ # PNML's node
412
+ # @param parser_name [String]
413
+ # place parser name
414
+ # @param target_name [Symbol]
415
+ # target name that has expected type
416
+ # @param expected_type [Pione::Lang::Type]
417
+ # expected PIONE type
418
+ # @return [Boolean]
419
+ # true if the node is the place parser
420
+ def match_place_parser_with_type?(env, node, parser_name, target_name, expected_type)
421
+ parsed = parse_place(env, node, parser_name)
422
+ if parsed and parsed[target_name]
423
+ expr = Lang::DocumentTransformer.new.apply(parsed[target_name], TRANSFORMER_OPT)
424
+ return expr.pione_type(env) == expected_type
425
+ else
426
+ return false
427
+ end
428
+ end
429
+
430
+ # Return true if the node matches the transition parser.
431
+ #
432
+ # @param env [Lang::Environment]
433
+ # language environment
434
+ # @param node [PNML::Node]
435
+ # PNML's node
436
+ # @param parser_name [Symbol]
437
+ # place parser name
438
+ # @return [Boolean]
439
+ # true if the node is the transition parser
440
+ def parse_transition(env, node, parser_name)
441
+ if node.kind_of?(Transition) and not(node.name.nil?)
442
+ begin
443
+ return Parser.new.send(parser_name).parse(node.name)
444
+ rescue Parslet::ParseFailed
445
+ end
446
+ end
447
+ end
448
+
449
+ # Return true if the node matches the transition parser.
450
+ #
451
+ # @param env [Lang::Environment]
452
+ # language environment
453
+ # @param node [PNML::Node]
454
+ # PNML's node
455
+ # @param parser_name [Symbol]
456
+ # transition parser name
457
+ # @return [Boolean]
458
+ # true if the node is the keyword
459
+ def match_transition_parser?(env, node, parser_name)
460
+ not(parse_transition(env, node, parser_name).nil?)
461
+ end
462
+
463
+ # Evaluate the transition and return the result.
464
+ #
465
+ # @param env [Lang::Environment]
466
+ # language environment
467
+ # @param node [PNML::Node]
468
+ # PNML's node
469
+ # @param parser_name [Symbol]
470
+ # place parser name
471
+ # @param target_name [Symbol]
472
+ # target name that has expected type
473
+ # @param expected_type [Pione::Lang::Type]
474
+ # expected PIONE type
475
+ # @return [Boolean]
476
+ # true if the node is the place parser
477
+ def eval_transition(env, node, parser_name, target_name)
478
+ parsed = parse_transition(node)
479
+ if parsed and parsed[target_name]
480
+ return Lang::DocumentTransformer.new.apply(parsed[target_name], TRANSFORMER_OPT)
481
+ else
482
+ return nil
483
+ end
484
+ end
485
+ end
486
+ end
166
487
 
488
+ class PioneModel
167
489
  # Return an indented version of the string. Indentation size is calculated
168
490
  # by the optional argument `:level`. If the level is zero, return the
169
491
  # string as is.
@@ -178,8 +500,8 @@ module Pione
178
500
  end
179
501
  end
180
502
 
181
- # `ConstituentRule` is a class represents PIONE's constituent rule.
182
- class ConstituentRule < Perspective
503
+ # ConstituentRule is a class represents PIONE's constituent rule.
504
+ class ConstituentRule < PioneModel
183
505
  attr_reader :type
184
506
  attr_reader :name
185
507
  attr_reader :params
@@ -204,69 +526,46 @@ module Pione
204
526
 
205
527
  private
206
528
 
207
- # Return a string form of PIONE's rule expression.
529
+ # Return a string of rule expression.
530
+ #
531
+ # @return [String]
532
+ # a string of rule expression
208
533
  def textize_rule_expr
209
534
  [@name, textize_params].compact.join(" ")
210
535
  end
211
536
 
212
- # Return a string form of PIONE's parameter set.
537
+ # Return a string of parameter set.
538
+ #
539
+ # @return [String]
540
+ # a string of parameter set
213
541
  def textize_params
214
542
  unless @params.empty?
215
- "{%s}" % [@params.map{|param| "%s: $%s" % [param.name, param.name]}.join(", ")]
543
+ @params.inject(Param.new){|res, param| res + param}.as_expr
216
544
  end
217
545
  end
218
546
  end
219
547
 
220
548
  # `DataCondition` is a class represents PIONE's input and output data condition.
221
- class DataCondition < Perspective
549
+ class Data < PioneModel
222
550
  attr_reader :data_expr
223
551
  attr_accessor :input_distribution
224
552
  attr_accessor :output_distribution
225
- attr_accessor :input_priority
226
- attr_accessor :output_priority
553
+ attr_accessor :priority
227
554
  attr_accessor :input_nonexistable
228
555
  attr_accessor :output_nonexistable
229
556
  attr_accessor :output_for_this_flow
230
557
 
231
- # @param data_expr [String]
558
+ # @param nod [PNML::Node]
232
559
  # data expression as a PIONE's expression string
233
- # @param attr [Hash]
234
- # various attributes for the data expression
235
- # @option attr [Symbol] :input_distribution
236
- # input distribution type of either `:each` or `:all`
237
- # @option attr [Symbol] :output_distribution
238
- # output distribution type of either `:each` or `:all`
239
- # @option attr [Integer] :input_priority
240
- # priority of this input condition
241
- # @option attr [Integer] :output_priority
242
- # priority of this output condition
243
- # @option attr [Boolean] :output_for_this_flow
244
- # flag for this flow's output
245
- def initialize(data_expr, attr={})
246
- @data_expr = data_expr
247
- @input_distribution = attr[:input_distribution]
248
- @output_distribution = attr[:output_distribution]
249
- @input_priority = attr[:input_priority] || 1
250
- @output_priority = attr[:output_priority] || 1
251
- @input_nonexistable = attr[:input_nonexistable]
252
- @output_nonexistable = attr[:output_nonexistable]
253
- @output_for_this_flow = attr[:output_for_this_flow]
254
- end
255
-
256
- # Return a declaration string of the data expression as input condition.
257
- def as_input_declaration(option={})
258
- indent("input %s" % textize_data_expr(:input), option)
259
- end
260
-
261
- # Return a declaration string of the data expression as output condition.
262
- def as_output_declaration(option={})
263
- indent("output %s" % textize_data_expr(:output), option)
560
+ def initialize(node)
561
+ @name = LabelExtractor.extract_data_expr(node.name)
562
+ @priority = LabelExtractor.extract_priority(node.name)
264
563
  end
265
564
 
266
565
  private
267
566
 
268
567
  def textize_data_expr(type)
269
- data_expr = "%s" % @data_expr
568
+ data_expr = "%s" % @name
270
569
  if (type == :input and @input_nonexistable) or (type == :output and @output_nonexistable)
271
570
  data_expr = data_expr + " or null"
272
571
  end
@@ -280,28 +579,105 @@ module Pione
280
579
  end
281
580
  end
282
581
 
283
- # `Param` is a class represents PIONE's paramter declaration.
284
- class Param < Perspective
582
+ class InputData < Data
583
+ # Return a declaration string of the data expression as input condition.
584
+ def as_declaration(option={})
585
+ indent("input %s" % textize_data_expr(:input), option)
586
+ end
587
+ end
588
+
589
+ class OutputData < Data
590
+ # Return a declaration string of the data expression as output condition.
591
+ def as_declaration(option={})
592
+ indent("output %s" % textize_data_expr(:output), option)
593
+ end
594
+ end
595
+
596
+ # Param is a class represents PIONE's paramter set.
597
+ class Param < PioneModel
598
+ # Create a parameter from the parameter set node.
599
+ #
600
+ # @param node [PNML::Node]
601
+ # parameter set node
602
+ # @return [Param]
603
+ # parameter
604
+ def self.set_of(node)
605
+ new(LabelExtractor.extract_data_from_param_set(node.name))
606
+ end
607
+
608
+ # Create a parameter from the parameter sentence node.
609
+ #
610
+ # @param node [PNML::Node]
611
+ # parameter sentence node
612
+ # @return [Param]
613
+ # parameter
614
+ def self.sentence_of(node)
615
+ new(LabelExtractor.extract_data_from_param_sentence(node.name))
616
+ end
617
+
618
+ attr_reader :data
619
+
620
+ # @param data [Hash]
621
+ # param set data
622
+ def initialize(data={})
623
+ @data = data
624
+ end
625
+
626
+ def as_expr
627
+ @data.map do |var, expr|
628
+ "%s: %s" % [var, expr]
629
+ end.join(", ").tap {|x| return "{%s}" % x}
630
+ end
631
+
632
+ def as_declarations(option={})
633
+ @data.map do |var, expr|
634
+ indent("param $%s := %s" % [var, expr], option)
635
+ end
636
+ end
637
+
638
+ def +(other)
639
+ self.class.new(@data.merge(other.data))
640
+ end
641
+ end
642
+
643
+ # Constraint represents a PIONE's constraint declaration.
644
+ class Constraint < PioneModel
645
+ attr_reader :expr
646
+
647
+ def initialize(expr)
648
+ @expr = expr
649
+ end
650
+
651
+ def as_declaration(option={})
652
+ indent("constraint " + @expr, option)
653
+ end
654
+ end
655
+
656
+ # Ticket represents a PIONE's ticket declaration.
657
+ class Ticket < PioneModel
285
658
  attr_reader :name
286
- attr_reader :default_expr
287
659
 
288
- # @param name [String]
289
- # parameter name, note that this name doesn't include heading `$`
290
- # @param default expr [String]
291
- # default value expression
292
- def initialize(name, default_expr)
660
+ def initialize(name)
293
661
  @name = name
294
- @default_expr = default_expr
662
+ end
663
+ end
664
+
665
+ # Feature represents a feature declaration in PIONE.
666
+ class Feature < PioneModel
667
+ attr_reader :expr
668
+
669
+ def initialize(expr)
670
+ @expr = expr
295
671
  end
296
672
 
297
673
  def as_declaration(option={})
298
- indent("param $%s := %s" % [@name, @default_expr], option)
674
+ indent("feature " + @expr, option)
299
675
  end
300
676
  end
301
677
 
302
678
  # ConditionalBranch is a class represents PIONE's conditional branch
303
679
  # declaration.
304
- class ConditionalBranch < Perspective
680
+ class ConditionalBranch < PioneModel
305
681
  attr_reader :condition
306
682
  attr_reader :table
307
683
 
@@ -315,21 +691,22 @@ module Pione
315
691
  case @type
316
692
  when :"if"
317
693
  branch_then = @table[:then].map do |rule|
318
- " rule %s" % Perspective.normalize_data_name(rule.name)
694
+ rule.as_declaration(option.merge(level: option[:level] + 1))
319
695
  end.join("\n")
320
696
 
321
697
  if @table[:else].empty?
322
698
  indent(Util::Indentation.cut(TEMPLATE_IF) % [@condition, branch_then], option)
323
699
  else
324
700
  branch_else = @table[:else].map do |rule|
325
- " rule %s" % Perspective.normalize_data_name(rule.name)
701
+ rule.as_declaration(option.merge(level: option[:level] + 1))
326
702
  end.join("\n")
327
703
  indent(Util::Indentation.cut(TEMPLATE_IF_ELSE) % [@condition, branch_then, branch_else], option)
328
704
  end
329
705
  when :"case"
330
- branches = @table.each_with_object([]) do |(val, rules), list|
331
- list << ((val == :else) ? "else" : "when %s" % val)
332
- list.concat(rules.map{|rule| " rule %s" % rule.name})
706
+ branches = @table.each_with_object([]) do |(val, rules), lines|
707
+ lines << ((val == :else) ? "else" : "when %s" % val)
708
+ level = (option[:level] || 0) + 1
709
+ lines.concat(rules.map{|rule| rule.as_declaration(option.merge(level: level))})
333
710
  end.join("\n")
334
711
  indent(Util::Indentation.cut(TEMPLATE_CASE) % [@condition, branches], option)
335
712
  end
@@ -356,22 +733,34 @@ module Pione
356
733
  TXT
357
734
  end
358
735
 
359
- class RuleDefinition < Perspective
360
- attr_accessor :name
736
+ class RuleDefinition < PioneModel
361
737
  attr_accessor :type
362
738
  attr_accessor :inputs
363
739
  attr_accessor :outputs
364
740
  attr_accessor :params
741
+ attr_accessor :constraints
742
+ attr_accessor :features
743
+ attr_accessor :source_tickets
744
+ attr_accessor :target_tickets
365
745
  attr_accessor :conditions
746
+ attr_accessor :variable_bindings
366
747
  attr_accessor :flow_elements
367
748
  attr_accessor :action_content
368
749
 
369
- def initialize(name, type, option={})
750
+ def initialize(name, type, is_external, net_name, index, option={})
370
751
  @name = name
371
752
  @type = type
753
+ @is_external = is_external
754
+ @net_name = net_name
755
+ @index = index
372
756
  @inputs = option[:inputs] || []
373
757
  @outputs = option[:outputs] || []
374
758
  @params = option[:params] || []
759
+ @constraints = option[:constraints] || []
760
+ @features = option[:features] || []
761
+ @source_tickets = option[:source_tickets] || []
762
+ @target_tickets = option[:target_tickets] || []
763
+ @variable_bindings = option[:variable_bindings] || []
375
764
  @conditions = option[:conditions] || []
376
765
  @flow_elements = option[:flow_elements] || []
377
766
  @action_content = nil
@@ -385,70 +774,136 @@ module Pione
385
774
  @type == :action
386
775
  end
387
776
 
388
- def textize
389
- if flow?
390
- template = Util::Indentation.cut(FLOW_RULE_TEMPLATE)
391
- else
392
- if @action_content
393
- template = Util::Indentation.cut(LITERATE_ACTION_RULE_TEMPLATE)
777
+ def external?
778
+ @is_external
779
+ end
780
+
781
+ def name
782
+ external? ? generate_wrapper_name(@name) : @name
783
+ end
784
+
785
+ # Return the declaration form string.
786
+ def as_declaration(option={})
787
+ expr_source_tickets =
788
+ if @source_tickets.size > 0
789
+ "(%s) ==> " % @source_tickets.map {|ticket| "%s" % ticket.name}.join(" | ")
790
+ else
791
+ ""
792
+ end
793
+ expr_target_tickets =
794
+ if @target_tickets.size > 0
795
+ " ==> (%s)" % @target_tickets.map {|ticket| "%s" % ticket.name}.join(" | ")
796
+ else
797
+ ""
798
+ end
799
+ "rule %s%s%s" % [expr_source_tickets, name, expr_target_tickets]
800
+ end
801
+
802
+ # Make rule conditions.
803
+ #
804
+ # @return [Array<String>]
805
+ # rule condition lines
806
+ def rule_conditions
807
+ conditions = []
808
+ sort_data_list(@inputs).each do |input|
809
+ conditions << input.as_declaration
810
+ end
811
+ sort_data_list(@outputs).each do |output|
812
+ conditions << output.as_declaration
813
+ end
814
+ @params.each do |param|
815
+ conditions += param.as_declarations
816
+ end
817
+ @constraints.each do |constraint|
818
+ conditions << constraint.as_declaration
819
+ end
820
+ @features.each do |feature|
821
+ conditions << feature.as_declaration
822
+ end
823
+ conditions
824
+ end
825
+
826
+ def sort_data_list(data_list)
827
+ data_list.sort do |a, b|
828
+ priority_a = a.priority
829
+ priority_b = b.priority
830
+
831
+ if a.priority and b.priority
832
+ a.priority <=> b.priority
833
+ elsif a.priority
834
+ 1
835
+ elsif b.priority
836
+ -1
394
837
  else
395
- template = Util::Indentation.cut(ACTION_RULE_TEMPLATE)
838
+ 0
396
839
  end
397
840
  end
841
+ end
842
+
843
+ def textize
398
844
  ERB.new(template, nil, "-").result(binding)
399
845
  end
400
846
 
847
+ def template
848
+ if external?
849
+ return Util::Indentation.cut(WRAPPER_TEMPLATE)
850
+ end
851
+
852
+ if flow?
853
+ return Util::Indentation.cut(FLOW_RULE_TEMPLATE)
854
+ end
855
+
856
+ if @action_content
857
+ return Util::Indentation.cut(LITERATE_ACTION_RULE_TEMPLATE)
858
+ else
859
+ return Util::Indentation.cut(ACTION_RULE_TEMPLATE)
860
+ end
861
+ end
862
+
863
+ # Generate a name for wrapper rule.
864
+ def generate_wrapper_name(name)
865
+ "__%s_%s_%s__" % [@net_name, @name, @index]
866
+ end
867
+
401
868
  FLOW_RULE_TEMPLATE = <<-RULE
402
- Rule <%= @name %>
403
- <%- @inputs.each do |input| -%>
404
- input <%= input %>
405
- <%- end -%>
406
- <%- @outputs.each do |output| -%>
407
- output <%= output %>
408
- <%- end -%>
409
- <%- @params.each do |param| -%>
410
- <%= param.as_declaration %>
869
+ Rule <%= name %>
870
+ <%- rule_conditions.each do |condition| -%>
871
+ <%= condition %>
411
872
  <%- end -%>
412
873
  Flow
413
874
  <%- @flow_elements.each do |element| -%>
414
- <%- if element.is_a?(RuleDefinition) -%>
415
- rule <%= element.name %>
416
- <%- else -%>
417
- <%= element.as_declaration(level: 1) %>
418
- <%- end -%>
875
+ <%= element.as_declaration(level: 1) %>
419
876
  <%- end -%>
420
877
  End
421
878
  RULE
422
879
 
423
880
  ACTION_RULE_TEMPLATE = <<-RULE
424
- Rule <%= @name %>
425
- <%- @inputs.each do |input| -%>
426
- input <%= input %>
427
- <%- end -%>
428
- <%- @outputs.each do |output| -%>
429
- output (<%= output %>).touch
430
- <%- end -%>
431
- <%- @params.each do |param| -%>
432
- <%= param.as_declaration %>
881
+ Rule <%= name %>
882
+ <%- rule_conditions.each do |condition| -%>
883
+ <%= condition %>
433
884
  <%- end -%>
434
885
  End
435
886
  RULE
436
887
 
437
888
  LITERATE_ACTION_RULE_TEMPLATE = <<-RULE
438
- Rule <%= @name %>
439
- <%- @inputs.each do |input| -%>
440
- input <%= input %>
441
- <%- end -%>
442
- <%- @outputs.each do |output| -%>
443
- output <%= output %>
444
- <%- end -%>
445
- <%- @params.each do |param| -%>
446
- <%= param.as_declaration %>
889
+ Rule <%= name %>
890
+ <%- rule_conditions.each do |condition| -%>
891
+ <%= condition %>
447
892
  <%- end -%>
448
893
  Action
449
894
  <%= Util::Indentation.indent(@action_content, 2) -%>
450
895
  End
451
896
  RULE
897
+
898
+ WRAPPER_TEMPLATE = <<-RULE
899
+ Rule <%= name %>
900
+ <%- rule_conditions.each do |condition| -%>
901
+ <%= condition %>
902
+ <%- end -%>
903
+ Flow
904
+ rule <%= @name %>
905
+ End
906
+ RULE
452
907
  end
453
908
  end
454
909
  end