pione 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDZkOWNhZjVhNzZhZTE3MjU2MDM5OWFiYzM1NTUxMDEzMGQ0Y2FmNQ==
4
+ M2Q3OTY4ZmU2YzAwZjVmM2NiZGU4MDc2NTU1N2FhNGEzZTBkODA5ZA==
5
5
  data.tar.gz: !binary |-
6
- OWZiYTQ3YzA3YjNjNDQ5NTI3Y2ZhNTczYWMzN2FkNGM2MDdiN2Y5MA==
6
+ NDJjOWM4YTAxNTQ3ZmU4YjI5NjNhMjYwMjQ3NmZiNmJlM2JhY2YzZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTZiMmE3ZmRlMmNhZjE3MjhkOGQ5YzFhNGY4Njg0NGQwNDBiYzZlMTE2M2Vi
10
- YmU0NjVjMzUxYmYzYzgxZjQ2NDZkMmM1NWVjNWZlNDEzODZlNGUxNmFkYzM1
11
- YjY5ZDliYmFhMWI2ZWRkZjQ3YjM1ZGUxNTc3YmY2MWEyZTNjYTY=
9
+ Zjc4MTI1YjJhNDEyOWNlMzk0NjgxYjAzNzhjZmQwNjBiMTVkYTRkMmM3OTE3
10
+ NjI2OGMwZjEzYTY0NzBmZGUxNGIxZmU5NGU4NmI0MjU2MDhiMGUyNGEyNjJl
11
+ YzRjY2FlY2Y2NjhlYzFlOTkxOTFjNTk2ODkxZTFhMjQ1ZmRhYjM=
12
12
  data.tar.gz: !binary |-
13
- YjAwNjIxZWJlNDY2ZWZjODVlMDEzYWQyNmVmN2ZiZWFlMzgwOGQ1ZDAzZDk5
14
- MzY3YTNlNzc1YjU0MTA2OWFlMjE0YWY1Y2RlYjY4MWRmYjI0ODM5MzNjYzQ1
15
- MTMwZGUyYjNlN2EzZmUxNWFlM2ZhMmQ5NTA1ZjlkODY2MmE2MWE=
13
+ NWNhN2JmNzA4MmI4ODMzOWQwYTc2YzFlZDczNmZhOGM3OWI2NGNmMGQwYTFi
14
+ ZjgwZjI5NjIxOWM3YWU1MDY4Nzk1OTA3NzViMWM3Y2M5OThjZjhmZGIyMjAy
15
+ YWJjNjg4OTY3MjYxZjkzNjIwNDhmMjBmZmFmZTczZDk4ZWYwMTQ=
@@ -1,5 +1,10 @@
1
1
  # History
2
2
 
3
+ ## 0.4.2(2014/9/1)
4
+
5
+ * Enable to compile PNML with action documents.
6
+ * Add flow rule notation(`&` with rule name) for PNML document.
7
+
3
8
  ## 0.4.1(2014/8/11)
4
9
 
5
10
  * Work with new PIONE webclient.
@@ -0,0 +1,47 @@
1
+ # CountChar.pione
2
+
3
+ ## ConvertToUTF8
4
+
5
+ Convert character encoding of text files into UTF-8.
6
+
7
+ ```
8
+ iconv -c -f Shift_JIS -t UTF-8 {$I[1]} > {$O[1]}
9
+ ```
10
+
11
+ ## CountUTF8Char
12
+
13
+ Count UTF-8 characters in the text file.
14
+
15
+ ```
16
+ #!/usr/bin/env ruby
17
+ # coding: utf-8
18
+
19
+ table = {}
20
+ text = File.open("{$I[1]}").read
21
+ text.split("").each do |c|
22
+ table[c] = table.has_key?(c) ? table[c].succ : 1
23
+ end
24
+ table.keys.sort {|a,b| table[b] <=> table[a] }.each do |key|
25
+ puts "#{key.inspect[1..-2]}:#{table[key]}"
26
+ end
27
+ ```
28
+
29
+ ## Summarize
30
+
31
+ Make a summary about numbers of character in text files.
32
+
33
+ ```
34
+ #!/usr/bin/env ruby
35
+ # coding: utf-8
36
+
37
+ table = {}
38
+ "{$I[1]}".split(" ").each do |path|
39
+ File.read(path).split("\n").map do |line|
40
+ c, number = line.split(":")
41
+ table[c] = (table.has_key?(c) ? table[c] : 0) + number.to_i
42
+ end
43
+ end
44
+ table.keys.sort {|a,b| table[b] <=> table[a] }.each do |key|
45
+ puts "#{key.inspect[1..-2]}:#{table[key]}"
46
+ end
47
+ ```
@@ -1,34 +1,21 @@
1
- Rule Main
2
- input ('*.txt' or 'terminate.cmd').except('summary.txt').all
3
- output '*.count'.all
4
- output 'summary.txt'
5
- Flow
6
- rule CountChar
7
- rule Summarize
8
- End
1
+ .@ PackageName :: "CountChar"
9
2
 
