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
@@ -16,7 +16,6 @@ module Pione::Model
16
16
  # @api private
17
17
  def textize
18
18
  "#PioneFloat{%s}" % @value
19
- # @value.to_s
20
19
  end
21
20
 
22
21
  # Returns ruby's value.
@@ -6,15 +6,27 @@ module Pione::Model
6
6
  attr_reader :package
7
7
  attr_reader :name
8
8
  attr_reader :params
9
+ attr_reader :input_ticket_expr
10
+ attr_reader :output_ticket_expr
9
11
 
10
12
  # Create a rule expression.
11
- # @param [String] package pione package name
12
- # @param [String] name rule name
13
- # @param [Parameters] params parameters
14
- def initialize(package, name, params=Parameters.empty)
13
+ #
14
+ # @param package [String]
15
+ # package name
16
+ # @param name [String]
17
+ # rule name
18
+ # @param params [Parameters]
19
+ # parameters
20
+ # @param input_ticket_expr [TicketExpr]
21
+ # input ticket condition
22
+ # @param output_ticket_expr [TicketExpr]
23
+ # output ticket condition
24
+ def initialize(package, name, params, input_ticket_expr, output_ticket_expr)
15
25
  @package = package
16
26
  @name = name
17
27
  @params = params
28
+ @input_ticket_expr = input_ticket_expr
29
+ @output_ticket_expr = output_ticket_expr
18
30
  super()
19
31
  end
20
32
 
@@ -41,6 +53,28 @@ module Pione::Model
41
53
  "rule_expr(%s,\"%s\")" % [@package.textize, @name]
42
54
  end
43
55
 
56
+ # Create a new rule expression with adding the ticket expression as input
57
+ # condition.
58
+ #
59
+ # @param ticket_expr [TicketExpr]
60
+ # ticket expression as additional input condition
61
+ # @return [RuleExpr]
62
+ # new rule expression
63
+ def add_input_ticket_expr(ticket_expr)
64
+ return self.class.new(@package, @name, @params, @input_ticket_expr + ticket_expr, @output_ticket_expr)
65
+ end
66
+
67
+ # Create a new rule expression with adding the ticket expression as output
68
+ # condition.
69
+ #
70
+ # @param ticket_expr [TicketExpr]
71
+ # ticket expression as additional output condition
72
+ # @return [RuleExpr]
73
+ # new rule expression
74
+ def add_output_ticket_expr(ticket_expr)
75
+ return self.class.new(@package, @name, @params, @input_ticket_expr, @output_ticket_expr + ticket_expr)
76
+ end
77
+
44
78
  # Sets a package name and returns a new expression.
45
79
  # @param [String] package
46
80
  # package name
@@ -56,7 +90,7 @@ module Pione::Model
56
90
  # @return [RuleExpr]
57
91
  # new rule expression with the parameters
58
92
  def set_params(params)
59
- return self.class.new(@package, @name, params)
93
+ return self.class.new(@package, @name, params, @input_ticket_expr, @output_ticket_expr)
60
94
  end
61
95
 
62
96
  # Evaluates the object with the variable table.
@@ -68,7 +102,9 @@ module Pione::Model
68
102
  return self.class.new(
69
103
  @package.eval(vtable),
70
104
  @name,
71
- @params.eval(vtable)
105
+ @params.eval(vtable),
106
+ @input_ticket_expr.eval(vtable),
107
+ @output_ticket_expr.eval(vtable)
72
108
  )
73
109
  end
74
110
 
@@ -76,7 +112,11 @@ module Pione::Model
76
112
  # @return [Boolean]
77
113
  # true if the package or parameters include variables
78
114
  def include_variable?
79
- @package.include_variable? or @params.include_variable?
115
+ [ @package.include_variable?,
116
+ @params.include_variable?,
117
+ @input_ticket_expr.include_variable?,
118
+ @output_ticket_expr.include_variable?
119
+ ].any?
80
120
  end
81
121
 
82
122
  # @api private
@@ -95,6 +135,80 @@ module Pione::Model
95
135
  def hash
96
136
  @package.hash + @name.hash + @params.hash
97
137
  end
