pione 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/History.txt +9 -2
  2. data/Rakefile +1 -1
  3. data/example/Fib/Fib.pione +5 -5
  4. data/example/SequentialProcess/SequentialProcess.pione +69 -0
  5. data/lib/pione.rb +7 -11
  6. data/lib/pione/agent/input-generator.rb +3 -2
  7. data/lib/pione/agent/task-worker.rb +6 -3
  8. data/lib/pione/agent/trivial-routine-worker.rb +6 -5
  9. data/lib/pione/command/basic-command.rb +7 -1
  10. data/lib/pione/command/child-process.rb +5 -1
  11. data/lib/pione/command/front-owner-command.rb +15 -4
  12. data/lib/pione/command/pione-client.rb +16 -9
  13. data/lib/pione/command/pione-syntax-checker.rb +45 -30
  14. data/lib/pione/command/pione-task-worker.rb +22 -13
  15. data/lib/pione/command/pione-tuple-space-provider.rb +4 -2
  16. data/lib/pione/command/pione-tuple-space-receiver.rb +10 -5
  17. data/lib/pione/front/task-worker-owner.rb +1 -0
  18. data/lib/pione/model/basic-model.rb +3 -0
  19. data/lib/pione/model/block.rb +2 -1
  20. data/lib/pione/model/call-rule.rb +10 -0
  21. data/lib/pione/model/feature-expr.rb +143 -54
  22. data/lib/pione/model/float.rb +0 -1
  23. data/lib/pione/model/rule-expr.rb +132 -7
  24. data/lib/pione/model/rule.rb +53 -17
  25. data/lib/pione/model/ticket-expr.rb +124 -0
  26. data/lib/pione/parser/expr-parser.rb +75 -38
  27. data/lib/pione/parser/literal-parser.rb +14 -0
  28. data/lib/pione/parser/parslet-extension.rb +143 -0
  29. data/lib/pione/rule-handler/flow-handler.rb +33 -3
  30. data/lib/pione/system/global.rb +10 -3
  31. data/lib/pione/transformer.rb +24 -0
  32. data/lib/pione/transformer/block-transformer.rb +6 -5
  33. data/lib/pione/transformer/document-transformer.rb +5 -10
  34. data/lib/pione/transformer/expr-transformer.rb +56 -30
  35. data/lib/pione/transformer/feature-expr-transformer.rb +9 -5
  36. data/lib/pione/transformer/flow-element-transformer.rb +21 -23
  37. data/lib/pione/transformer/literal-transformer.rb +39 -35
  38. data/lib/pione/transformer/rule-definition-transformer.rb +8 -6
  39. data/lib/pione/transformer/transformer-module.rb +7 -5
  40. data/lib/pione/tuple/ticket-tuple.rb +8 -0
  41. data/lib/pione/util/{message.rb → console-message.rb} +54 -26
  42. data/lib/pione/version.rb +1 -1
  43. data/pione.gemspec +2 -1
  44. data/test/model/spec_feature-expr.rb +18 -3
  45. data/test/model/spec_feature-expr.yml +28 -16
  46. data/test/model/spec_ticket-expr.rb +67 -0
  47. data/test/parser/spec_expr-parser.yml +74 -25
  48. data/test/parser/spec_literal-parser.yml +11 -0
  49. data/test/test-util.rb +1 -1
  50. data/test/transformer/spec_expr-transformer.rb +27 -54
  51. data/test/transformer/spec_literal-transformer.rb +6 -0
  52. metadata +29 -7
  53. data/lib/pione/parser/syntax-error.rb +0 -61
data/History.txt CHANGED
@@ -1,6 +1,13 @@
1
1
  # History
2
2
 
3
- ## 0.1.1
3
+ ## 0.1.2(2013/04/01)
4
+
5
+ * Added shorthand notation for setting parameters
6
+ * Added ticket concept for sequential processing
7
+ * Improved termination sequence
8
+ * Refactored parser and transformer
9
+
10
+ ## 0.1.1(2013/03/20)
4
11
 
5
12
  * Improved performance
6
13
  * Added the concept of document parameter
@@ -8,6 +15,6 @@
8
15
  * Fixed bugs of features handling
9
16
  * Improved comment parser
10
17
 
11
- ## 0.1.0
18
+ ## 0.1.0(2013/02/19)
12
19
 
13
20
  * First gem release
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  desc 'Show undocumented function list'
11
11
  task 'html:undoc' do
12
- sh 'bundle exec yard stats --list-undoc --no-api --private'
12
+ sh 'bundle exec yard stats --list-undoc --no-api --private --compact'
13
13
  end
14
14
 
15
15
  desc 'count characters in input direcotry'
@@ -3,8 +3,8 @@ param $NUM := 3
3
3
  Rule Main
4
4
  output 'result.txt'