10
- Rule CountChar
11
- input '*.txt'.except('summary.txt')
12
- output '{$*}.count'
3
+ Rule Main
4
+ input '*.txt'
5
+ output 'summary.out'
13
6
  Flow
14
- rule ConvertToUtf8
15
7
  rule CountUTF8Char
16
- rule Terminate
17
- End
18
-
19
- Rule ConvertToUtf8
20
- input '*.txt'.except('summary.txt')
21
- output '{$*}.utf8'
22
- Action
23
- iconv -c -f Shift_JIS -t UTF-8 {$I[1]} > {$O[1]}
8
+ rule ConvertToUTF8
9
+ rule Summarize
24
10
  End
25
11
 
26
12
  Rule CountUTF8Char
27
13
  input '*.utf8'
28
14
  output '{$*}.count'.stdout
29
15
  Action
30
- #!/usr/bin/env ruby
31
- # coding: utf-8
16
+ #!/usr/bin/env ruby
17
+ # coding: utf-8
18
+
32
19
  table = {}
33
20
  text = File.open("{$I[1]}").read
34
21
  text.split("").each do |c|
@@ -39,12 +26,20 @@ Action
39
26
  end
40
27
  End
41
28
 
29
+ Rule ConvertToUTF8
30
+ input '*.txt'
31
+ output '{$*}.utf8'
32
+ Action
33
+ iconv -c -f Shift_JIS -t UTF-8 {$I[1]} > {$O[1]}
34
+ End
35
+
42
36
  Rule Summarize
43
37
  input '*.count'.all
44
- output 'summary.txt'.stdout
38
+ output 'summary.out'.stdout
45
39
  Action
46
- #!/usr/bin/env ruby
47
- # coding: utf-8
40
+ #!/usr/bin/env ruby
41
+ # coding: utf-8
42
+
48
43
  table = {}
49
44
  "{$I[1]}".split(" ").each do |path|
50
45
  File.read(path).split("\n").map do |line|
@@ -56,9 +51,3 @@ Action
56
51
  puts "#{key.inspect[1..-2]}:#{table[key]}"
57
52
  end
58
53
  End