138
+
139
+ # Return a set that contains self as a single element.
140
+ #
141
+ # @return [Set<RuleExpr>]
142
+ # a set that contains self
143
+ def to_set
144
+ Set.new([self])
145
+ end
146
+ end
147
+
148
+ class CompositionalRuleExpr < RuleExpr
149
+ # Create a new compositional rule expression. This consists from left and
150
+ # right child expressions.
151
+ #
152
+ # @param left [RuleExpr]
153
+ # left expression
154
+ # @param right [RuleExpr]
155
+ # right expression
156
+ def initialize(left, right)
157
+ @left = left
158
+ @right = right
159
+ end
160
+
161
+ # Create a new compositioanl rule expression with adding the ticket
162
+ # expression as input condition of left expression.
163
+ #
164
+ # @param ticket_expr [TicketExpr]
165
+ # ticket expression as additional input condition
166
+ # @return [CompositionalRuleExpr]
167
+ # new rule expression
168
+ def add_input_ticket_expr(ticket_expr)
169
+ return self.class.new(@left.add_input_ticket_expr(ticket_expr), @right)
170
+ end
171
+
172
+ # Create a new compositional rule expression with adding the ticket
173
+ # expression as output condition of right expression.
174
+ #
175
+ # @param ticket_expr [TicketExpr]
176
+ # ticket expression as additional output condition
177
+ # @return [CompositionalRuleExpr]
178
+ # new rule expression
179
+ def add_output_ticket_expr(ticket_expr)
180
+ return self.class.new(@left, @right.add_output_ticket_expr(ticket_expr))
181
+ end
182
+
183
+ # Evaluates left and right expressions with the variable table.
184
+ #
185
+ # @param [VariableTable] vtable
186
+ # variable table for evaluation
187
+ # @return [CompositionalRuleExpr]
188
+ # evaluation result
189
+ def eval(vtable)
190
+ return self.class.new(@left.eval(vtable), @right.eval(vtable))
191
+ end
192
+
193
+ # @api private
194
+ def ==(other)
195
+ return false unless other.kind_of?(self.class)
196
+ return to_set == other.to_set
197
+ end
198
+ alias :eql? :"=="
199
+
200
+ # @api private
201
+ def hash
202
+ @left.hash + @right.hash
203
+ end
204
+
205
+ # Return a set that contains all rule expressions of left and right.
206
+ #
207
+ # @return [Set<RuleExpr>]
208
+ # a set that contains all rule expressions of left and right
209
+ def to_set
210
+ @left.to_set + @right.to_set
211
+ end
98
212
  end
99
213
 
100
214
  TypeRuleExpr.instance_eval do
@@ -116,5 +230,16 @@ module Pione::Model
116
230
  define_pione_method("as_string", [], TypeString) do |rec|
117
231
  PioneString.new(rec.name)
118
232
  end
233
+
234
+ define_pione_method("==>", [TypeTicketExpr], TypeRuleExpr) do |rec, ticket_expr|
235
+ rec.add_output_ticket_expr(ticket_expr)
236
+ end
237
+
238
+ define_pione_method(">>>", [TypeRuleExpr], TypeRuleExpr) do |rec, other|
239
+ ticket_expr = TicketExpr.new([rec.path])
240
+ left = rec.add_output_ticket_expr(ticket_expr)
241
+ right = other.add_input_ticket_expr(ticket_expr)
242
+ CompositionalRuleExpr.new(left, right)
243
+ end
119
244
  end
120
245
  end
@@ -1,53 +1,79 @@
1
1
  module Pione::Model
2
2
  # RuleCondition represents rule condition.
3
3
  class RuleCondition < BasicModel
4
- # Returns the value of attribute inputs.
4
+ # the value of attribute inputs
5
+ #
5
6
  # @return [Array<DataExpr, Array<DataExpr>>]
6
7
  # rule inputs condition
7
8
  attr_reader :inputs
8
9
 
9
- # Returns the value of attribute outputs.
10
+ # the value of attribute outputs
11
+ #
10
12
  # @return [Array<DataExpr, Array<DataExpr>>]
11
- # rule outputs condition
13
+ # rule outputs condition
12
14
  attr_reader :outputs
13
15
 
14
- # Returns the value of attribute params.
16
+ # the value of attribute params
17
+ #
15
18
  # @return [Parameters]
16
19
  # rule parameters table
17
20
  attr_reader :params
18
21
 
19
- # Returns the value of attribute features.
22
+ # the value of attribute features
23
+ #
20
24
  # @return [Feature]
21
25
  # rule feature condition
22
26
  attr_reader :features
23
27
 