5
5
  Flow
6
- rule Fib.params({N: $NUM})
7
- rule Result.params({N: $NUM})
6
+ rule Fib {N: $NUM}
7
+ rule Result {N: $NUM}
8
8
  End
9
9
 
10
10
  Rule Fib0
@@ -31,9 +31,9 @@ Flow
31
31
  else
32
32
  $P1 := $N - 2
33
33
  $P2 := $N - 1
34
- rule Fib.params({N: $P1})
35
- rule Fib.params({N: $P2})
36
- rule Calc.params({N: $N, P1: $P1, P2: $P2})
34
+ rule Fib {N: $P1}
35
+ rule Fib {N: $P2}
36
+ rule Calc {N: $N, P1: $P1, P2: $P2}
37
37
  end
38
38
  End
39
39
 
@@ -0,0 +1,69 @@
1
+ Rule Main
2
+ output '*.a'.all
3
+ output '*.b'.all
4
+ Flow
5
+ rule A ==> <T>
6
+ rule <T> ==> B
7
+ End
8
+
9
+ Rule A
10
+ output '*.a'.all
11
+ Flow
12
+ rule <T> ==> A4
13
+ rule A1 >>> A2 >>> A3 ==> <T>
14
+ End
15
+
16
+ Rule A1
17
+ output '1.a'
18
+ Action
19
+ echo "A1" > {$O[1]}
20
+ End
21
+
22
+ Rule A2
23
+ output '2.a'
24
+ Action
25
+ echo "A2" > {$O[1]}
26
+ End
27
+
28
+ Rule A3
29
+ output '3.a'
30
+ Action
31
+ echo "A3" > {$O[1]}
32
+ End
33
+
34
+ Rule A4
35
+ output '4.a'
36
+ Action
37
+ echo "A4" > {$O[1]}
38
+ End
39
+
40
+ Rule B
41
+ output '*.b'.all
42
+ Flow
43
+ rule <T> ==> B4
44
+ rule B1 >>> B2 >>> B3 ==> <T>
45
+ End
46
+
47
+ Rule B1
48
+ output '1.b'
49
+ Action
50
+ echo "B1" > {$O[1]}
51
+ End
52
+
53
+ Rule B2
54
+ output '2.b'
55
+ Action
56
+ echo "B2" > {$O[1]}
57
+ End
58
+
59
+ Rule B3
60
+ output '3.b'
61
+ Action
62
+ echo "B3" > {$O[1]}
63
+ End
64
+
65
+ Rule B4
66
+ output '4.b'
67
+ Action
68
+ echo "B4" > {$O[1]}
69
+ End
data/lib/pione.rb CHANGED
@@ -29,6 +29,7 @@ require 'ostruct'
29
29
  require 'net/ftp'
30
30
  require 'highline'
31
31
  require 'dropbox_sdk'
32
+ require 'hamster'
32
33
  require 'naming'
33
34
 
34
35
  #
@@ -41,7 +42,7 @@ require 'pione/version'
41
42
  # util
42
43
  require 'pione/util/misc'
43
44
  require 'pione/util/terminal'
44
- require 'pione/util/message'
45
+ require 'pione/util/console-message'
45
46
  require 'pione/util/log'
46
47
  require 'pione/util/waiter-table'
47
48
  require 'pione/util/error-report'
@@ -94,6 +95,7 @@ require 'pione/model/variable-table'
94
95
  require 'pione/model/data-expr'
95
96
  require 'pione/model/parameters'
96
97
  require 'pione/model/package'
98
+ require 'pione/model/ticket-expr'
97
99
  require 'pione/model/rule-expr'
98
100
  require 'pione/model/binary-operator'
99
101
  require 'pione/model/message'
@@ -123,6 +125,7 @@ require 'pione/tuple/exception-tuple'
123
125
  require 'pione/tuple/log-tuple'
124
126
  require 'pione/tuple/rule-tuple'
125
127
  require 'pione/tuple/task-worker-resource-tuple'
128
+ require 'pione/tuple/ticket-tuple'
126
129
 
127
130
  # tuple-space
128
131
  require 'pione/tuple-space/tuple-space-server-interface'
@@ -134,7 +137,7 @@ require 'pione/tuple-space/data-finder'
134
137
  require 'pione/tuple-space/update-criteria'
135
138
 
136
139
  # parser
137
- require 'pione/parser/syntax-error'
140
+ require 'pione/parser/parslet-extension'
138
141
  require 'pione/parser/common-parser'
139
142
  require 'pione/parser/literal-parser'
140
143
  require 'pione/parser/feature-expr-parser'
@@ -145,14 +148,7 @@ require 'pione/parser/rule-definition-parser'
145
148
  require 'pione/parser/document-parser'
146
149
 
147
150
  # transformer