59
-
60
- Rule Terminate
61
- input 'terminate.cmd'
62
- Flow
63
- rule &system:Terminate
64
- End
@@ -0,0 +1,358 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--PLEASE DO NOT EDIT THIS FILE
3
+ Created with Workflow PetriNet Designer Version 1.0 (woped.org)-->
4
+ <pnml>
5
+ <net type="http://www.informatik.hu-berlin.de/top/pntd/ptNetb" id="noID">
6
+ <place id="p7">
7
+ <name>
8
+ <text>'*.utf8'</text>
9
+ <graphics>
10
+ <offset x="400" y="210"/>
11
+ </graphics>
12
+ </name>
13
+ <graphics>
14
+ <position x="400" y="170"/>
15
+ <dimension x="40" y="40"/>
16
+ </graphics>
17
+ </place>
18
+ <place id="p6">
19
+ <name>
20
+ <text>'summary.out'.stdout</text>
21
+ <graphics>
22
+ <offset x="480" y="340"/>
23
+ </graphics>
24
+ </name>
25
+ <graphics>
26
+ <position x="480" y="300"/>
27
+ <dimension x="40" y="40"/>
28
+ </graphics>
29
+ </place>
30
+ <place id="p5">
31
+ <name>
32
+ <text>'{$*}.count'.stdout</text>
33
+ <graphics>
34
+ <offset x="560" y="150"/>
35
+ </graphics>
36
+ </name>
37
+ <graphics>
38
+ <position x="560" y="170"/>
39
+ <dimension x="40" y="40"/>
40
+ </graphics>
41
+ </place>
42
+ <place id="p4">
43
+ <name>
44
+ <text>>'summary.out'</text>
45
+ <graphics>
46
+ <offset x="640" y="340"/>
47
+ </graphics>
48
+ </name>
49
+ <graphics>
50
+ <position x="640" y="300"/>
51
+ <dimension x="40" y="40"/>
52
+ </graphics>
53
+ </place>
54
+ <place id="p3">
55
+ <name>
56
+ <text>'*.count'.all</text>
57
+ <graphics>
58
+ <offset x="310" y="340"/>
59
+ </graphics>
60
+ </name>
61
+ <graphics>
62
+ <position x="310" y="300"/>
63
+ <dimension x="40" y="40"/>
64
+ </graphics>
65
+ </place>
66
+ <place id="p2">
67
+ <name>
68
+ <text>'{$*}.utf8'</text>
69
+ <graphics>
70
+ <offset x="240" y="210"/>
71
+ </graphics>
72
+ </name>
73
+ <graphics>
74
+ <position x="240" y="170"/>
75
+ <dimension x="40" y="40"/>
76
+ </graphics>
77
+ </place>
78
+ <place id="p1">
79
+ <name>
80
+ <text>&lt;'*.txt'</text>
81
+ <graphics>
82
+ <offset x="70" y="210"/>
83
+ </graphics>
84
+ </name>
85
+ <graphics>
86
+ <position x="70" y="170"/>
87
+ <dimension x="40" y="40"/>
88
+ </graphics>
89
+ </place>
90
+ <transition id="t3">
91
+ <name>
92
+ <text>CountUTF8Char</text>
93
+ <graphics>
94
+ <offset x="480" y="210"/>
95
+ </graphics>
96
+ </name>
97
+ <graphics>
98
+ <position x="480" y="170"/>
99
+ <dimension x="40" y="40"/>
100
+ </graphics>
101
+ <toolspecific tool="WoPeD" version="1.0">
102
+ <time>0</time>
103
+ <timeUnit>1</timeUnit>
104
+ <orientation>1</orientation>
105
+ </toolspecific>
106
+ </transition>
107
+ <transition id="t2">
108
+ <name>
109
+ <text/>
110
+ <graphics>
111
+ <offset x="650" y="210"/>
112
+ </graphics>
113
+ </name>
114
+ <graphics>
115
+ <position x="650" y="170"/>
116
+ <dimension x="40" y="40"/>
117
+ </graphics>
118
+ <toolspecific tool="WoPeD" version="1.0">
119
+ <time>0</time>
120
+ <timeUnit>1</timeUnit>
121
+ <orientation>1</orientation>
122
+ </toolspecific>
123
+ </transition>
124
+ <transition id="t1">
125
+ <name>
126
+ <text>ConvertToUTF8</text>
127
+ <graphics>
128
+ <offset x="150" y="210"/>
129
+ </graphics>
130
+ </name>
131
+ <graphics>
132
+ <position x="150" y="170"/>
133
+ <dimension x="40" y="40"/>
134
+ </graphics>
135
+ <toolspecific tool="WoPeD" version="1.0">
136
+ <time>0</time>
137
+ <timeUnit>1</timeUnit>
138
+ <orientation>1</orientation>
139
+ </toolspecific>
140
+ </transition>
141
+ <transition id="t4">
142
+ <name>
143
+ <text>Summarize</text>
144
+ <graphics>
145
+ <offset x="400" y="340"/>
146
+ </graphics>
147
+ </name>
148
+ <graphics>
149
+ <position x="400" y="300"/>
150
+ <dimension x="40" y="40"/>
151
+ </graphics>
152
+ <toolspecific tool="WoPeD" version="1.0">
153
+ <time>0</time>
154
+ <timeUnit>1</timeUnit>
155
+ <orientation>1</orientation>
156
+ </toolspecific>
157
+ </transition>
158
+ <transition id="t5">
159
+ <name>
160
+ <text/>
161
+ <graphics>
162
+ <offset x="560" y="340"/>
163
+ </graphics>
164
+ </name>
165
+ <graphics>
166
+ <position x="560" y="300"/>
167
+ <dimension x="40" y="40"/>
168
+ </graphics>
169
+ <toolspecific tool="WoPeD" version="1.0">
170
+ <time>0</time>
171
+ <timeUnit>1</timeUnit>
172
+ <orientation>1</orientation>
173
+ </toolspecific>
174
+ </transition>
175
+ <transition id="t6">
176
+ <name>
177
+ <text/>
178
+ <graphics>
179
+ <offset x="320" y="210"/>
180
+ </graphics>
181
+ </name>
182
+ <graphics>
183
+ <position x="320" y="170"/>
184
+ <dimension x="40" y="40"/>
185
+ </graphics>
186
+ <toolspecific tool="WoPeD" version="1.0">
187
+ <time>0</time>
188
+ <timeUnit>1</timeUnit>
189
+ <orientation>1</orientation>
190
+ </toolspecific>
191
+ </transition>
192
+ <transition id="t7">
193
+ <name>
194
+ <text>.@ PackageName :: "CountChar"</text>
195
+ <graphics>
196
+ <offset x="70" y="120"/>
197
+ </graphics>
198
+ </name>
199
+ <graphics>
200
+ <position x="70" y="80"/>
201
+ <dimension x="40" y="40"/>
202
+ </graphics>
203
+ <toolspecific tool="WoPeD" version="1.0">
204
+ <time>0</time>
205
+ <timeUnit>1</timeUnit>
206
+ <orientation>1</orientation>
207
+ </toolspecific>
208
+ </transition>
209
+ <arc id="a9" source="p3" target="t4">
210
+ <inscription>
211
+ <text>1</text>
212
+ </inscription>
213
+ <graphics/>
214
+ <toolspecific tool="WoPeD" version="1.0">
215
+ <probability>1.0</probability>
216
+ <displayProbabilityOn>false</displayProbabilityOn>
217
+ <displayProbabilityPosition x="500.0" y="0.0"/>
218
+ </toolspecific>
219
+ </arc>
220
+ <arc id="a12" source="t2" target="p3">
221
+ <inscription>
222
+ <text>1</text>
223
+ </inscription>
224
+ <graphics/>
225
+ <toolspecific tool="WoPeD" version="1.0">
226
+ <probability>1.0</probability>
227
+ <displayProbabilityOn>false</displayProbabilityOn>
228
+ <displayProbabilityPosition x="500.0" y="0.0"/>
229
+ </toolspecific>
230
+ </arc>
231
+ <arc id="a10" source="t4" target="p6">
232
+ <inscription>
233
+ <text>1</text>
234
+ </inscription>
235
+ <graphics/>
236
+ <toolspecific tool="WoPeD" version="1.0">
237
+ <probability>1.0</probability>
238
+ <displayProbabilityOn>false</displayProbabilityOn>
239
+ <displayProbabilityPosition x="500.0" y="0.0"/>
240
+ </toolspecific>
241
+ </arc>
242
+ <arc id="a11" source="p7" target="t3">
243
+ <inscription>
244
+ <text>1</text>
245
+ </inscription>
246
+ <graphics/>
247
+ <toolspecific tool="WoPeD" version="1.0">
248
+ <probability>1.0</probability>
249
+ <displayProbabilityOn>false</displayProbabilityOn>
250
+ <displayProbabilityPosition x="500.0" y="0.0"/>
251
+ </toolspecific>
252
+ </arc>
253
+ <arc id="a1" source="p1" target="t1">
254
+ <inscription>
255
+ <text>1</text>
256
+ </inscription>
257
+ <graphics/>
258
+ <toolspecific tool="WoPeD" version="1.0">
259
+ <probability>1.0</probability>
260
+ <displayProbabilityOn>false</displayProbabilityOn>
261
+ <displayProbabilityPosition x="500.0" y="0.0"/>
262
+ </toolspecific>
263
+ </arc>
264
+ <arc id="a2" source="t1" target="p2">
265
+ <inscription>
266
+ <text>1</text>
267
+ </inscription>
268
+ <graphics/>
269
+ <toolspecific tool="WoPeD" version="1.0">
270
+ <probability>1.0</probability>
271
+ <displayProbabilityOn>false</displayProbabilityOn>
272
+ <displayProbabilityPosition x="500.0" y="0.0"/>
273
+ </toolspecific>
274
+ </arc>
275
+ <arc id="a3" source="p6" target="t5">
276
+ <inscription>
277
+ <text>1</text>
278
+ </inscription>
279
+ <graphics/>
280
+ <toolspecific tool="WoPeD" version="1.0">
281
+ <probability>1.0</probability>
282
+ <displayProbabilityOn>false</displayProbabilityOn>
283
+ <displayProbabilityPosition x="500.0" y="0.0"/>
284
+ </toolspecific>
285
+ </arc>
286
+ <arc id="a4" source="t5" target="p4">
287
+ <inscription>
288
+ <text>1</text>
289
+ </inscription>
290
+ <graphics/>
291
+ <toolspecific tool="WoPeD" version="1.0">
292
+ <probability>1.0</probability>
293
+ <displayProbabilityOn>false</displayProbabilityOn>
294
+ <displayProbabilityPosition x="500.0" y="0.0"/>
295
+ </toolspecific>
296
+ </arc>
297
+ <arc id="a5" source="p2" target="t6">
298
+ <inscription>
299
+ <text>1</text>
300
+ </inscription>
301
+ <graphics/>
302
+ <toolspecific tool="WoPeD" version="1.0">
303
+ <probability>1.0</probability>
304
+ <displayProbabilityOn>false</displayProbabilityOn>
305
+ <displayProbabilityPosition x="500.0" y="0.0"/>
306
+ </toolspecific>
307
+ </arc>
308
+ <arc id="a6" source="t6" target="p7">
309
+ <inscription>
310
+ <text>1</text>
311
+ </inscription>
312
+ <graphics/>
313
+ <toolspecific tool="WoPeD" version="1.0">
314
+ <probability>1.0</probability>
315
+ <displayProbabilityOn>false</displayProbabilityOn>
316
+ <displayProbabilityPosition x="500.0" y="0.0"/>
317
+ </toolspecific>
318
+ </arc>
319
+ <arc id="a7" source="t3" target="p5">
320
+ <inscription>
321
+ <text>1</text>
322
+ </inscription>
323
+ <graphics/>
324
+ <toolspecific tool="WoPeD" version="1.0">
325
+ <probability>1.0</probability>
326
+ <displayProbabilityOn>false</displayProbabilityOn>
327
+ <displayProbabilityPosition x="500.0" y="0.0"/>
328
+ </toolspecific>
329
+ </arc>
330
+ <arc id="a8" source="p5" target="t2">
331
+ <inscription>
332
+ <text>1</text>
333
+ </inscription>
334
+ <graphics/>
335
+ <toolspecific tool="WoPeD" version="1.0">
336
+ <probability>1.0</probability>
337
+ <displayProbabilityOn>false</displayProbabilityOn>
338
+ <displayProbabilityPosition x="500.0" y="0.0"/>
339
+ </toolspecific>
340
+ </arc>
341
+ <toolspecific tool="WoPeD" version="1.0">
342
+ <bounds>
343
+ <position x="2" y="25"/>
344
+ <dimension x="1425" y="596"/>
345
+ </bounds>
346
+ <scale>100</scale>
347
+ <treeWidthRight>1129</treeWidthRight>
348
+ <overviewPanelVisible>true</overviewPanelVisible>
349
+ <treeHeightOverview>100</treeHeightOverview>
350
+ <treePanelVisible>true</treePanelVisible>
351
+ <verticalLayout>false</verticalLayout>
352
+ <resources/>
353
+ <simulations/>
354
+ <partnerLinks/>
355
+ <variables/>
356
+ </toolspecific>
357
+ </net>
358
+ </pnml>
@@ -0,0 +1,18 @@
1
+ {
2
+ "PackageName": "CountChar",
3
+ "Parents": [
4
+
5
+ ],
6
+ "Documents": [
7
+ "Main.pione"
8
+ ],
9
+ "Scenarios": [
10
+
11
+ ],
12
+ "Bins": [
13
+
14
+ ],
15
+ "Etcs": [
16
+
17
+ ]
18
+ }
@@ -52,15 +52,33 @@ module Pione
52
52
  item.desc = 'Set package tag'
