pione 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +12 -1
- data/example/AbstractRule/AbstractRule.pione +40 -0
- data/example/Fib/Fib.pione +12 -5
- data/example/LucasNumber/LucasNumber.pione +1 -1
- data/example/MakePair/MakePair.pione +21 -6
- data/example/OddSelector/OddSelector.pione +17 -0
- data/example/OddSelector/data/1.i +0 -0
- data/example/OddSelector/data/10.i +0 -0
- data/example/OddSelector/data/2.i +0 -0
- data/example/OddSelector/data/3.i +0 -0
- data/example/OddSelector/data/4.i +0 -0
- data/example/OddSelector/data/5.i +0 -0
- data/example/OddSelector/data/6.i +0 -0
- data/example/OddSelector/data/7.i +0 -0
- data/example/OddSelector/data/8.i +0 -0
- data/example/OddSelector/data/9.i +0 -0
- data/example/SequentialParameter/SequentialParameter.pione +4 -0
- data/example/SieveOfEratosthenes/SieveOfEratosthenes.pione +31 -43
- data/example/SingleParticlesWithRef/SingleParticlesWithRef.pione +1 -1
- data/example/Touch/Touch.pione +3 -0
- data/lib/pione/command/pione-syntax-checker.rb +4 -4
- data/lib/pione/model/assignment.rb +6 -1
- data/lib/pione/model/basic-model.rb +92 -278
- data/lib/pione/model/binary-operator.rb +5 -1
- data/lib/pione/model/block.rb +17 -0
- data/lib/pione/model/boolean.rb +54 -22
- data/lib/pione/model/constraints.rb +34 -0
- data/lib/pione/model/data-expr.rb +184 -297
- data/lib/pione/model/feature-expr.rb +13 -4
- data/lib/pione/model/float.rb +24 -41
- data/lib/pione/model/integer.rb +75 -41
- data/lib/pione/model/keyed-sequence.rb +143 -0
- data/lib/pione/model/list.rb +12 -8
- data/lib/pione/model/message.rb +8 -4
- data/lib/pione/model/ordinal-sequence.rb +75 -0
- data/lib/pione/model/package.rb +6 -2
- data/lib/pione/model/parameters.rb +61 -9
- data/lib/pione/model/pione-method.rb +146 -0
- data/lib/pione/model/rule-expr.rb +44 -38
- data/lib/pione/model/rule-io.rb +11 -3
- data/lib/pione/model/rule.rb +105 -155
- data/lib/pione/model/sequence.rb +273 -0
- data/lib/pione/model/string.rb +75 -29
- data/lib/pione/model/ticket-expr.rb +17 -29
- data/lib/pione/model/type.rb +242 -0
- data/lib/pione/model/variable-table.rb +52 -53
- data/lib/pione/model/variable.rb +8 -4
- data/lib/pione/model.rb +34 -0
- data/lib/pione/parser/block-parser.rb +44 -20
- data/lib/pione/parser/common-parser.rb +2 -1
- data/lib/pione/parser/document-parser.rb +6 -1
- data/lib/pione/parser/expr-parser.rb +57 -11
- data/lib/pione/parser/flow-element-parser.rb +2 -2
- data/lib/pione/parser/rule-definition-parser.rb +23 -1
- data/lib/pione/patch/rinda-patch.rb +1 -5
- data/lib/pione/rule-handler/action-handler.rb +5 -5
- data/lib/pione/rule-handler/basic-handler.rb +30 -7
- data/lib/pione/rule-handler/empty-handler.rb +14 -0
- data/lib/pione/rule-handler/flow-handler.rb +132 -115
- data/lib/pione/rule-handler/root-handler.rb +6 -2
- data/lib/pione/rule-handler/update-criteria.rb +152 -0
- data/lib/pione/rule-handler.rb +14 -0
- data/lib/pione/system/identifier.rb +9 -9
- data/lib/pione/transformer/block-transformer.rb +4 -0
- data/lib/pione/transformer/expr-transformer.rb +1 -1
- data/lib/pione/transformer/flow-element-transformer.rb +4 -2
- data/lib/pione/transformer/literal-transformer.rb +14 -3
- data/lib/pione/transformer/rule-definition-transformer.rb +17 -5
- data/lib/pione/tuple-space/data-finder.rb +15 -52
- data/lib/pione/version.rb +1 -1
- data/lib/pione.rb +12 -38
- data/test/agent/spec_task-worker.rb +13 -12
- data/test/model/spec_assignment.rb +2 -2
- data/test/model/spec_binary-operator.rb +10 -10
- data/test/model/spec_block.rb +8 -8
- data/test/model/spec_boolean.rb +1 -72
- data/test/model/spec_boolean.yml +134 -0
- data/test/model/spec_data-expr.rb +50 -237
- data/test/model/spec_data-expr.yml +16 -45
- data/test/model/spec_data-expr_match.yml +45 -0
- data/test/model/spec_feature-expr.rb +2 -43
- data/test/model/spec_feature-expr.yml +0 -28
- data/test/model/spec_feature-expr_decide.yml +28 -0
- data/test/model/spec_float.rb +1 -119
- data/test/model/spec_float.yml +17 -0
- data/test/model/spec_integer.rb +1 -119
- data/test/model/spec_integer.yml +57 -0
- data/test/model/spec_keyed-sequence.rb +5 -0
- data/test/model/spec_keyed-sequence.yml +22 -0
- data/test/model/spec_message.rb +7 -7
- data/test/model/spec_parameters.rb +50 -63
- data/test/model/spec_pione-method.rb +56 -0
- data/test/model/spec_rule-expr.rb +18 -8
- data/test/model/spec_rule.rb +12 -12
- data/test/model/spec_sequence.rb +5 -0
- data/test/model/spec_sequence.yml +60 -0
- data/test/model/spec_string.rb +3 -70
- data/test/model/spec_string.yml +83 -0
- data/test/model/spec_ticket-expr.rb +4 -54
- data/test/model/spec_ticket-expr.yml +11 -0
- data/test/model/spec_variable-table.rb +41 -42
- data/test/model/spec_variable.rb +20 -22
- data/test/parser/spec_block-parser.yml +9 -0
- data/test/parser/spec_expr-parser.yml +0 -17
- data/test/parser/spec_flow-element-parser.yml +1 -1
- data/test/parser/spec_rule-definition-parser.yml +0 -4
- data/test/rule-handler/spec_update-criteria.pione +39 -0
- data/test/rule-handler/spec_update-criteria.rb +53 -0
- data/test/rule-handler/spec_update-criteria.yml +158 -0
- data/test/test-util.rb +25 -0
- data/test/transformer/spec_block-transformer.rb +7 -0
- data/test/transformer/spec_expr-transformer.rb +64 -19
- data/test/transformer/spec_flow-element-transformer.rb +11 -11
- data/test/transformer/spec_literal-transformer.rb +29 -29
- data/test/transformer/spec_rule-definition-transformer.rb +39 -21
- metadata +57 -11
- data/lib/pione/model/undefined-value.rb +0 -24
- data/lib/pione/tuple-space/update-criteria.rb +0 -97
- data/test/model/spec_list.rb +0 -26
- data/test/model/spec_rule-io.rb +0 -32
- data/test/spec_update-criteria.rb +0 -83
@@ -13,8 +13,8 @@ module Pione
|
|
13
13
|
# @api private
|
14
14
|
def message
|
15
15
|
args = [
|
16
|
-
@type.
|
17
|
-
@obj.pione_model_type.
|
16
|
+
@type.name,
|
17
|
+
@obj.pione_model_type.name,
|
18
18
|
@obj.line,
|
19
19
|
@obj.column
|
20
20
|
]
|
@@ -39,267 +39,95 @@ module Pione
|
|
39
39
|
|
40
40
|
# @api private
|
41
41
|
def message
|
42
|
-
|
43
|
-
begin
|
44
|
-
str = @obj.call_pione_method("as_string")
|
45
|
-
rescue => e
|
46
|
-
str = @obj.to_s
|
47
|
-
end
|
48
|
-
"method \"%s\" is not found in %s" % [@name, str]
|
42
|
+
"PIONE method \"%s\" is not found in %s" % [@name, @obj.inspect]
|
49
43
|
end
|
50
44
|
end
|
51
45
|
|
52
|
-
#
|
53
|
-
class
|
54
|
-
attr_reader :type_string
|
55
|
-
attr_reader :method_interface
|
56
|
-
attr_reader :method_body
|
57
|
-
|
58
|
-
# Creates a type for PIONE model object.
|
59
|
-
# @param [Symbol] type_string
|
60
|
-
# PIONE model type
|
61
|
-
def initialize(type_string)
|
62
|
-
@type_string = type_string
|
63
|
-
@method_interface = {}
|
64
|
-
@method_body = {}
|
65
|
-
end
|
66
|
-
|
67
|
-
# Return true if the type or the pione model object matches.
|
68
|
-
# @param [Type, BasicModel] other
|
69
|
-
# type or object for match test target
|
70
|
-
# @return [Boolean]
|
71
|
-
# true if it matches, or false
|
72
|
-
def match(other)
|
73
|
-
case other
|
74
|
-
when Type
|
75
|
-
other == TypeAny || @type_string == other.type_string
|
76
|
-
when BasicModel
|
77
|
-
match(other.pione_model_type)
|
78
|
-
when nil
|
79
|
-
# do nothing
|
80
|
-
else
|
81
|
-
raise ArgumentError.new(other)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Defines PIONE model object methods.
|
86
|
-
# @param [String] name
|
87
|
-
# method name
|
88
|
-
# @param [Array<Type>] inputs
|
89
|
-
# input types of the method
|
90
|
-
# @param [Type] output
|
91
|
-
# output type of the method
|
92
|
-
# @param [Proc] b
|
93
|
-
# @return [void]
|
94
|
-
def define_pione_method(name, inputs, output, &b)
|
95
|
-
raise ArgumentError.new(inputs) unless inputs.kind_of?(Array)
|
96
|
-
raise ArgumentError.new(inputs) unless inputs.all?{|input|
|
97
|
-
input.kind_of?(Type)
|
98
|
-
}
|
99
|
-
raise ArgumentError.new(output) unless output.kind_of?(Type)
|
100
|
-
@method_interface[name] = PioneMethodInterface.new(inputs, output)
|
101
|
-
@method_body[name] = b
|
102
|
-
end
|
103
|
-
|
104
|
-
# Returns true if the data has the type.
|
105
|
-
# @return [void]
|
106
|
-
def check(data)
|
107
|
-
unless match(data.pione_model_type)
|
108
|
-
raise PioneModelTypeError.new(data, self)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
# @api private
|
113
|
-
def to_s
|
114
|
-
"#<Type %s>" % @type_string
|
115
|
-
end
|
116
|
-
|
117
|
-
# @api private
|
118
|
-
def ==(other)
|
119
|
-
@type_string == other.type_string
|
120
|
-
end
|
121
|
-
|
122
|
-
# @api private
|
123
|
-
def hash
|
124
|
-
@type_string.hash
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
class VariableType
|
129
|
-
def initialize(name)
|
130
|
-
@name = name
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
# TypeList represetnts list type of element type.
|
135
|
-
class TypeList < Type
|
136
|
-
attr_reader :element_type
|
137
|
-
|
138
|
-
# @api private
|
139
|
-
@table = {}
|
140
|
-
|
46
|
+
# BasicModel is a class for pione model object.
|
47
|
+
class BasicModel < Pione::PioneObject
|
141
48
|
class << self
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
return t
|
149
|
-
end
|
49
|
+
# Return true if the object is atomic.
|
50
|
+
#
|
51
|
+
# @return [Boolean]
|
52
|
+
# true if the object is atom, or false.
|
53
|
+
def atomic?
|
54
|
+
@atomic ||= true
|
150
55
|
end
|
151
|
-
end
|
152
56
|
|
153
|
-
|
154
|
-
|
155
|
-
|
57
|
+
def set_atomic(b)
|
58
|
+
@atomic = b
|
59
|
+
end
|
156
60
|
end
|
157
61
|
|
158
|
-
|
159
|
-
return false unless other.kind_of?(TypeList)
|
160
|
-
@element_type.match(other.element_type)
|
161
|
-
end
|
62
|
+
forward :class, :atomic?
|
162
63
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
else
|
167
|
-
self.class[TypeAny].method_body
|
168
|
-
end
|
64
|
+
# Creates a model object.
|
65
|
+
def initialize(&b)
|
66
|
+
instance_eval(&b) if block_given?
|
169
67
|
end
|
170
68
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
69
|
+
# Evaluates the model object in the variable table.
|
70
|
+
# @param [VariableTable] vtable
|
71
|
+
# variable table for evaluation
|
72
|
+
# @return [BasicModel]
|
73
|
+
# evaluated object
|
74
|
+
def eval(vtable=VariableTable.new)
|
75
|
+
return self
|
177
76
|
end
|
178
|
-
end
|
179
77
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
# Creates an interface for a pione method.
|
186
|
-
# @param [Array<Type>] inputs
|
187
|
-
# inputs type definition
|
188
|
-
# @param [Type] output
|
189
|
-
# ouutput type definition
|
190
|
-
def initialize(inputs, output)
|
191
|
-
@inputs = inputs
|
192
|
-
@output = output
|
78
|
+
# Returns true if the object has pione variables.
|
79
|
+
# @return [Boolean]
|
80
|
+
# true if the object has pione variables, or false
|
81
|
+
def include_variable?
|
82
|
+
false
|
193
83
|
end
|
194
84
|
|
195
|
-
#
|
85
|
+
# Returns rule definition document path.
|
196
86
|
# @return [void]
|
197
|
-
def
|
198
|
-
@
|
199
|
-
unless input.match(args[i].pione_model_type)
|
200
|
-
raise PioneModelTypeError.new(args[i], input)
|
201
|
-
end
|
202
|
-
end
|
87
|
+
def set_document_path(path)
|
88
|
+
@__document_path__ = path
|
203
89
|
end
|
204
90
|
|
205
|
-
#
|
91
|
+
# Sets line and column number of the definition.
|
206
92
|
# @return [void]
|
207
|
-
def
|
208
|
-
@
|
93
|
+
def set_line_and_column(line_and_column)
|
94
|
+
@__line__, @__column__ = line_and_column
|
209
95
|
end
|
210
|
-
end
|
211
|
-
|
212
|
-
# boolean type for PIONE system
|
213
|
-
TypeBoolean = Type.new("boolean")
|
214
|
-
|
215
|
-
# integer type for PIONE system
|
216
|
-
TypeInteger = Type.new("integer")
|
217
|
-
|
218
|
-
# float type for PIONE system
|
219
|
-
TypeFloat = Type.new("float")
|
220
|
-
|
221
|
-
# string type for PIONE system
|
222
|
-
TypeString = Type.new("string")
|
223
|
-
|
224
|
-
# data expression type for PIONE system
|
225
|
-
TypeDataExpr = Type.new("data-expr")
|
226
|
-
|
227
|
-
# feature type for PIONE system
|
228
|
-
TypeFeature = Type.new("feature")
|
229
|
-
|
230
|
-
# rule expression type for PIONE system
|
231
|
-
TypeRuleExpr = Type.new("rule-expr")
|
232
|
-
|
233
|
-
# parameters type for PIONE system
|
234
|
-
TypeParameters = Type.new("parameters")
|
235
|
-
|
236
|
-
# assignment type for PIONE system
|
237
|
-
TypeAssignment = Type.new("assignment")
|
238
|
-
|
239
|
-
# variable table type for PIONE system
|
240
|
-
TypeVariableTable = Type.new("variable-table")
|
241
96
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
# rule io list type for PIONE system
|
249
|
-
TypeRuleIOList = Type.new("rule-io-list")
|
250
|
-
|
251
|
-
# rule io element type for PIONE system
|
252
|
-
TypeRuleIOElement = Type.new("rule-io-element")
|
253
|
-
|
254
|
-
# ticket expression type
|
255
|
-
TypeTicketExpr = Type.new("ticket-expr")
|
256
|
-
|
257
|
-
# any type for PIONE system
|
258
|
-
TypeAny = Type.new("any")
|
259
|
-
|
260
|
-
def TypeAny.match(other)
|
261
|
-
true
|
262
|
-
end
|
97
|
+
# Returns line number of the model in definition document.
|
98
|
+
# @return [Integer]
|
99
|
+
# line number
|
100
|
+
def line
|
101
|
+
@__line__
|
102
|
+
end
|
263
103
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
raise UnboundVariableError.new(res)
|
270
|
-
end
|
104
|
+
# Returns coloumn number of the model in definition document.
|
105
|
+
# @return [Integer]
|
106
|
+
# column number
|
107
|
+
def column
|
108
|
+
@__column__
|
271
109
|
end
|
272
110
|
|
273
|
-
|
274
|
-
|
111
|
+
# Returns itself.
|
112
|
+
# @return [BasicModel]
|
113
|
+
def to_pione
|
114
|
+
self
|
275
115
|
end
|
276
116
|
end
|
277
117
|
|
278
|
-
|
279
|
-
class BasicModel < Pione::PioneObject
|
118
|
+
class Callable < BasicModel
|
280
119
|
class << self
|
281
|
-
|
282
|
-
|
120
|
+
attr_reader :pione_model_type
|
121
|
+
|
122
|
+
# Set pione model type of the model.
|
123
|
+
#
|
124
|
+
# @param [Type] type
|
283
125
|
# pione model type
|
284
126
|
# @return [void]
|
285
127
|
def set_pione_model_type(type)
|
286
|
-
raise ArgumentError unless type.kind_of?(Type)
|
287
128
|
@pione_model_type = type
|
288
129
|
end
|
289
130
|
|
290
|
-
# Returns the pione model type of the model.
|
291
|
-
# @return [Symbol]
|
292
|
-
# pione model type
|
293
|
-
def pione_model_type
|
294
|
-
@pione_model_type
|
295
|
-
end
|
296
|
-
|
297
|
-
# Defines a pione method.
|
298
|
-
# @return [void]
|
299
|
-
def define_pione_method(*args, &b)
|
300
|
-
@pione_model_type.define_pione_method(*args, &b)
|
301
|
-
end
|
302
|
-
|
303
131
|
# @api private
|
304
132
|
def inherited(subclass)
|
305
133
|
if @pione_model_type
|
@@ -308,34 +136,23 @@ module Pione
|
|
308
136
|
end
|
309
137
|
end
|
310
138
|
|
139
|
+
forward :class, :pione_model_type
|
140
|
+
|
311
141
|
# Creates a model object.
|
312
142
|
def initialize(&b)
|
313
143
|
instance_eval(&b) if block_given?
|
314
144
|
end
|
315
145
|
|
316
|
-
#
|
317
|
-
#
|
318
|
-
# PIONE model type
|
319
|
-
def pione_model_type
|
320
|
-
self.class.pione_model_type
|
321
|
-
end
|
322
|
-
|
323
|
-
# Evaluates the model object in the variable table.
|
146
|
+
# Evaluate the model object in the variable table.
|
147
|
+
#
|
324
148
|
# @param [VariableTable] vtable
|
325
149
|
# variable table for evaluation
|
326
150
|
# @return [BasicModel]
|
327
|
-
# evaluated
|
151
|
+
# evaluated result
|
328
152
|
def eval(vtable=VariableTable.new)
|
329
153
|
return self
|
330
154
|
end
|
331
155
|
|
332
|
-
# Returns true if the object is atomic.
|
333
|
-
# @return [Boolean]
|
334
|
-
# true if the object is atom, or false.
|
335
|
-
def atomic?
|
336
|
-
true
|
337
|
-
end
|
338
|
-
|
339
156
|
# Returns true if the object has pione variables.
|
340
157
|
# @return [Boolean]
|
341
158
|
# true if the object has pione variables, or false
|
@@ -343,33 +160,8 @@ module Pione
|
|
343
160
|
false
|
344
161
|
end
|
345
162
|
|
346
|
-
#
|
347
|
-
#
|
348
|
-
def set_document_path(path)
|
349
|
-
@__document_path__ = path
|
350
|
-
end
|
351
|
-
|
352
|
-
# Sets line and column number of the definition.
|
353
|
-
# @return [void]
|
354
|
-
def set_line_and_column(line_and_column)
|
355
|
-
@__line__, @__column__ = line_and_column
|
356
|
-
end
|
357
|
-
|
358
|
-
# Returns line number of the model in definition document.
|
359
|
-
# @return [Integer]
|
360
|
-
# line number
|
361
|
-
def line
|
362
|
-
@__line__
|
363
|
-
end
|
364
|
-
|
365
|
-
# Returns coloumn number of the model in definition document.
|
366
|
-
# @return [Integer]
|
367
|
-
# column number
|
368
|
-
def column
|
369
|
-
@__column__
|
370
|
-
end
|
371
|
-
|
372
|
-
# Calls pione model object method.
|
163
|
+
# Call pione model object method.
|
164
|
+
#
|
373
165
|
# @param [String] name
|
374
166
|
# method name
|
375
167
|
# @param [Array] args
|
@@ -377,12 +169,8 @@ module Pione
|
|
377
169
|
# @return [Object]
|
378
170
|
# method's result
|
379
171
|
def call_pione_method(name, *args)
|
380
|
-
|
381
|
-
|
382
|
-
method.validate_inputs(*args)
|
383
|
-
output = pione_model_type.method_body[name].call(self, *args)
|
384
|
-
pione_model_type.method_interface[name].validate_output(output)
|
385
|
-
return output
|
172
|
+
if pione_method = pione_model_type.find_method(name, self, *args)
|
173
|
+
pione_method.call(self, *args)
|
386
174
|
else
|
387
175
|
raise MethodNotFound.new(name, self)
|
388
176
|
end
|
@@ -394,5 +182,31 @@ module Pione
|
|
394
182
|
self
|
395
183
|
end
|
396
184
|
end
|
185
|
+
|
186
|
+
class Element < BasicModel
|
187
|
+
class << self
|
188
|
+
attr_reader :sequence_class
|
189
|
+
|
190
|
+
def set_sequence_class(sequence_class)
|
191
|
+
@sequence_class = sequence_class
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
forward :class, :sequence_class
|
196
|
+
|
197
|
+
def to_seq
|
198
|
+
sequence_class.new([self])
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
class Value < Element
|
203
|
+
attr_reader :value
|
204
|
+
|
205
|
+
# @param value [Integer]
|
206
|
+
# value in ruby
|
207
|
+
def initialize(value)
|
208
|
+
@value = value
|
209
|
+
end
|
210
|
+
end
|
397
211
|
end
|
398
212
|
end
|
@@ -46,7 +46,11 @@ module Pione
|
|
46
46
|
|
47
47
|
# @api private
|
48
48
|
def pione_model_type
|
49
|
-
@left.pione_model_type.
|
49
|
+
if pione_method = @left.pione_model_type.find_method(@symbol, @left, @right)
|
50
|
+
return pione_method.get_output_type(@left)
|
51
|
+
else
|
52
|
+
raise MethodNotFound.new(@name.to_s, self)
|
53
|
+
end
|
50
54
|
end
|
51
55
|
|
52
56
|
# Evaluate the application expression and returns application result.
|
data/lib/pione/model/block.rb
CHANGED
@@ -241,5 +241,22 @@ module Pione
|
|
241
241
|
@condition.hash + @blocks.hash
|
242
242
|
end
|
243
243
|
end
|
244
|
+
|
245
|
+
# EmptyBlock is no elements block.
|
246
|
+
class EmptyBlock < BasicModel
|
247
|
+
include Singleton
|
248
|
+
|
249
|
+
def eval(vtable)
|
250
|
+
return self
|
251
|
+
end
|
252
|
+
|
253
|
+
def include_variable?
|
254
|
+
false
|
255
|
+
end
|
256
|
+
|
257
|
+
def textize
|
258
|
+
"empty_block()"
|
259
|
+
end
|
260
|
+
end
|
244
261
|
end
|
245
262
|
end
|
data/lib/pione/model/boolean.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
module Pione
|
2
2
|
module Model
|
3
3
|
# PioneBoolean representes truth value in PIONE system.
|
4
|
-
class PioneBoolean <
|
5
|
-
set_pione_model_type TypeBoolean
|
6
|
-
|
4
|
+
class PioneBoolean < Value
|
7
5
|
# Returns the value in ruby.
|
8
6
|
attr_reader :value
|
9
7
|
|
@@ -58,8 +56,8 @@ module Pione
|
|
58
56
|
# @param value [Boolean]
|
59
57
|
# true or false
|
60
58
|
def initialize(value)
|
59
|
+
raise ArgumentError.new(value) unless value == true or value == false
|
61
60
|
@value = value
|
62
|
-
super()
|
63
61
|
end
|
64
62
|
|
65
63
|
# @api private
|
@@ -96,6 +94,10 @@ module Pione
|
|
96
94
|
return @value
|
97
95
|
end
|
98
96
|
|
97
|
+
def to_seq
|
98
|
+
BooleanSequence.new([self])
|
99
|
+
end
|
100
|
+
|
99
101
|
# @api private
|
100
102
|
def ==(other)
|
101
103
|
return false unless other.kind_of?(self.class)
|
@@ -109,40 +111,70 @@ module Pione
|
|
109
111
|
@value.hash
|
110
112
|
end
|
111
113
|
|
112
|
-
|
113
|
-
|
114
|
-
#
|
115
|
-
|
116
|
-
define_pione_method("==", [TypeBoolean], TypeBoolean) do |rec, other|
|
117
|
-
PioneBoolean.new(rec.value == other.value)
|
114
|
+
def inspect
|
115
|
+
"#<PioneBoolean %s>" % @value
|
118
116
|
end
|
117
|
+
end
|
119
118
|
|
120
|
-
|
121
|
-
|
122
|
-
|
119
|
+
class BooleanSequence < OrdinalSequence
|
120
|
+
set_pione_model_type TypeBoolean
|
121
|
+
set_element_class PioneBoolean
|
122
|
+
set_shortname "BSeq"
|
123
123
|
|
124
|
-
|
125
|
-
|
124
|
+
def value
|
125
|
+
@value ||= @elements.inject(true){|b, elt| b and elt.value}
|
126
126
|
end
|
127
|
+
end
|
127
128
|
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
#
|
130
|
+
# pione methods
|
131
|
+
#
|
131
132
|
|
133
|
+
TypeBoolean.instance_eval do
|
132
134
|
define_pione_method("and", [TypeBoolean], TypeBoolean) do |rec, other|
|
133
|
-
|
135
|
+
sequential_map2(TypeBoolean, rec, other) do |rec_elt, other_elt|
|
136
|
+
rec_elt.value && other_elt.value
|
137
|
+
end
|
134
138
|
end
|
135
139
|
|
136
140
|
define_pione_method("or", [TypeBoolean], TypeBoolean) do |rec, other|
|
137
|
-
|
141
|
+
sequential_map2(TypeBoolean, rec, other) do |rec_elt, other_elt|
|
142
|
+
rec_elt.value || other_elt.value
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
define_pione_method("as_integer", [], TypeInteger) do |rec|
|
147
|
+
sequential_map1(TypeInteger, rec) {|rec| rec.value ? 1 : 0}
|
148
|
+
end
|
149
|
+
|
150
|
+
define_pione_method("as_float", [], TypeFloat) do |rec|
|
151
|
+
sequential_map1(TypeFloat, rec) {|rec| rec.value ? 1.0 : 0.0}
|
138
152
|
end
|
139
153
|
|
140
154
|
define_pione_method("as_string", [], TypeString) do |rec|
|
141
|
-
|
155
|
+
sequential_map1(TypeString, rec) {|rec| rec.value.to_s}
|
156
|
+
end
|
157
|
+
|
158
|
+
define_pione_method("as_data_expr", [], TypeDataExpr) do |rec|
|
159
|
+
sequential_map1(TypeDataExpr, rec) {|rec| rec.value.to_s}
|
142
160
|
end
|
143
161
|
|
144
162
|
define_pione_method("not", [], TypeBoolean) do |rec|
|
145
|
-
|
163
|
+
sequential_map1(TypeBoolean, rec) do |elt|
|
164
|
+
not(elt.value)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
define_pione_method("every?", [], TypeBoolean) do |rec|
|
169
|
+
PioneBoolean.new(not(rec.elements.include?(PioneBoolean.false))).to_seq
|
170
|
+
end
|
171
|
+
|
172
|
+
define_pione_method("any?", [], TypeBoolean) do |rec|
|
173
|
+
PioneBoolean.new(rec.elements.include?(PioneBoolean.true)).to_seq
|
174
|
+
end
|
175
|
+
|
176
|
+
define_pione_method("one?", [], TypeBoolean) do |rec|
|
177
|
+
PioneBoolean.new(rec.elements.select{|elt| elt == PioneBoolean.true}.size == 1).to_seq
|
146
178
|
end
|
147
179
|
end
|
148
180
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Pione
|
2
|
+
module Model
|
3
|
+
class Constraints
|
4
|
+
class << self
|
5
|
+
# Return the empty constraints.
|
6
|
+
#
|
7
|
+
# @return [Constraints]
|
8
|
+
# empty constraints
|
9
|
+
def empty
|
10
|
+
new([])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param exprs [Array<BasicModel>]
|
15
|
+
# constraint expressions
|
16
|
+
def initialize(exprs)
|
17
|
+
@exprs = exprs
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return true if constraints satisfied.
|
21
|
+
#
|
22
|
+
# @param vtable [VariableTable]
|
23
|
+
# variable table
|
24
|
+
# @return [Boolean]
|
25
|
+
# true if constraints satisfied
|
26
|
+
def satisfy?(vtable)
|
27
|
+
@exprs.all? do |expr|
|
28
|
+
res = expr.eval(vtable)
|
29
|
+
res.kind_of?(BooleanSequence) and res.value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|