24
- # Creates a rule condition.
25
- # @param [Array<DataExpr, Array<DataExpr>>] inputs
28
+ # input ticket expression
29
+ #
30
+ # @return [TicketExpr]
31
+ # input ticket expression
32
+ attr_reader :input_ticket_expr
33
+
34
+ # output ticket expression
35
+ #
36
+ # @return [TicketExpr]
37
+ # output ticket
38
+ attr_reader :output_ticket_expr
39
+
40
+ # Create a rule condition.
41
+ #
42
+ # @param inputs [Array<DataExpr, Array<DataExpr>>]
26
43
  # rule inputs
27
- # @param [Array<DataExpr, Array<DataExpr>>] outputs
44
+ # @param outputs [Array<DataExpr, Array<DataExpr>>]
28
45
  # rule outputs
29
- # @param [Parameters] params
46
+ # @param params [Parameters]
30
47
  # rule parameters
31
- # @param [Feature] features
48
+ # @param features [Feature]
32
49
  # rule features
33
- def initialize(inputs, outputs, params, features)
50
+ # @param input_ticket_expr [TicketExpr]
51
+ # input ticket expression
52
+ # @param output_ticket_expr [TicketExpr]
53
+ # output ticket expression
54
+ def initialize(inputs, outputs, params, features, input_ticket_expr, output_ticket_expr)
34
55
  check_argument_type(params, Parameters)
35
56
  check_argument_type(features, Feature::Expr)
36
57
  @inputs = inputs
37
58
  @outputs = outputs
38
59
  @params = params
39
60
  @features = features
61
+ @input_ticket_expr = input_ticket_expr
62
+ @output_ticket_expr = output_ticket_expr
40
63
  super()
41
64
  end
42
65
 
43
- # Returns true if the condition includes variable.
66
+ # Return true if the condition includes variable.
67
+ #
44
68
  # @return [Boolean]
45
69
  # true if the condition includes variable, or false
46
70
  def include_variable?
47
71
  [ @inputs.any? {|input| input.include_variable?},
48
72
  @outputs.any? {|output| output.include_variable?},
49
73
  @params.include_variable?,
50
- @features.include_variable?
74
+ @features.include_variable?,
75
+ @input_tickets.any? {|ticket| ticket.include_variable?},
76
+ @output_tickets.any? {|ticket| ticket.include_variable?}
51
77
  ].any?
52
78
  end
53
79
 
@@ -60,6 +86,7 @@ module Pione::Model
60
86
  return true
61
87
  end
62
88
 
89
+ # @api private
63
90
  alias :eql? :"=="
64
91
 
65
92
  # @api private
@@ -86,6 +113,7 @@ module Pione::Model
86
113
  attr_reader :body
87
114
 
88
115
  def_delegators :@condition, :inputs, :outputs, :params, :features
116
+ def_delegators :@condition, :input_ticket_expr, :output_ticket_expr
89
117
 
90
118
  # Creates a rule.
91
119
  # @param [RuleExpr] expr
@@ -211,7 +239,7 @@ module Pione::Model
211
239
  @params = params
212
240
  condition = make_condition
213
241
  super(
214
- RuleExpr.new(Package.new("root"), "Root"),
242
+ RuleExpr.new(Package.new("root"), "Root", Parameters.empty, TicketExpr.empty, TicketExpr.empty),
215
243
  condition,
216
244
  FlowBlock.new(CallRule.new(@main.expr.set_params(@params)))
217
245
  )
@@ -244,7 +272,9 @@ module Pione::Model
244
272
  @main.inputs,
245
273
  @main.outputs,
246
274
  Parameters.empty,
247
- Feature.empty
275
+ Feature.empty,
276
+ TicketExpr.empty,
277
+ TicketExpr.empty
248
278
  )
249
279
  end
250
280
 
@@ -263,7 +293,13 @@ module Pione::Model
263
293
  # @param [Proc] b
264
294
  # rule process
265
295
  def initialize(name, &b)
266
- expr = RuleExpr.new(Package.new('system'), name)
296
+ expr = RuleExpr.new(
297
+ Package.new('system'),
298
+ name,
299
+ Parameters.empty,
300
+ TicketExpr.empty,
301
+ TicketExpr.empty
302
+ )
267
303
  condition = make_condition
268
304
  super(expr, condition, b)
269
305
  end
@@ -273,7 +309,7 @@ module Pione::Model
273
309
  # @api private
274
310
  def make_condition