53
53
  end
54
54
 
55
+ option(:literate_action_document) do |item|
56
+ item.type = :string
57
+ item.long = '--action'
58
+ item.arg = 'LOCATION'
59
+ item.desc = 'Set a literate action document'
60
+ end
61
+
55
62
  #
56
63
  # command lifecycle: execution phase
57
64
  #
58
65
 
59
66
  phase(:execution) do |item|
67
+ item << :literate_action
60
68
  item << :compile_pnml
61
69
  item << :print
62
70
  end
63
71
 
72
+ execution(:literate_action) do |item|
73
+ item.desc = "Parse a literate action document."
74
+
75
+ item.assign(:literate_action) do
76
+ if document = model[:literate_action_document]
77
+ LiterateAction::Parser.parse(Location[document].read)
78
+ end
79
+ end
80
+ end
81
+
64
82
  execution(:compile_pnml) do |item|
65
83
  item.desc = "Compile from PNML to PIONE"
66
84
 
@@ -70,7 +88,8 @@ module Pione
70
88
  :flow_name => model[:flow_name],
71
89
  :package_name => model[:package_name],
72
90
  :editor => model[:editor],
73
- :tag => model[:tag]
91
+ :tag => model[:tag],
92
+ :literate_actions => model[:literate_action]
74
93
  }