148
- require 'pione/transformer/transformer-module'
149
- require 'pione/transformer/literal-transformer'
150
- require 'pione/transformer/feature-expr-transformer'
151
- require 'pione/transformer/expr-transformer'
152
- require 'pione/transformer/flow-element-transformer'
153
- require 'pione/transformer/block-transformer'
154
- require 'pione/transformer/rule-definition-transformer'
155
- require 'pione/transformer/document-transformer'
151
+ require 'pione/transformer'
156
152
 
157
153
  # resource
158
154
  require 'pione/resource/basic-resource'
@@ -227,7 +223,7 @@ module Pione
227
223
  include System
228
224
  include Relay
229
225
  include Util
230
- include Util::Message
226
+ include Util::ConsoleMessage
231
227
  include Model
232
228
  include TupleSpace
233
229
  include Parser
@@ -73,9 +73,10 @@ module Pione
73
73
  end
74
74
  end
75
75
 
76
- # Initializes the generator. This method is called when root rule is
76
+ # Initialize the generator. This method is called when root rule is
77
77
  # requested in stream mode.
78
- # @retrun [void]
78
+ #
79
+ # @return [void]
79
80
  def init
80
81
  if @dir_path
81
82
  @gen = Resource[@dir_path].entries.to_enum
@@ -213,18 +213,21 @@ module Pione
213
213
 
214
214
  debug_message_end "End Task Execution #{rule.rule_path} by worker(#{uuid})"
215
215
 
216
- return task, handler, @__result_task_execution__
216
+ return task, rule, handler, @__result_task_execution__
217
217
  end
218
218
 
219
219
  # State data_outputing.
220
- # @param [Task] task
220
+ # @param task [Task]
221
221
  # task tuple
222
+ # @param rule [Rule]
223
+ # rule model
222
224
  # @param [RuleHandler] handler
223
225
  # rule handler
224
226
  # @param [Array<Data>] result
225
227
  # result data tuples
226
228
  # @return [Array<Task,RuleHandler>]
227
- def transit_to_data_outputing(task, handler, result)
229
+ def transit_to_data_outputing(task, rule, handler, result)
230
+ # output data
228
231
  result.flatten.each do |output|
229
232
  begin
230
233
  write(output)
@@ -9,17 +9,18 @@ module Pione
9
9
  define_state_transition :initialized => :working
10
10
  define_state_transition :working => :working
11
11
 
12
- # Creates a worker.
13
- # @param [Proc] action
12
+ # Create a trivial routine worker.
13
+ #
14
+ # @param action [Proc]
14
15
  # worker's action as proc object
15
- # @param [Integer] sec
16
- # sleeping time
17
16
  def initialize(action)
18
17
  raise ArgumentError.new(action) unless action.kind_of?(Proc)
19
18
  @action = action
20
19
  end
21
20
 
22
- # Calls the action.
21
+ # Call the action.
22
+ #
23
+ # @return [void]
23
24
  def transit_to_working
24
25
  @action.call
25
26
  end
@@ -123,8 +123,14 @@ module Pione
123
123
  raise NotImplementedError
124
124
  end
125
125
 
126
+ # Terminate the command. Exit from PIONE system.
127
+ #
128
+ # @return [void]
126
129
  def terminate
127
- exit
130
+ Global.monitor.synchronize do
131
+ # exit with no exception
132
+ exit!
133
+ end
128
134
  end
129
135
  end
130
136
  end
@@ -33,10 +33,14 @@ module Pione
33
33
  @watchdog.start
34
34
  end
35
35
 
36
+ # Terminate the child front. Kill watchdog.
37
+ #
38
+ # @return [void]
36
39
  def terminate
40
+ # kill watchdog
37
41
  @watchdog.terminate
42
+ # go to other termination processes
38
43
  super
39
- abort
40
44
  end
41
45
  end
42
46
  end
@@ -6,6 +6,8 @@ module Pione
6
6
  end
7
7
 
8
8
  # Runs the command.
9
+ #
10
+ # @return [void]
9
11
  def run
10
12
  parse_options
11
13
  validate_options
@@ -15,22 +17,31 @@ module Pione
15
17
  start
16
18
  end
17
19
 
18
- # Setups font server.
20
+ # Setup font server.
21
+ #
19
22
  # @return [void]
20
23
  def setup_front
21
24
  Global.front = create_front
22
25
  end
23
26
 
24
- # Creates a front server. This method should be overridden in subclasses.
27
+ # Create a front server. This method should be overridden in subclasses.
28
+ #
25
29
  # @return [BasicFront]
26
30
  # front server
27
31
  def create_front
28
32
  raise NotImplementedError
29
33
  end
30
34
 
35
+ # Terminate PIONE front. Stop DRb service.
36
+ #
37
+ # @return [void]
31
38
  def terminate
