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
@@ -52,7 +52,7 @@ module Pione::Model
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# Expr is a super class for all feature expressions.
|
55
|
-
class Expr <
|
55
|
+
class Expr < Callable
|
56
56
|
set_pione_model_type TypeFeature
|
57
57
|
|
58
58
|
# Return simplified expression.
|
@@ -865,19 +865,28 @@ module Pione::Model
|
|
865
865
|
end
|
866
866
|
end
|
867
867
|
end
|
868
|
+
|
869
|
+
# class FeatureSequence < Sequence
|
870
|
+
# set_pione_model_type TypeFeature
|
871
|
+
# set_element_class Feature::Expr
|
872
|
+
# end
|
868
873
|
end
|
869
874
|
|
870
875
|
TypeFeature.instance_eval do
|
871
876
|
define_pione_method("==", [TypeFeature], TypeBoolean) do |rec, other|
|
872
|
-
PioneBoolean.new(rec == other)
|
877
|
+
PioneBoolean.new(rec == other).to_seq
|
873
878
|
end
|
874
879
|
|
875
880
|
define_pione_method("!=", [TypeFeature], TypeBoolean) do |rec, other|
|
876
|
-
PioneBoolean.not(rec.call_pione_method("==", other))
|
881
|
+
PioneBoolean.not(rec.call_pione_method("==", other)).to_seq
|
877
882
|
end
|
878
883
|
|
879
884
|
define_pione_method("as_string", [], TypeString) do |rec|
|
880
|
-
PioneString.new(rec.as_string)
|
885
|
+
PioneString.new(rec.as_string).to_seq
|
886
|
+
end
|
887
|
+
|
888
|
+
define_pione_method("str", [], TypeString) do |rec|
|
889
|
+
rec.call_pione_method("as_string")
|
881
890
|
end
|
882
891
|
end
|
883
892
|
end
|
data/lib/pione/model/float.rb
CHANGED
@@ -1,20 +1,7 @@
|
|
1
1
|
module Pione
|
2
2
|
module Model
|
3
3
|
# PioneFloat represents float values in PIONE system.
|
4
|
-
class PioneFloat <
|
5
|
-
set_pione_model_type TypeFloat
|
6
|
-
|
7
|
-
attr_reader :value
|
8
|
-
|
9
|
-
# Create a float value in PIONE system.
|
10
|
-
#
|
11
|
-
# @param value [Float]
|
12
|
-
# value in ruby
|
13
|
-
def initialize(value)
|
14
|
-
@value = value
|
15
|
-
super()
|
16
|
-
end
|
17
|
-
|
4
|
+
class PioneFloat < Value
|
18
5
|
# @api private
|
19
6
|
def textize
|
20
7
|
"#PioneFloat{%s}" % @value
|
@@ -42,43 +29,35 @@ module Pione
|
|
42
29
|
end
|
43
30
|
end
|
44
31
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# true if the other equals self
|
50
|
-
define_pione_method("==", [TypeFloat], TypeBoolean) do |rec, other|
|
51
|
-
PioneBoolean.new(rec.value == other.value)
|
52
|
-
end
|
32
|
+
class FloatSequence < OrdinalSequence
|
33
|
+
set_pione_model_type TypeFloat
|
34
|
+
set_element_class PioneFloat
|
35
|
+
set_shortname "FSeq"
|
53
36
|
|
54
|
-
|
55
|
-
|
37
|
+
def value
|
38
|
+
@value ||= @elements.inject(0.0){|n, elt| n + elt.value}
|
56
39
|
end
|
40
|
+
end
|
57
41
|
|
42
|
+
TypeFloat.instance_eval do
|
58
43
|
define_pione_method(">", [TypeFloat], TypeBoolean) do |rec, other|
|
59
|
-
PioneBoolean.new(rec.value > other.value)
|
60
|
-
end
|
61
|
-
|
62
|
-
define_pione_method(">=", [TypeFloat], TypeBoolean) do |rec, other|
|
63
|
-
PioneBoolean.or(rec.call_pione_method(">", other),
|
64
|
-
rec.call_pione_method("==", other))
|
44
|
+
BooleanSequence.new([PioneBoolean.new(rec.value > other.value)])
|
65
45
|
end
|
66
46
|
|
67
47
|
define_pione_method("<", [TypeFloat], TypeBoolean) do |rec, other|
|
68
|
-
PioneBoolean.new(rec.value < other.value)
|
69
|
-
end
|
70
|
-
|
71
|
-
define_pione_method("<=", [TypeFloat], TypeBoolean) do |rec, other|
|
72
|
-
PioneBoolean.or(rec.call_pione_method("<", other),
|
73
|
-
rec.call_pione_method("==", other))
|
48
|
+
BooleanSequence.new([PioneBoolean.new(rec.value < other.value)])
|
74
49
|
end
|
75
50
|
|
76
51
|
define_pione_method("+", [TypeFloat], TypeFloat) do |rec, other|
|
77
|
-
|
52
|
+
map2(rec, other) do |rec_elt, other_elt|
|
53
|
+
PioneFloat.new(rec_elt.value + other_elt.value)
|
54
|
+
end
|
78
55
|
end
|
79
56
|
|
80
57
|
define_pione_method("-", [TypeFloat], TypeFloat) do |rec, other|
|
81
|
-
|
58
|
+
map2(rec, other) do |rec_elt, other_elt|
|
59
|
+
PioneFloat.new(rec_elt.value - other_elt.value)
|
60
|
+
end
|
82
61
|
end
|
83
62
|
|
84
63
|
define_pione_method("*", [TypeFloat], TypeFloat) do |rec, other|
|
@@ -96,11 +75,15 @@ module Pione
|
|
96
75
|
end
|
97
76
|
|
98
77
|
define_pione_method("as_string", [], TypeString) do |rec|
|
99
|
-
|
78
|
+
sequential_map1(TypeString, rec) do |elt|
|
79
|
+
elt.value.to_s
|
80
|
+
end
|
100
81
|
end
|
101
82
|
|
102
|
-
define_pione_method("
|
103
|
-
|
83
|
+
define_pione_method("as_integer", [], TypeInteger) do |rec|
|
84
|
+
sequential_map1(TypeInteger, rec) do |elt|
|
85
|
+
elt.value.to_i
|
86
|
+
end
|
104
87
|
end
|
105
88
|
|
106
89
|
define_pione_method("as_float", [], TypeFloat) do |rec|
|
data/lib/pione/model/integer.rb
CHANGED
@@ -1,20 +1,7 @@
|
|
1
1
|
module Pione
|
2
2
|
module Model
|
3
3
|
# PioneInteger represents integer value in PIONE system.
|
4
|
-
class PioneInteger <
|
5
|
-
set_pione_model_type TypeInteger
|
6
|
-
|
7
|
-
attr_reader :value
|
8
|
-
|
9
|
-
# Create a integer value in PIONE system.
|
10
|
-
#
|
11
|
-
# @param value [Integer]
|
12
|
-
# value in ruby
|
13
|
-
def initialize(value)
|
14
|
-
@value = value
|
15
|
-
super()
|
16
|
-
end
|
17
|
-
|
4
|
+
class PioneInteger < Value
|
18
5
|
# @api private
|
19
6
|
def task_id_string
|
20
7
|
"Integer<#{@value}>"
|
@@ -33,6 +20,10 @@ module Pione
|
|
33
20
|
return @value
|
34
21
|
end
|
35
22
|
|
23
|
+
def to_seq
|
24
|
+
IntegerSequence.new([self])
|
25
|
+
end
|
26
|
+
|
36
27
|
# @api private
|
37
28
|
def ==(other)
|
38
29
|
return false unless other.kind_of?(self.class)
|
@@ -48,88 +39,131 @@ module Pione
|
|
48
39
|
|
49
40
|
# @api private
|
50
41
|
def inspect
|
51
|
-
"#<
|
42
|
+
"#<PioneInteger %s>" % @value
|
52
43
|
end
|
53
44
|
|
54
45
|
# @api private
|
55
46
|
alias :to_s :inspect
|
56
47
|
end
|
57
48
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
define_pione_method("!=", [TypeInteger], TypeBoolean) do |rec, other|
|
64
|
-
PioneBoolean.not(rec.call_pione_method("==", other))
|
65
|
-
end
|
49
|
+
class IntegerSequence < OrdinalSequence
|
50
|
+
set_pione_model_type TypeInteger
|
51
|
+
set_element_class PioneInteger
|
52
|
+
set_shortname "ISeq"
|
53
|
+
end
|
66
54
|
|
55
|
+
TypeInteger.instance_eval do
|
67
56
|
define_pione_method(">", [TypeInteger], TypeBoolean) do |rec, other|
|
68
|
-
|
57
|
+
sequential_map2(TypeBoolean, rec, other) do |rec_elt, other_elt|
|
58
|
+
rec_elt.value > other_elt.value
|
59
|
+
end
|
69
60
|
end
|
70
61
|
|
71
62
|
define_pione_method(">=", [TypeInteger], TypeBoolean) do |rec, other|
|
72
|
-
|
73
|
-
rec.call_pione_method("==", other))
|
63
|
+
BooleanSequence.new(
|
64
|
+
[PioneBoolean.new(rec.call_pione_method(">", other).value || rec.call_pione_method("==", other).value)]
|
65
|
+
)
|
74
66
|
end
|
75
67
|
|
76
68
|
define_pione_method("<", [TypeInteger], TypeBoolean) do |rec, other|
|
77
|
-
|
69
|
+
sequential_map2(TypeBoolean, rec, other) do |rec_elt, other_elt|
|
70
|
+
rec_elt.value < other_elt.value
|
71
|
+
end
|
78
72
|
end
|
79
73
|
|
80
74
|
define_pione_method("<=", [TypeInteger], TypeBoolean) do |rec, other|
|
81
|
-
|
82
|
-
|
75
|
+
BooleanSequence.new(
|
76
|
+
[PioneBoolean.new(
|
77
|
+
rec.call_pione_method("<", other).value ||
|
78
|
+
rec.call_pione_method("==", other).value
|
79
|
+
)]
|
80
|
+
)
|
83
81
|
end
|
84
82
|
|
85
83
|
define_pione_method("+", [TypeInteger], TypeInteger) do |rec, other|
|
86
|
-
|
84
|
+
sequential_map2(TypeInteger, rec, other) do |rec_elt, other_elt|
|
85
|
+
rec_elt.value + other_elt.value
|
86
|
+
end
|
87
87
|
end
|
88
88
|
|
89
89
|
define_pione_method("-", [TypeInteger], TypeInteger) do |rec, other|
|
90
|
-
|
90
|
+
sequential_map2(TypeInteger, rec, other) do |rec_elt, other_elt|
|
91
|
+
rec_elt.value - other_elt.value
|
92
|
+
end
|
91
93
|
end
|
92
94
|
|
93
95
|
define_pione_method("*", [TypeInteger], TypeInteger) do |rec, other|
|
94
|
-
|
96
|
+
sequential_map2(TypeInteger, rec, other) do |rec_elt, other_elt|
|
97
|
+
rec_elt.value * other_elt.value
|
98
|
+
end
|
95
99
|
end
|
96
100
|
|
97
101
|
define_pione_method("%", [TypeInteger], TypeInteger) do |rec, other|
|
98
102
|
# TODO: zero division error
|
99
|
-
|
103
|
+
sequential_map2(TypeInteger, rec, other) do |rec_elt, other_elt|
|
104
|
+
rec_elt.value % other_elt.value
|
105
|
+
end
|
100
106
|
end
|
101
107
|
|
102
108
|
define_pione_method("/", [TypeInteger], TypeInteger) do |rec, other|
|
103
109
|
# TODO: zero division error
|
104
|
-
|
110
|
+
sequential_map2(TypeInteger, rec, other) do |rec_elt, other_elt|
|
111
|
+
rec_elt.value / other_elt.value
|
112
|
+
end
|
105
113
|
end
|
106
114
|
|
107
115
|
define_pione_method("as_string", [], TypeString) do |rec|
|
108
|
-
|
116
|
+
sequential_map1(TypeString, rec) {|elt| elt.value.to_s}
|
109
117
|
end
|
110
118
|
|
111
|
-
define_pione_method("
|
119
|
+
define_pione_method("as_integer", [], TypeInteger) do |rec|
|
112
120
|
rec
|
113
121
|
end
|
114
122
|
|
115
123
|
define_pione_method("as_float", [], TypeFloat) do |rec|
|
116
|
-
|
124
|
+
sequential_map1(TypeFloat, rec) {|elt| elt.value.to_f}
|
117
125
|
end
|
118
126
|
|
119
127
|
define_pione_method("next", [], TypeInteger) do |rec|
|
120
|
-
|
128
|
+
sequential_map1(TypeInteger, rec) {|elt| elt.value.next}
|
121
129
|
end
|
122
130
|
|
123
131
|
define_pione_method("prev", [], TypeInteger) do |rec|
|
124
|
-
|
132
|
+
sequential_map1(TypeInteger, rec) {|elt| elt.value.pred}
|
125
133
|
end
|
126
134
|
|
127
135
|
define_pione_method("even?", [], TypeBoolean) do |rec|
|
128
|
-
|
136
|
+
sequential_pred1(rec) {|elt| elt.value.even?}
|
129
137
|
end
|
130
138
|
|
131
139
|
define_pione_method("odd?", [], TypeBoolean) do |rec|
|
132
|
-
|
140
|
+
sequential_pred1(rec) {|elt| elt.value.odd?}
|
141
|
+
end
|
142
|
+
|
143
|
+
# upto : *integer -> *integer
|
144
|
+
define_pione_method("upto", [TypeInteger], TypeInteger) do |rec, max|
|
145
|
+
sequential_fold2(TypeInteger, rec, max) do |seq, rec_elt, max_elt|
|
146
|
+
if rec_elt.value < max_elt.value
|
147
|
+
rec_elt.value.upto(max_elt.value).inject(seq) do |_seq, i|
|
148
|
+
_seq.push(PioneInteger.new(i))
|
149
|
+
end
|
150
|
+
else
|
151
|
+
seq.push(rec_elt)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# downto : *integer -> *integer
|
157
|
+
define_pione_method("downto", [TypeInteger], TypeInteger) do |rec, min|
|
158
|
+
sequential_fold2(TypeInteger, rec, min) do |seq, rec_elt, min_elt|
|
159
|
+
if rec_elt.value > min_elt.value
|
160
|
+
rec_elt.value.downto(min_elt.value).inject(seq) do |_seq, i|
|
161
|
+
_seq.push(PioneInteger.new(i))
|
162
|
+
end
|
163
|
+
else
|
164
|
+
seq.push(rec_elt)
|
165
|
+
end
|
166
|
+
end
|
133
167
|
end
|
134
168
|
end
|
135
169
|
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
module Pione
|
2
|
+
module Model
|
3
|
+
# KeyedSequence is a sequence that have key and value pairs.
|
4
|
+
class KeyedSequence < Sequence
|
5
|
+
set_pione_model_type TypeKeyedSequence
|
6
|
+
set_shortname "KeyedSeq"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def empty(attributes={})
|
10
|
+
new({}, attributes)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param elements [Hash{Element => Sequence}]
|
15
|
+
# sequence elements
|
16
|
+
# @param attribute [Hash]
|
17
|
+
# sequence attribute
|
18
|
+
def initialize(elements, attribute={})
|
19
|
+
raise ArgumentError.new(elements) unless elements.kind_of?(Hash)
|
20
|
+
@elements = elements
|
21
|
+
@attribute = Hash.new.merge(attribute)
|
22
|
+
|
23
|
+
# fill default value
|
24
|
+
sequence_attribute.each do |name, values|
|
25
|
+
@attribute[name] ||= values.first
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def index_type
|
30
|
+
ordinal_sequence_of_element(@elements.keys.first).pione_model_type
|
31
|
+
end
|
32
|
+
|
33
|
+
def element_type
|
34
|
+
ordinal_sequence_of_element(@elements.values.flatten.first).pione_model_type
|
35
|
+
end
|
36
|
+
|
37
|
+
def ordinal_sequence_of_element(elt)
|
38
|
+
case elt
|
39
|
+
when PioneInteger
|
40
|
+
IntegerSequence
|
41
|
+
when PioneString
|
42
|
+
StringSequence
|
43
|
+
when PioneFloat
|
44
|
+
FloatSequence
|
45
|
+
when PioneBoolean
|
46
|
+
BooleanSequence
|
47
|
+
when DataExpr
|
48
|
+
DataExprSequence
|
49
|
+
else
|
50
|
+
raise ArgumentError.new(elt)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Concatenate another sequence.
|
55
|
+
#
|
56
|
+
# @param other [Sequence]
|
57
|
+
# other sequence
|
58
|
+
# @return [Sequence]
|
59
|
+
# a new sequence that have members of self and other
|
60
|
+
def concat(other)
|
61
|
+
raise SequenceAttributeError.new(other) unless @attribute == other.attribute
|
62
|
+
new_elements = (@elements.to_a + other.elements.to_a).inject({}) do |elts, list|
|
63
|
+
key, vals = list
|
64
|
+
elts[key] = (elts[key] ||= []) + vals
|
65
|
+
elts
|
66
|
+
end
|
67
|
+
self.class.new(new_elements, @attribute)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Get the element by the key.
|
71
|
+
#
|
72
|
+
# @param key [Element]
|
73
|
+
# index key
|
74
|
+
# @return [BasicModel]
|
75
|
+
# element
|
76
|
+
def get(key)
|
77
|
+
@elements[key] || []
|
78
|
+
end
|
79
|
+
|
80
|
+
# Put the element to the sequecence.
|
81
|
+
#
|
82
|
+
# @param key [Element]
|
83
|
+
# the key
|
84
|
+
# @param element [Element]
|
85
|
+
# the element
|
86
|
+
# @return [Sequence]
|
87
|
+
# a new sequence that have member self and the element.
|
88
|
+
def put(key, element)
|
89
|
+
raise ArgumentError.new(element) unless element.kind_of?(Element)
|
90
|
+
self.class.new(@elements.merge({key => get(key) + [element]}), @attribute)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Iterate each elements.
|
94
|
+
#
|
95
|
+
# @return [Enumerator]
|
96
|
+
# return an enumerator if the block is not given
|
97
|
+
def each
|
98
|
+
if block_given?
|
99
|
+
@elements.each {|key, val| yield self.class.new({key => val}, @attribute)}
|
100
|
+
else
|
101
|
+
Enumerator.new(self, :each)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def eval(vtable)
|
106
|
+
new_elements = @elements.inject({}) do |elts, key, val|
|
107
|
+
elts[key.eval(vtable)] = val.eval(vtable)
|
108
|
+
end
|
109
|
+
self.class.new(new_elements, @attribute)
|
110
|
+
end
|
111
|
+
|
112
|
+
def include_variable?
|
113
|
+
@elements.any?{|key, value| key.include_variable? or val.include_variable?}
|
114
|
+
end
|
115
|
+
|
116
|
+
def textize
|
117
|
+
inspect
|
118
|
+
end
|
119
|
+
|
120
|
+
def inspect
|
121
|
+
"#<%s [%s] %s>" % [shortname, @elements.map{|key, vals| "%s:(%s)" % [key.textize, vals.map{|val| val.textize}.join("|")]}.join(","), @attribute]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
TypeKeyedSequence.instance_eval do
|
126
|
+
define_pione_method("keys", [], :index_type) do |rec|
|
127
|
+
keys = rec.elements.keys
|
128
|
+
rec.ordinal_sequence_of_element(keys.first).new(keys)
|
129
|
+
end
|
130
|
+
|
131
|
+
define_pione_method("values", [], :element_type) do |rec|
|
132
|
+
vals = rec.elements.values.flatten
|
133
|
+
rec.ordinal_sequence_of_element(vals.first).new(vals)
|
134
|
+
end
|
135
|
+
|
136
|
+
define_pione_method("[]", [:index_type], :element_type) do |rec, index|
|
137
|
+
index.elements.map do |index_elt|
|
138
|
+
rec.elements[index_elt]
|
139
|
+
end.flatten.tap{|x| break rec.ordinal_sequence_of_element(x.first).new(x, rec.attribute)}
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
data/lib/pione/model/list.rb
CHANGED
@@ -3,7 +3,7 @@ module Pione::Model
|
|
3
3
|
class PioneList < BasicModel
|
4
4
|
extend Forwardable
|
5
5
|
|
6
|
-
set_pione_model_type TypeList[
|
6
|
+
set_pione_model_type TypeList[TypeSequence]
|
7
7
|
|
8
8
|
attr_reader :values
|
9
9
|
def_delegators :@values, :[], :size, :empty?
|
@@ -27,7 +27,7 @@ module Pione::Model
|
|
27
27
|
# @return [TypeList]
|
28
28
|
# the type
|
29
29
|
def pione_model_type
|
30
|
-
type = @values.empty? ?
|
30
|
+
type = @values.empty? ? TypeSequence : @values.first.pione_model_type
|
31
31
|
TypeList.new(type)
|
32
32
|
end
|
33
33
|
|
@@ -69,23 +69,23 @@ module Pione::Model
|
|
69
69
|
# pione method
|
70
70
|
#
|
71
71
|
|
72
|
-
define_pione_method("==", [TypeList[
|
72
|
+
define_pione_method("==", [TypeList[TypeSequence]], TypeBoolean) do |rec, other|
|
73
73
|
PioneBoolean.new(rec.values == other.values)
|
74
74
|
end
|
75
75
|
|
76
|
-
define_pione_method("!=", [TypeList[
|
76
|
+
define_pione_method("!=", [TypeList[TypeSequence]], TypeBoolean) do |rec, other|
|
77
77
|
PioneBoolean.not(rec.call_pione_method("==", other))
|
78
78
|
end
|
79
79
|
|
80
|
-
define_pione_method("+", [TypeList[
|
80
|
+
define_pione_method("+", [TypeList[TypeSequence]], TypeList[TypeSequence]) do |rec, other|
|
81
81
|
PioneList.new(rec.values + other.values)
|
82
82
|
end
|
83
83
|
|
84
|
-
define_pione_method("-", [TypeList[
|
84
|
+
define_pione_method("-", [TypeList[TypeSequence]], TypeList[TypeSequence]) do |rec, other|
|
85
85
|
PioneList.new(rec.values - other.values)
|
86
86
|
end
|
87
87
|
|
88
|
-
define_pione_method("*", [TypeList[
|
88
|
+
define_pione_method("*", [TypeList[TypeSequence]], TypeList[TypeSequence]) do |rec, other|
|
89
89
|
PioneList.new(rec.values * other.values)
|
90
90
|
end
|
91
91
|
|
@@ -93,12 +93,16 @@ module Pione::Model
|
|
93
93
|
PioneBoolean.new(rec.empty?)
|
94
94
|
end
|
95
95
|
|
96
|
-
define_pione_method("[]", [TypeInteger],
|
96
|
+
define_pione_method("[]", [TypeInteger], TypeSequence) do |rec, i|
|
97
97
|
rec.values[i.value]
|
98
98
|
end
|
99
99
|
|
100
100
|
define_pione_method("as_string", [], TypeString) do |rec|
|
101
101
|
PioneString.new(rec.values.to_s)
|
102
102
|
end
|
103
|
+
|
104
|
+
define_pione_method("str", [], TypeString) do |rec|
|
105
|
+
rec.call_pione_method("as_string")
|
106
|
+
end
|
103
107
|
end
|
104
108
|
end
|
data/lib/pione/model/message.rb
CHANGED
@@ -36,11 +36,11 @@ module Pione
|
|
36
36
|
|
37
37
|
# Return PIONE model type of the message result according to type interface.
|
38
38
|
#
|
39
|
-
|
39
|
+
# @return [Symbol]
|
40
40
|
# PIONE model type
|
41
41
|
def pione_model_type
|
42
|
-
if
|
43
|
-
|
42
|
+
if pione_method = @receiver.pione_model_type.find_method(@name, @receiver, *@arguments)
|
43
|
+
pione_method.get_output_type(@receiver)
|
44
44
|
else
|
45
45
|
raise MethodNotFound.new(@name.to_s, self)
|
46
46
|
end
|
@@ -68,10 +68,14 @@ module Pione
|
|
68
68
|
|
69
69
|
# @api private
|
70
70
|
def textize
|
71
|
-
args = [@name, @receiver.textize, @arguments.textize]
|
71
|
+
args = [@name, @receiver.textize, @arguments.map{|arg| arg.textize}.join(",")]
|
72
72
|
"message(\"%s\",%s,[%s])" % args
|
73
73
|
end
|
74
74
|
|
75
|
+
def inspect
|
76
|
+
'#<Message "%s" %s %s>' % [@name, @receiver.inspect, @arguments.inspect]
|
77
|
+
end
|
78
|
+
|
75
79
|
# @api private
|
76
80
|
def ==(other)
|
77
81
|
return false unless other.kind_of?(self.class)
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Pione
|
2
|
+
module Model
|
3
|
+
class OrdinalSequence < Sequence
|
4
|
+
set_index_type TypeInteger
|
5
|
+
define_sequence_attribute :separator, " "
|
6
|
+
|
7
|
+
# @param elements [Array<Element>]
|
8
|
+
# sequence elements
|
9
|
+
# @param attribute [Hash]
|
10
|
+
# sequence attribute
|
11
|
+
def initialize(elements, attribute={})
|
12
|
+
super(elements, attribute)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
TypeOrdinalSequence.instance_eval do
|
17
|
+
define_pione_method("==", [:receiver_type], TypeBoolean) do |rec, other|
|
18
|
+
if rec.elements.size == other.elements.size
|
19
|
+
rec.elements.size.times.all? do |i|
|
20
|
+
rec.elements[i].value == other.elements[i].value
|
21
|
+
end.tap {|x| break BooleanSequence.new([PioneBoolean.new(x)])}
|
22
|
+
else
|
23
|
+
BooleanSequence.new([PioneBoolean.new(false)])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
define_pione_method("nth", [TypeInteger], :receiver_type) do |rec, index|
|
28
|
+
map1(index) do |elt|
|
29
|
+
elt.value == 0 ? rec : rec.elements[elt.value-1]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
define_pione_method("[]", [:index_type], :receiver_type) do |rec, index|
|
34
|
+
rec.call_pione_method("nth", index)
|
35
|
+
end
|
36
|
+
|
37
|
+
define_pione_method("reverse", [], :receiver_type) do |rec|
|
38
|
+
rec.class.new(rec.elements.reverse, rec.attribute)
|
39
|
+
end
|
40
|
+
|
41
|
+
define_pione_method("head", [], :receiver_type) do |rec|
|
42
|
+
rec.class.new([rec.elements[0]], rec.attribute)
|
43
|
+
end
|
44
|
+
|
45
|
+
define_pione_method("tail", [], :receiver_type) do |rec|
|
46
|
+
# NOTE: #tail should fail when the sequence length is less than 1
|
47
|
+
rec.class.new(rec.elements[1..-1], rec.attribute)
|
48
|
+
end
|
49
|
+
|
50
|
+
define_pione_method("last", [], :receiver_type) do |rec|
|
51
|
+
rec.class.new([rec.elements[-1]], rec.attribute)
|
52
|
+
end
|
53
|
+
|
54
|
+
define_pione_method("init", [], :receiver_type) do |rec|
|
55
|
+
# NOTE: #init should fail when the sequence length is less than 1
|
56
|
+
rec.class.new(rec.elements[0..-2], rec.attribute)
|
57
|
+
end
|
58
|
+
|
59
|
+
define_pione_method("type", [], TypeString) do |rec|
|
60
|
+
case rec
|
61
|
+
when StringSequence
|
62
|
+
"string"
|
63
|
+
when IntegerSequence
|
64
|
+
"integer"
|
65
|
+
when FloatSequence
|
66
|
+
"float"
|
67
|
+
when BooleanSequence
|
68
|
+
"boolean"
|
69
|
+
else
|
70
|
+
"undefined"
|
71
|
+
end.tap {|x| break PioneString.new(x).to_seq}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/pione/model/package.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module Pione
|
2
2
|
module Model
|
3
3
|
# Package is a PIONE model class for rule package.
|
4
|
-
class Package <
|
4
|
+
class Package < Element
|
5
5
|
attr_reader :name
|
6
|
-
set_pione_model_type TypePackage
|
7
6
|
|
8
7
|
# Create a package with name.
|
9
8
|
#
|
@@ -48,5 +47,10 @@ module Pione
|
|
48
47
|
@value.hash
|
49
48
|
end
|
50
49
|
end
|
50
|
+
|
51
|
+
class PackageSequence < Sequence
|
52
|
+
set_pione_model_type TypePackage
|
53
|
+
set_element_class Package
|
54
|
+
end
|
51
55
|
end
|
52
56
|
end
|