75
94
  PNML::Compiler.new(net, option).compile
76
95
  end
@@ -89,12 +89,12 @@ module Pione
89
89
  item.process do
90
90
  model[:source_locations].each do |location|
91
91
  if ppg = try_to_archive(location)
92
- Log::SystemLog.info("Package build process has succeeded: %s" % ppg.address)
92
+ Log::SystemLog.info('Package %s has been built successfully.' % ppg.address)
93
93
  cmd.terminate
94
94
  end
95
95
  end
96
96
 
97
- cmd.abort("Package build process has failed.")
97
+ cmd.abort("Package build has failed.")
98
98
  end
99
99
  end
100
100
  end
@@ -102,7 +102,34 @@ module Pione
102
102
  # `PionePackageBuildContext` is a context for `pione package build`.
103
103
  class PionePackageBuildContext < Rootage::CommandContext
104
104
  def try_to_archive(location)
105
- handler = Package::PackageReader.read(location)
105
+ local_location = location.local
106
+
107
+ # action documents
108
+ actions = local_location.entries.each_with_object(Hash.new) do |entry, actions|
109
+ if entry.basename.end_with?(".action.md")
110
+ actions.merge!(LiterateAction::Parser.parse(entry.read))
111
+ end
112
+ end
113
+
114
+ # compile
115
+ local_location.each_entry do |entry|
116
+ if (entry.extname == ".pnml")
117
+ flow_name = entry.basename(".pnml")
118
+ net = PNML::Reader.read(entry)
119
+ option = {
120
+ :flow_name => flow_name,
121
+ :literate_actions => actions,
122
+ }
123
+ content = PNML::Compiler.new(net, option).compile
124
+ file = entry.dirname + (flow_name + ".pione")
125
+ file.write(content)
126
+ end
127
+ end
128
+
129
+ # update
130
+ Package::PackageHandler.write_info_files(local_location, force: true)
131
+
132
+ handler = Package::PackageReader.read(local_location)
106
133
  cache_location = Package::PackageCache.directory_cache(handler.digest)