275
311
  inputs = [DataExpr.new('*')]
276
- RuleCondition.new(inputs, [], Parameters.empty, Feature::EmptyFeature.new)
312
+ RuleCondition.new(inputs, [], Parameters.empty, Feature::EmptyFeature.new, TicketExpr.empty, TicketExpr.empty)
277
313
  end
278
314
 
279
315
  # @api private
@@ -0,0 +1,124 @@
1
+ module Pione
2
+ module Model
3
+ # TicketExpr is a ticket expression as alternative input or output
4
+ # conditions of rules for sequential process. An object of this class
5
+ # represents a set of ticket conditions.
6
+ #
7
+ # @example Sequencial process of rule A and B by tickets in PIONE flow rule
8
+ # Rule Main
9
+ # input '*.in'
10
+ # output '*.out'
11
+ # Flow
12
+ # rule A ==> <T>
13
+ # <T> ==> rule B
14
+ # End
15
+ # @example TicketExpr represents a set
16
+ # TicketExpr.new("T1") + TicketExpr.new("T2") #=> TicketExpr.new(["T1", "T2"])
17
+ class TicketExpr < BasicModel
18
+ set_pione_model_type TypeTicketExpr
19
+
20
+ class << self
21
+ # Return an emtpy ticket expression. Empty ticket expression has no
22
+ # ticket conditions.
23
+ def empty
24
+ self.new(Set.new)
25
+ end
26
+ end
27
+
28
+ # ticket names
29
+ attr_reader :names
30
+
31
+ # Create a ticket expression with names.
32
+ #
33
+ # @param names [Set, Array]
34
+ # ticket names
35
+ #
36
+ # @example
37
+ # TicketExpr.new(["T1", "T2"])
38
+ # @example
39
+ # TicketExpr.new(Set.new(["T1", "T2"]))
40
+ def initialize(names)
41
+ @names = Set.new(names)
42
+ super()
43
+ end
44
+
45
+ # Return true if the ticket expression is empty.
46
+ def empty?
47
+ @names.empty?
48
+ end
49
+
50
+ # Evaluate the object with the variable table.
51
+ #
52
+ # @param vtable [VariableTable]
53
+ # variable table for evaluation
54
+ # @return [BasicModel]
55
+ # evaluation result
56
+ def eval(vtable)
57
+ self
58
+ end
59
+
60
+ # Return true if the value includes variables.
61
+ #
62
+ # @return [Boolean]
63
+ # true if the value includes variables
64
+ def include_variable?
65
+ false
66
+ end
67
+
68
+ # Composite ticket expressions between this and another.
69
+ #
70
+ # @param other [TicketExpr]
71
+ # another ticket expression
72
+ # @return [TicketExpr]
73
+ # compositional ticket expression
74
+ def +(other)
75
+ raise ArgumentError.new(other) unless other.kind_of?(TicketExpr)
76
+ self == other ? self : TicketExpr.new(@names + other.names)
77
+ end
78
+
79
+ # @api private
80
+ def task_id_string
81
+ "TicketExpr<#{@names}>"
82
+ end
83
+
84
+ # @api private
85
+ def textize
86
+ "<%s>" % [@names]
87
+ end
88
+
89
+ # @api private
90
+ def ==(other)
91
+ return false unless other.kind_of?(self.class)
92
+ @names == other.names
93
+ end
94
+ alias :eql? :"=="
95
+
96
+ # @api private
97
+ def hash
98
+ @names.hash
99
+ end
100
+ end
101
+
102
+ TypeTicketExpr.instance_eval do
103
+ define_pione_method("==", [TypeTicketExpr], TypeBoolean) do |rec, other|
104
+ PioneBoolean.new(rec.names == other.names)
105
+ end
106
+
107
+ define_pione_method("!=", [TypeTicketExpr], TypeBoolean) do |rec, other|
108
+ PioneBoolean.not(rec.call_pione_method("==", other))
109
+ end
110
+
111
+ define_pione_method("==>", [TypeRuleExpr], TypeRuleExpr) do |rec, other|
112
+ other.add_input_ticket_expr(rec)
113
+ end
114
+
115
+ define_pione_method("+", [TypeTicketExpr], TypeTicketExpr) do |rec, other|
116
+ rec + other
117
+ end
118
+
119
+ define_pione_method("as_string", [], TypeString) do |rec|
120
+ rec.textize
121
+ end
122
+ end
123
+ end
124
+ end