32
- super
33
- DRb.stop_service
39
+ Global.monitor.synchronize do
40
+ # stop DRb service
41
+ DRb.stop_service
42
+ # go to other termination processes
43
+ super
44
+ end
34
45
  end
35
46
  end
36
47
  end
@@ -203,19 +203,26 @@ module Pione
203
203
  terminate
204
204
  end
205
205
 
206
+ # Terminate pione-client command. Kill tuple space provider.
207
+ #
208
+ # @return [void]
206
209
  def terminate
207
- # kill the thread for starting tuple space provider
208
- if @start_tuple_space_provider_thread
209
- if @start_tuple_space_provider_thread.alive?
210
- @start_tuple_space_provider_thread.kill
210
+ Global.monitor.synchronize do
211
+ # kill the thread for starting tuple space provider
212
+ if @start_tuple_space_provider_thread
213
+ if @start_tuple_space_provider_thread.alive?
214
+ @start_tuple_space_provider_thread.kill
215
+ end
211
216
  end
212
- end
213
217
 
214
- # terminate tuple space provider
215
- if @tuple_space_provider
216
- @tuple_space_provider.terminate
218
+ # terminate tuple space provider
219
+ if @tuple_space_provider
220
+ @tuple_space_provider.terminate
221
+ end
222
+
223
+ # go to other termination processes.
224
+ super
217
225
  end
218
- super
219
226
  end
220
227
 
221
228
  private
@@ -16,6 +16,11 @@ TXT
16
16
  @transform = true
17
17
  end
18
18
 
19
+ define_option('-f', '--file=PATH', 'check syntax of the document') do |path|
20
+ @document = path
21
+ @readline_mode = false
22
+ end
23
+
19
24
  def initialize
20
25
  @readline_mode = true
21
26
  end
@@ -28,53 +33,63 @@ TXT
28
33
 
29
34
  def start
30
35
  if @readline_mode
31
- require 'readline'
32
- restore_history
33
- buf = ""
34
- mark = ">"
36
+ start_readline_mode
37
+ else
38
+ if @document
39
+ print_result(Pathname.new(@document).read)
40
+ else
41
+ # print parsing result
42
+ print_result(@expr)
43
+ end
44
+ end
45
+ end
35
46
 
36
- # start loop
37
- while buf += Readline.readline(Terminal.red("#{mark} "), true)
38
- if /[^\s]/.match(buf)
39
- # don't record if previous line is the same
40
- if Readline::HISTORY.size > 1 && Readline::HISTORY[-2] == buf
41
- Readline::HISTORY.pop
42
- end
43
- if buf[-1] == "\\"
44
- buf[-1] = "\n"
45
- mark = "+"
46
- next
47
- else
48
- # print parsing result
49
- puts buf
50
- print_result(buf)
51
- buf = ""
52
- mark = ">"
53
- end
54
- else
55
- # don't record if it is an empty line
47
+ private
48
+
49
+ def start_readline_mode
50
+ require 'readline'
51
+ restore_history
52
+ buf = ""
53
+ mark = ">"
54
+
55
+ # start loop
56
+ while buf += Readline.readline(Terminal.red("#{mark} "), true)
57
+ if /[^\s]/.match(buf)
58
+ # don't record if previous line is the same
59
+ if Readline::HISTORY.size > 1 && Readline::HISTORY[-2] == buf
56
60
  Readline::HISTORY.pop
57
61
  end
62
+ if buf[-1] == "\\"
63
+ buf[-1] = "\n"
64
+ mark = "+"
65
+ next
66
+ else
67
+ # print parsing result
68
+ puts buf
69
+ print_result(buf)
70
+ buf = ""
71
+ mark = ">"
72
+ end
73
+ else
74
+ # don't record if it is an empty line
75
+ Readline::HISTORY.pop
58
76
  end
59
- else
60
77
  # print parsing result
61
- print_result(@expr)
78
+ print_result(buf)
62
79
  end
63
80
  end
64
81
 
65
- private
66
-
67
82
  # Prints parsing result of the string
68
83
  def print_result(str)
69
84
  begin
70
85
  puts Terminal.green("syntax:")
71
- stree = DocumentParser.new.parse(str).first
86
+ stree = DocumentParser.new.parse(str)
72
87
  pp stree
73
88
  if @transform
74
89
  puts Terminal.green("model:")
75
90
  pp DocumentTransformer.new.apply(stree)
76
91
  end
77
- rescue Pione::Parser::ParserError, Parslet::UnconsumedInput, Parslet::ParseFailed => e
92
+ rescue Pione::Parser::ParserError, Parslet::ParseFailed => e
78
93
  msg = "Pione syntax error: %s (%s)" % [e.message, e.class.name]
79
94
  @readline_mode ? puts(msg) : abort(msg)
80
95
  rescue Pione::Model::PioneModelTypeError,