107
134
 
108
135
  # make archiver
@@ -112,6 +139,7 @@ module Pione
112
139
  return archiver.archive(model[:output], false)
113
140
  rescue => e
114
141
  Log::Debug.system("PIONE has failed to archive %s: %s" % [location, e.message])
142
+ return nil
115
143
  end
116
144
  end
117
145
 
@@ -29,7 +29,7 @@ module Pione
29
29
  option(:force) do |item|
30
30
  item.type = :boolean
31
31
  item.long = "--force"
32
- item.desc = "update pacakge info files"
32
+ item.desc = "Update pacakge information files"
33
33
  item.default = true
34
34
  end
35
35
 
@@ -1,6 +1,7 @@
1
1
  module Pione
2
2
  module LiterateAction
3
3
  class Document
4
+ # Load a literate document from the location.
4
5
  def self.load(location)
5
6
  new(location.read)
6
7
  end
@@ -9,12 +10,15 @@ module Pione
9
10
  @action = Parser.parse(src)
10
11
  end
11
12
 
12
- # Return action names in the document.
13
+ # Return action rule names in the document.
14
+ #
15
+ # @return [Array<String>]
16
+ # rule names
13
17
  def action_names
14
18
  @action.keys
15
19
  end
16
20
 
17
- # Find target action fromt the name.
21
+ # Find target action by the name.
18
22
  def find(name)
19
23
  if action = @action[name]
20
24
  Handler.new(action)
@@ -1,5 +1,6 @@
1
1
  module Pione
2
2
  module LiterateAction
3
+ # Handler is action rule handler.
3
4
  class Handler
4
5
  def initialize(action)
5
6
  @lang = action[:lang]
@@ -34,18 +34,22 @@ module Pione
34
34
 
35
35
  private
36
36
 
37
- # Find a rule name from the element.
37
+ # Find a rule name from the document element.
38
38
  def find_rule_name(elt)
39
39
  if elt.type == :header and elt.options[:level] == 2
40
40
  elt.options[:raw_text]
41
41
  end
42
42
  end
43
43
 
44
- # Find an action from the element.
44
+ # Find an action from the document element.
45
45
  def find_action(elt)
46
46
  if elt.type == :codeblock
47
47
  if elt.attr["class"] and elt.attr["class"].start_with?("language-")
48
+ # with language
48
49
  return [elt.attr["class"].sub("language-", ""), elt.value]
50
+ else
51
+ # without language
52
+ return [nil, elt.value]
49
53
  end
50
54
  end
51
55
  end
@@ -9,16 +9,16 @@ module Pione
9
9
  @tag = option[:tag]
10
10
  end
11
11
 
12
- # Extract an annotation from the place. If the place has the name that we
13
- # can parse as an annotation declarartion sentence, return the name as
14
- # is. Otherwise, return nil.
12
+ # Extract annotations from transitions. If the transition has the name
13
+ # that we can parse as an annotation declarartion sentence, return the
14
+ # name as is. Otherwise, return nil.
15
15
 
16
- # Extract annotations from places.
16
+ # Extract annotations from transitions.
17
17
  def extract
18
18
  package_annotations = []
19
19
 
20
- @net.places.each do |place|
21
- if line = extract_annotation(place)
20
+ @net.transitions.each do |transition|
21
+ if line = extract_annotation(transition)
22
22
  package_annotations << line
23
23
  end
24
24
  end
@@ -32,11 +32,11 @@ module Pione
32
32
 
33
33
  private
34
34
 
35
- # Extract an annotation from the place. If the place has the name that we
36
- # can parse as an annotation declarartion sentence, return the name as
37
- # is. Otherwise, return nil.
38
- def extract_annotation(place)
39
- name = place.name
35
+ # Extract an annotation from the transition. If the transition has the
36
+ # name that we can parse as an annotation declarartion sentence, return
37
+ # the name as is. Otherwise, return nil.
38
+ def extract_annotation(transition)
39
+ name = transition.name
40
40
  Lang::DocumentParser.new.annotation_sentence.parse(name)
41
41
  return name
42
42
  rescue Parslet::ParseFailed => e
@@ -25,6 +25,7 @@ module Pione
25
25
  rules << OutputDecompositionComplement
26
26
  rules << OutputSynchronizationComplement
27
27
  end
28
+ @actions = []
28
29
  end
29
30
 
30
31
  # Compile a PNML file into PIONE document as a string.
@@ -39,6 +40,15 @@ module Pione
39
40
  rules, flow_elements = build_constituent_rule_definitions
40
41
  definition_main = build_flow_rule_definition(@option[:flow_rule_name] || "Main", flow_elements)
41
42
 
43
+ # merge literate actions
44
+ rules.each do |rule|
45
+ if @option[:literate_actions]
46
+ if action = @option[:literate_actions][rule.name]
47
+ rule.action_content = action[:content]
48
+ end
49
+ end
50
+ end
51
+
42
52
  # textize
43
53
  [*annotations, "", definition_main.textize, *rules.map {|rule| rule.textize}].join("\n")
44
54
  end
@@ -49,7 +59,8 @@ module Pione
49
59
  def build_constituent_rule_definitions
50
60
  definition = @net.transitions.each_with_object({}) do |transition, table|
51
61
  if Perspective.rule?(transition)
52
- rule = RuleDefinition.new(transition.name)
62
+ type = Perspective.flow_rule?(transition) ? :flow : :action
63
+ rule = RuleDefinition.new(transition.name, type)
53
64
 
54
65
  # inputs
55
66
  @net.find_all_places_by_target_id(transition.id).each do |place|
@@ -75,14 +86,14 @@ module Pione
75
86
  end
76
87
 
77
88
  # save all inner rules
78
- rules = definition.values.compact
89
+ rules = definition.values.select{|rule_def| rule_def.action?}.compact
79
90
  flow_elements = definition.values.compact
80
91
 
81
92
  # conditional branch
82
93
  @net.transitions.each do |transition|
83
94
  places = @net.find_all_places_by_target_id(transition.id)
84
- inputs = places.select {|place| Perspective.file?(place)}
85
- inputs = inputs.map {|input| Perspective.normalize_data_name(input.name)}
95
+ input_places = places.select {|place| Perspective.file?(place)}
96
+ inputs = input_places.map {|input| Perspective.normalize_data_name(input.name)}
86
97
 
87
98
  case Perspective.normalize_data_name(transition.name)
88
99
  when "if"
@@ -157,7 +168,7 @@ module Pione
157
168
  :flow_elements => flow_elements,
158
169
  }
159
170
 
160
- RuleDefinition.new(name, option)
171
+ RuleDefinition.new(name, :flow, option)
161
172
  end
162
173
 
163
174
  def find_next_rules(base_rule)
@@ -103,6 +103,15 @@ module Pione
103
103
  return name.size > 0
104
104
  end
105
105
 
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
110
+
111
+ def self.action_rule?(node)
112
+ rule?(node) and not(flow_rule?(node))
113
+ end
114
+
106
115
  def self.normalize_data_name(name)
107
116
  return nil if name.nil?
108
117
 
@@ -193,10 +202,6 @@ module Pione
193
202
  indent("rule %s" % textize_rule_expr, option)
194
203
  end
195
204
 
196
- def as_rule_definition
197
- RuleDefinition.new()
198
- end
199
-
200
205
  private
201
206
 
202
207
  # Return a string form of PIONE's rule expression.
@@ -353,26 +358,42 @@ module Pione
353
358
 
354
359
  class RuleDefinition < Perspective
355
360
  attr_accessor :name
361
+ attr_accessor :type
356
362
  attr_accessor :inputs
357
363
  attr_accessor :outputs
358
364
  attr_accessor :params
359
365
  attr_accessor :conditions
360
366
  attr_accessor :flow_elements
367
+ attr_accessor :action_content
361
368
 
362
- def initialize(name, option={})
369
+ def initialize(name, type, option={})
363
370
  @name = name
371
+ @type = type
364
372
  @inputs = option[:inputs] || []
365
373
  @outputs = option[:outputs] || []
366
374
  @params = option[:params] || []
367
375
  @conditions = option[:conditions] || []
368
376
  @flow_elements = option[:flow_elements] || []
377
+ @action_content = nil
378
+ end
379
+
380
+ def flow?
381
+ @type == :flow
382
+ end
383
+
384
+ def action?
385
+ @type == :action
369
386
  end
370
387
 
371
388
  def textize
372
- if flow_elements.empty?
373
- template = Util::Indentation.cut(ACTION_RULE_TEMPLATE)
374
- else
389
+ if flow?
375
390
  template = Util::Indentation.cut(FLOW_RULE_TEMPLATE)
391
+ else
392
+ if @action_content
393
+ template = Util::Indentation.cut(LITERATE_ACTION_RULE_TEMPLATE)
394
+ else
395
+ template = Util::Indentation.cut(ACTION_RULE_TEMPLATE)
396
+ end
376
397
  end
377
398
  ERB.new(template, nil, "-").result(binding)
378
399
  end
@@ -412,6 +433,22 @@ module Pione
412
433
  <%- end -%>
413
434
  End
414
435
  RULE
436
+
437
+ 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 %>
447
+ <%- end -%>
448
+ Action
449
+ <%= Util::Indentation.indent(@action_content, 2) -%>
450
+ End
451
+ RULE
415
452
  end
416
453
  end
417
454
  end
@@ -14,6 +14,20 @@ module Pione
14
14
  n = line.length - line.lstrip.length
15
15
  n > 0 ? text.gsub(/^[ ]{0,#{n}}/m, "") : text
16
16
  end
17
+
18
+ # Add Indentation to the text.
19
+ #
20
+ # @param text [String]
21
+ # the text
22
+ # @param size [Integer]
23
+ # indentaion size
24
+ # @return [String]
25
+ # indented text
26
+ def self.indent(text, size)
27
+ text.lines.each_with_object("") do |line, indented|
28
+ indented << " " * size + line
29
+ end
30
+ end
17
31
  end
18
32
  end
19
33
  end
@@ -1,4 +1,4 @@
1
1
  module Pione
2
2
  # version of pione
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.2"
4
4
  end
@@ -11,5 +11,8 @@
11
11
  ],
12
12
  "Bins": [
13
13
 
14
+ ],
15
+ "Etcs": [
16
+
14
17
  ]
15
18
  }
@@ -12,5 +12,8 @@
12
12
  ],
13
13
  "Bins": [
14
14
 
15
+ ],
16
+ "Etcs": [
17
+
15
18
  ]
16
19
  }
@@ -12,5 +12,8 @@
12
12
  ],
13
13
  "Bins": [
14
14
 
15
+ ],
16
+ "Etcs": [
17
+
15
18
  ]
16
19
  }
@@ -13,5 +13,8 @@
13
13
  ],
14
14
  "Bins": [
15
15
 
16
+ ],
17
+ "Etcs": [
18
+
16
19
  ]
17
20
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pione
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Yamaguchi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-10 00:00:00.000000000 Z
11
+ date: 2014-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -477,8 +477,12 @@ files:
477
477
  - example/ActionError/pione-package.json
478
478
  - example/CTFCorrection/CTFCorrection.pione
479
479
  - example/CTFCorrection/package.yml
480
- - example/CountChar/CountChar.pione
480
+ - example/CountChar/CountChar.action.md
481
+ - example/CountChar/Main.pione
482
+ - example/CountChar/Main.pnml
483
+ - example/CountChar/flow.png
481
484
  - example/CountChar/misc/CountChar.rb
485
+ - example/CountChar/pione-package.json
482
486
  - example/CountChar/text/aidokushono_insho.txt
483
487
  - example/CountChar/text/aikokuka_shokan.txt
484
488
  - example/CountChar/text/carlyle_hakubutsukan.txt