pione 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/History.txt +11 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/bin/pione-log +5 -0
- data/example/CountChar/CountChar.pione +1 -1
- data/example/SieveOfEratosthenes/SieveOfEratosthenes.pione +39 -38
- data/lib/pione.rb +14 -35
- data/lib/pione/agent/input-generator.rb +38 -40
- data/lib/pione/agent/logger.rb +52 -19
- data/lib/pione/agent/rule-provider.rb +5 -8
- data/lib/pione/agent/task-worker.rb +25 -32
- data/lib/pione/agent/tuple-space-client.rb +22 -14
- data/lib/pione/command.rb +21 -0
- data/lib/pione/command/basic-command.rb +267 -84
- data/lib/pione/command/child-process.rb +21 -18
- data/lib/pione/command/daemon-process.rb +9 -8
- data/lib/pione/command/front-owner-command.rb +8 -25
- data/lib/pione/command/pione-broker.rb +27 -24
- data/lib/pione/command/pione-clean.rb +6 -6
- data/lib/pione/command/pione-client.rb +143 -128
- data/lib/pione/command/pione-log.rb +61 -0
- data/lib/pione/command/pione-relay-account-db.rb +40 -38
- data/lib/pione/command/pione-relay-client-db.rb +38 -42
- data/lib/pione/command/pione-relay.rb +19 -20
- data/lib/pione/command/pione-syntax-checker.rb +70 -45
- data/lib/pione/command/pione-task-worker.rb +56 -66
- data/lib/pione/command/pione-tuple-space-provider.rb +36 -45
- data/lib/pione/command/pione-tuple-space-receiver.rb +34 -32
- data/lib/pione/command/pione-tuple-space-viewer.rb +63 -47
- data/lib/pione/location.rb +10 -0
- data/lib/pione/location/basic-location.rb +272 -0
- data/lib/pione/location/dropbox-location.rb +139 -0
- data/lib/pione/location/ftp-location.rb +156 -0
- data/lib/pione/location/local-location.rb +116 -0
- data/lib/pione/log.rb +10 -0
- data/lib/pione/log/domain-info.rb +72 -0
- data/lib/pione/log/process-log.rb +176 -0
- data/lib/pione/log/process-record.rb +189 -0
- data/lib/pione/log/xes-log.rb +105 -0
- data/lib/pione/model/assignment.rb +88 -80
- data/lib/pione/model/binary-operator.rb +74 -68
- data/lib/pione/model/block.rb +218 -207
- data/lib/pione/model/boolean.rb +123 -112
- data/lib/pione/model/call-rule.rb +72 -65
- data/lib/pione/model/data-expr.rb +596 -290
- data/lib/pione/model/float.rb +108 -103
- data/lib/pione/model/integer.rb +133 -129
- data/lib/pione/model/message.rb +79 -72
- data/lib/pione/model/package.rb +42 -38
- data/lib/pione/model/parameters.rb +265 -236
- data/lib/pione/model/rule-expr.rb +247 -242
- data/lib/pione/model/rule-io.rb +137 -133
- data/lib/pione/model/rule.rb +307 -292
- data/lib/pione/model/string.rb +110 -99
- data/lib/pione/model/variable-table.rb +300 -271
- data/lib/pione/model/variable.rb +88 -83
- data/lib/pione/option.rb +13 -0
- data/lib/pione/option/child-process-option.rb +19 -0
- data/lib/pione/{command-option → option}/common-option.rb +6 -5
- data/lib/pione/option/option-interface.rb +73 -0
- data/lib/pione/{command-option → option}/presence-notifier-option.rb +4 -3
- data/lib/pione/option/task-worker-owner-option.rb +24 -0
- data/lib/pione/{command-option → option}/tuple-space-provider-option.rb +6 -4
- data/lib/pione/option/tuple-space-provider-owner-option.rb +18 -0
- data/lib/pione/option/tuple-space-receiver-option.rb +8 -0
- data/lib/pione/parser/common-parser.rb +3 -2
- data/lib/pione/parser/expr-parser.rb +6 -1
- data/lib/pione/patch/em-ftpd-patch.rb +21 -0
- data/lib/pione/patch/rinda-patch.rb +31 -23
- data/lib/pione/rule-handler/action-handler.rb +35 -25
- data/lib/pione/rule-handler/basic-handler.rb +92 -18
- data/lib/pione/rule-handler/flow-handler.rb +104 -98
- data/lib/pione/rule-handler/root-handler.rb +11 -0
- data/lib/pione/system/common.rb +10 -0
- data/lib/pione/system/file-cache.rb +103 -84
- data/lib/pione/system/global.rb +67 -12
- data/lib/pione/system/init.rb +20 -0
- data/lib/pione/transformer/expr-transformer.rb +6 -1
- data/lib/pione/tuple-space/data-finder.rb +33 -6
- data/lib/pione/tuple-space/tuple-space-receiver.rb +4 -3
- data/lib/pione/tuple-space/tuple-space-server-interface.rb +58 -13
- data/lib/pione/tuple-space/tuple-space-server.rb +13 -11
- data/lib/pione/tuple-space/update-criteria.rb +8 -7
- data/lib/pione/tuple/base-location-tuple.rb +9 -0
- data/lib/pione/tuple/basic-tuple.rb +7 -7
- data/lib/pione/tuple/data-tuple.rb +5 -2
- data/lib/pione/tuple/lift-tuple.rb +14 -0
- data/lib/pione/tuple/rule-tuple.rb +1 -1
- data/lib/pione/tuple/task-tuple.rb +5 -1
- data/lib/pione/version.rb +1 -1
- data/pione.gemspec +5 -1
- data/test/location/spec_basic-location.rb +35 -0
- data/test/location/spec_ftp-location.rb +100 -0
- data/test/location/spec_local-location.rb +99 -0
- data/test/log/data/sample.log +1003 -0
- data/test/log/spec_xes-log.rb +11 -0
- data/test/model/spec_data-expr.rb +249 -6
- data/test/model/spec_data-expr.yml +45 -0
- data/test/parser/spec_expr-parser.yml +4 -0
- data/test/spec_data-finder.rb +13 -7
- data/test/spec_data-finder.yml +42 -13
- data/test/system/spec_file-cache.rb +39 -0
- data/test/test-util.rb +226 -1
- data/test/transformer/spec_expr-transformer.rb +12 -1
- metadata +107 -24
- data/bin/pione-search-log +0 -30
- data/lib/pione/command-option/basic-option.rb +0 -42
- data/lib/pione/command-option/child-process-option.rb +0 -17
- data/lib/pione/command-option/daemon-option.rb +0 -12
- data/lib/pione/command-option/task-worker-owner-option.rb +0 -17
- data/lib/pione/command-option/tuple-space-provider-owner-option.rb +0 -16
- data/lib/pione/command-option/tuple-space-receiver-option.rb +0 -12
- data/lib/pione/command/tuple-space-provider-owner.rb +0 -6
- data/lib/pione/resource/basic-resource.rb +0 -92
- data/lib/pione/resource/dropbox-resource.rb +0 -106
- data/lib/pione/resource/ftp.rb +0 -84
- data/lib/pione/resource/local.rb +0 -113
- data/lib/pione/tuple/base-uri-tuple.rb +0 -9
- data/lib/pione/tuple/shift-tuple.rb +0 -13
- data/lib/pione/util/log.rb +0 -79
- data/test/spec_resource.rb +0 -73
data/lib/pione/model/string.rb
CHANGED
@@ -1,108 +1,119 @@
|
|
1
|
-
module Pione
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
rec
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
1
|
+
module Pione
|
2
|
+
module Model
|
3
|
+
# PioneString is a string value in PIONE system.
|
4
|
+
class PioneString < BasicModel
|
5
|
+
set_pione_model_type TypeString
|
6
|
+
attr_reader :value
|
7
|
+
|
8
|
+
# Create a string with the value.
|
9
|
+
#
|
10
|
+
# @param value [String]
|
11
|
+
# string value
|
12
|
+
def initialize(value)
|
13
|
+
@value = value
|
14
|
+
super()
|
15
|
+
end
|
16
|
+
|
17
|
+
# Evaluate the object with the variable table.
|
18
|
+
#
|
19
|
+
# @param vtable [VariableTable]
|
20
|
+
# variable table for evaluation
|
21
|
+
# @return [BasicModel]
|
22
|
+
# evaluation result
|
23
|
+
def eval(vtable)
|
24
|
+
self.class.new(vtable.expand(@value))
|
25
|
+
end
|
26
|
+
|
27
|
+
# Return true if the value includes variables.
|
28
|
+
#
|
29
|
+
# @return [Boolean]
|
30
|
+
# true if the value includes variables
|
31
|
+
def include_variable?
|
32
|
+
VariableTable.check_include_variable(@value)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @api private
|
36
|
+
def task_id_string
|
37
|
+
"String<#{@value}>"
|
38
|
+
end
|
39
|
+
|
40
|
+
# @api private
|
41
|
+
def textize
|
42
|
+
"\"%s\"" % [@value]
|
43
|
+
end
|
44
|
+
|
45
|
+
# Return ruby's value.
|
46
|
+
#
|
47
|
+
# @return [String]
|
48
|
+
# the value in ruby
|
49
|
+
def to_ruby
|
50
|
+
return @value
|
51
|
+
end
|
52
|
+
|
53
|
+
# @api private
|
54
|
+
def ==(other)
|
55
|
+
return false unless other.kind_of?(self.class)
|
56
|
+
@value == other.value
|
57
|
+
end
|
58
|
+
|
59
|
+
alias :eql? :"=="
|
60
|
+
|
61
|
+
# @api private
|
62
|
+
def hash
|
63
|
+
@value.hash
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
TypeString.instance_eval do
|
68
|
+
define_pione_method("==", [TypeString], TypeBoolean) do |rec, other|
|
69
|
+
PioneBoolean.new(rec.value == other.value)
|
70
|
+
end
|
71
|
+
|
72
|
+
define_pione_method("!=", [TypeString], TypeBoolean) do |rec, other|
|
73
|
+
PioneBoolean.not(rec.call_pione_method("==", other))
|
74
|
+
end
|
75
|
+
|
76
|
+
define_pione_method("+", [TypeString], TypeString) do |rec, other|
|
77
|
+
PioneString.new(rec.value + other.value)
|
78
|
+
end
|
79
|
+
|
80
|
+
define_pione_method("as_string", [], TypeString) do |rec|
|
81
|
+
rec
|
82
|
+
end
|
83
|
+
|
84
|
+
define_pione_method("as_int", [], TypeInteger) do |rec|
|
85
|
+
PioneInteger.new(rec.value.to_i)
|
86
|
+
end
|
87
|
+
|
88
|
+
define_pione_method("as_float", [], TypeFloat) do |rec|
|
89
|
+
PioneFloat.new(rec.value.to_f)
|
90
|
+
end
|
91
|
+
|
92
|
+
define_pione_method("length", [], TypeInteger) do |rec|
|
93
|
+
PioneInteger.new(rec.value.size)
|
94
|
+
end
|
95
|
+
|
96
|
+
define_pione_method("include?", [TypeString], TypeBoolean) do |rec, str|
|
97
|
+
PioneBoolean.new(rec.value.include?(str.value))
|
98
|
+
end
|
99
|
+
|
100
|
+
define_pione_method("as_data_expr", [], TypeDataExpr) do |rec|
|
101
|
+
DataExpr.new(rec.value)
|
102
|
+
end
|
103
|
+
|
104
|
+
define_pione_method("substring",
|
105
|
+
[TypeInteger, TypeInteger],
|
106
|
+
TypeString) do |rec, nth, len|
|
107
|
+
PioneString.new(rec.value[nth.value, len.value])
|
108
|
+
end
|
99
109
|
end
|
100
110
|
end
|
101
111
|
end
|
102
112
|
|
103
113
|
# String extention for PIONE system.
|
104
114
|
class String
|
105
|
-
#
|
115
|
+
# Return PIONE's value.
|
116
|
+
#
|
106
117
|
# @return [PioneString]
|
107
118
|
# PIONE's value
|
108
119
|
def to_pione
|
@@ -1,315 +1,344 @@
|
|
1
|
-
module Pione
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
module Pione
|
2
|
+
module Model
|
3
|
+
# UnboundVariableError represents an unknown variable reference.
|
4
|
+
class UnboundVariableError < StandardError
|
5
|
+
attr_reader :variable
|
6
|
+
|
7
|
+
# Create an error.
|
8
|
+
#
|
9
|
+
# @param variable [Variable]
|
10
|
+
# unbound variable
|
11
|
+
def initialize(variable)
|
12
|
+
@variable = variable
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
# @api private
|
16
|
+
def message
|
17
|
+
"Refferred unbound variable '%s' in the context." % @variable.name
|
18
|
+
end
|
16
19
|
end
|
17
|
-
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
21
|
+
# VariableBindingError represents an error that you try to bind different value
|
22
|
+
# to a variable.
|
23
|
+
class VariableBindingError < StandardError
|
24
|
+
attr_reader :variable
|
25
|
+
attr_reader :new_value
|
26
|
+
attr_reader :old_value
|
27
|
+
|
28
|
+
# Create an error.
|
29
|
+
#
|
30
|
+
# @param variable [Variable]
|
31
|
+
# double bound variable
|
32
|
+
# @param new_value [BasicModel]
|
33
|
+
# new value
|
34
|
+
# @param old_value [BasicModel]
|
35
|
+
# old value
|
36
|
+
def initialize(variable, new_value, old_value)
|
37
|
+
@variable = variable
|
38
|
+
@new_value = new_value
|
39
|
+
@old_value = old_value
|
40
|
+
end
|
38
41
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
# @api private
|
43
|
+
def message
|
44
|
+
args = [
|
45
|
+
@new_value.textize,
|
46
|
+
@variable.name,
|
47
|
+
@old_value.textize,
|
48
|
+
@variable.line,
|
49
|
+
@variable.column
|
50
|
+
]
|
51
|
+
message = [
|
52
|
+
"Try to bind the value '%s' as variable %s, ",
|
53
|
+
"but already bound the value '%s'",
|
54
|
+
"(line: %s, column: %s)"
|
55
|
+
] % args
|
56
|
+
end
|
53
57
|
end
|
54
|
-
end
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
# VariableTable represents variable tables for rule context.
|
60
|
+
class VariableTable < BasicModel
|
61
|
+
set_pione_model_type TypeVariableTable
|
59
62
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
# Creates a vairable table.
|
68
|
-
# @param [Hash{Variable => BasicModel}] table
|
69
|
-
# initial values for the variable table
|
70
|
-
def initialize(table={})
|
71
|
-
@table = table.to_hash.dup
|
72
|
-
super()
|
73
|
-
end
|
63
|
+
# Return empty variable table.
|
64
|
+
#
|
65
|
+
# @return [VariableTable]
|
66
|
+
# empty variable table
|
67
|
+
def self.empty
|
68
|
+
new
|
69
|
+
end
|
74
70
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
71
|
+
# Create a vairable table.
|
72
|
+
#
|
73
|
+
# @param table [Hash{Variable => BasicModel}]
|
74
|
+
# initial values for the variable table
|
75
|
+
def initialize(table={})
|
76
|
+
@table = table.to_hash.dup
|
77
|
+
super()
|
78
|
+
end
|
81
79
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
80
|
+
# Return the variable table as hash.
|
81
|
+
#
|
82
|
+
# @return [Hash{Variable => BasicModel}]
|
83
|
+
# hash form of the variable table
|
84
|
+
def to_hash
|
85
|
+
@table
|
86
|
+
end
|
88
87
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
88
|
+
# Return the parameters form.
|
89
|
+
#
|
90
|
+
# @return [Parameters]
|
91
|
+
# parameters form of the variable table
|
92
|
+
def to_params
|
93
|
+
Parameters.new(to_hash)
|
94
|
+
end
|
95
95
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
def get(var)
|
103
|
-
check_argument_type(var, Variable)
|
104
|
-
val = @table[var]
|
105
|
-
case val
|
106
|
-
when Variable
|
107
|
-
next_val = get(val)
|
108
|
-
return next_val.nil? ? val : next_val
|
109
|
-
when BasicModel
|
110
|
-
return not(val.atomic?) ? val.eval(self) : val
|
96
|
+
# Return true if the table is empty.
|
97
|
+
#
|
98
|
+
# @return [Boolean]
|
99
|
+
# true if the table is empty
|
100
|
+
def empty?
|
101
|
+
@table.empty?
|
111
102
|
end
|
112
|
-
return val
|
113
|
-
end
|
114
103
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
104
|
+
# Gets the variable value and evaluates the value if the value is not
|
105
|
+
# atomic.
|
106
|
+
#
|
107
|
+
# @param var [Variable]
|
108
|
+
# table key to get the value
|
109
|
+
# @return [BasicModel]
|
110
|
+
# the value
|
111
|
+
def get(var)
|
112
|
+
check_argument_type(var, Variable)
|
113
|
+
val = @table[var]
|
114
|
+
case val
|
115
|
+
when Variable
|
116
|
+
next_val = get(val)
|
117
|
+
return next_val.nil? ? val : next_val
|
118
|
+
when BasicModel
|
119
|
+
return not(val.atomic?) ? val.eval(self) : val
|
129
120
|
end
|
121
|
+
return val
|
130
122
|
end
|
131
|
-
@table[variable] = new_value
|
132
|
-
end
|
133
|
-
|
134
|
-
# Sets a variable. This method overrides old variable value.
|
135
|
-
# @param [Variable] variable
|
136
|
-
# table key
|
137
|
-
# @param [BasicModel] new_value
|
138
|
-
# new value
|
139
|
-
# @return [void]
|
140
|
-
def set!(variable, new_value)
|
141
|
-
check_argument_type(variable, Variable)
|
142
|
-
check_argument_type(new_value, BasicModel)
|
143
|
-
@table[variable] = new_value
|
144
|
-
end
|
145
123
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
124
|
+
# Set a new variable. This method raises an exception when the variable has
|
125
|
+
# its value already.
|
126
|
+
#
|
127
|
+
# @param variable [Variable]
|
128
|
+
# table key
|
129
|
+
# @param new_value [BasicModel]
|
130
|
+
# new value
|
131
|
+
# @return [VariableTable]
|
132
|
+
# new variable table
|
133
|
+
def set(variable, new_value)
|
134
|
+
check_argument_type(variable, Variable)
|
135
|
+
check_argument_type(new_value, BasicModel)
|
136
|
+
if old_value = @table[variable]
|
137
|
+
unless old_value.kind_of?(UndefinedValue) or new_value == old_value
|
138
|
+
raise VariableBindingError.new(variable, new_value, old_value)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
@table[variable] = new_value
|
156
142
|
end
|
157
|
-
|
158
|
-
|
159
|
-
|
143
|
+
|
144
|
+
# Set a variable. This method overrides old variable value.
|
145
|
+
#
|
146
|
+
# @param variable [Variable]
|
147
|
+
# table key
|
148
|
+
# @param new_value [BasicModel]
|
149
|
+
# new value
|
150
|
+
# @return [void]
|
151
|
+
def set!(variable, new_value)
|
152
|
+
check_argument_type(variable, Variable)
|
153
|
+
check_argument_type(new_value, BasicModel)
|
154
|
+
@table[variable] = new_value
|
160
155
|
end
|
161
|
-
end
|
162
156
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
@
|
168
|
-
|
157
|
+
# Expand variables in the string.
|
158
|
+
#
|
159
|
+
# @param str [String]
|
160
|
+
# string
|
161
|
+
# @return [String]
|
162
|
+
# expanded string
|
163
|
+
def expand(str)
|
164
|
+
variables = to_hash
|
165
|
+
new_str = str.to_s.gsub(/\{(\$.+?)\}/) do
|
166
|
+
expr = DocumentTransformer.new.apply(DocumentParser.new.expr.parse($1))
|
167
|
+
expr.eval(self).call_pione_method("as_string").to_ruby
|
168
|
+
end
|
169
|
+
new_str.gsub(/\<\?\s*(.+?)\s*\?\>/) do
|
170
|
+
expr = DocumentTransformer.new.apply(DocumentParser.new.expr.parse($1))
|
171
|
+
expr.eval(self).call_pione_method("as_string").to_ruby
|
172
|
+
end
|
173
|
+
end
|
169
174
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
def self.check_include_variable(str)
|
177
|
-
str = str.to_s
|
178
|
-
return true if /\{\$(.+?)\}/.match(str)
|
179
|
-
str.gsub(/\<\?\s*(.+?)\s*\?\>/) do
|
180
|
-
expr = Transformer.new.apply(Parser.new.expr.parse($1))
|
181
|
-
return true if expr.include_variable?
|
175
|
+
# Return key variables of the table.
|
176
|
+
#
|
177
|
+
# @return [Array<Variable>]
|
178
|
+
# variable as table keys
|
179
|
+
def variables
|
180
|
+
@table.keys
|
182
181
|
end
|
183
|
-
return false
|
184
|
-
end
|
185
182
|
|
186
|
-
# Returns true if table's values include variables.
|
187
|
-
# @return [Boolean]
|
188
|
-
# true if table's values include variables
|
189
|
-
def include_variable?
|
190
183
|
# FIXME
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
184
|
+
# Return true if the string includes variables.
|
185
|
+
#
|
186
|
+
# @param str [String]
|
187
|
+
# target string
|
188
|
+
# @return [Boolean]
|
189
|
+
# true if the string includes variables
|
190
|
+
def self.check_include_variable(str)
|
191
|
+
str = str.to_s
|
192
|
+
return true if /\{\$(.+?)\}/.match(str)
|
193
|
+
str.gsub(/\<\?\s*(.+?)\s*\?\>/) do
|
194
|
+
expr = Transformer.new.apply(Parser.new.expr.parse($1))
|
195
|
+
return true if expr.include_variable?
|
196
|
+
end
|
197
|
+
return false
|
204
198
|
end
|
205
|
-
end
|
206
199
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
set(Variable.new("OUTPUT"), Variable.new("O"))
|
215
|
-
output_exprs.each_with_index do |expr, index|
|
216
|
-
make_io_auto_variables(:output, expr, output_tuples[index], index+1)
|
200
|
+
# Return true if table's values include variables.
|
201
|
+
#
|
202
|
+
# @return [Boolean]
|
203
|
+
# true if table's values include variables
|
204
|
+
def include_variable?
|
205
|
+
# FIXME
|
206
|
+
@table.values.any?{|val| val.include_variable?}
|
217
207
|
end
|
218
|
-
end
|
219
|
-
|
220
|
-
# @api private
|
221
|
-
def ==(other)
|
222
|
-
return false unless other.kind_of?(self.class)
|
223
|
-
@table == other.to_hash
|
224
|
-
end
|
225
208
|
|
226
|
-
|
209
|
+
# Make input auto-variables.
|
210
|
+
#
|
211
|
+
# @param input_exprs [Array<DataExpr>]
|
212
|
+
# input expressions
|
213
|
+
# @param input_tuples [Array<Expr>]
|
214
|
+
# input tuples
|
215
|
+
# @return [void]
|
216
|
+
def make_input_auto_variables(input_exprs, input_tuples)
|
217
|
+
set(Variable.new("INPUT"), Variable.new("I"))
|
218
|
+
input_exprs.each_with_index do |expr, index|
|
219
|
+
make_io_auto_variables(:input, expr, input_tuples[index], index+1)
|
220
|
+
end
|
221
|
+
end
|
227
222
|
|
228
|
-
|
229
|
-
|
230
|
-
@
|
231
|
-
|
223
|
+
# Make output auto-variables.
|
224
|
+
#
|
225
|
+
# @param output_exprs [Array<DataExpr>]
|
226
|
+
# output expressions
|
227
|
+
# @param output_tuples [Array<DataExpr>]
|
228
|
+
# output tuples
|
229
|
+
# @return [void]
|
230
|
+
def make_output_auto_variables(output_exprs, output_tuples)
|
231
|
+
set(Variable.new("OUTPUT"), Variable.new("O"))
|
232
|
+
output_exprs.each_with_index do |expr, index|
|
233
|
+
make_io_auto_variables(:output, expr, output_tuples[index], index+1)
|
234
|
+
end
|
235
|
+
end
|
232
236
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
def make_io_auto_variables(type, expr, data, index)
|
238
|
-
expr = expr.eval(self)
|
239
|
-
prefix = (type == :input ? "I" : "O")
|
240
|
-
case expr.modifier
|
241
|
-
when :all
|
242
|
-
make_io_auto_variables_by_all(type, prefix, expr, data)
|
243
|
-
when :each
|
244
|
-
make_io_auto_variables_by_each(prefix, expr, data, index)
|
237
|
+
# @api private
|
238
|
+
def ==(other)
|
239
|
+
return false unless other.kind_of?(self.class)
|
240
|
+
@table == other.to_hash
|
245
241
|
end
|
246
|
-
|
242
|
+
alias :eql? :"=="
|
247
243
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
def make_io_auto_variables_by_each(prefix, expr, tuple, index)
|
252
|
-
return if tuple.nil?
|
253
|
-
# variable
|
254
|
-
var = Variable.new(prefix)
|
255
|
-
# matched data
|
256
|
-
md = expr.match(tuple.name).to_a
|
257
|
-
|
258
|
-
# setup rule-io list
|
259
|
-
list = get(var)
|
260
|
-
list = RuleIOList.new unless list
|
261
|
-
elt = RuleIOElement.new(PioneString.new(tuple.name))
|
262
|
-
elt.uri = PioneString.new(tuple.uri)
|
263
|
-
elt.match = PioneList.new(*md.map{|d| PioneString.new(d)})
|
264
|
-
|
265
|
-
# update the list
|
266
|
-
set!(var, list.add(elt))
|
267
|
-
|
268
|
-
# set special variable if index equals 1
|
269
|
-
if prefix == 'I' && index == 1
|
270
|
-
set(Variable.new("*"), PioneString.new(md[1]))
|
244
|
+
# @api private
|
245
|
+
def hash
|
246
|
+
@table.hash
|
271
247
|
end
|
272
|
-
end
|
273
248
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
#
|
279
|
-
|
249
|
+
private
|
250
|
+
|
251
|
+
# Make input or output auto variables.
|
252
|
+
#
|
253
|
+
# @api private
|
254
|
+
def make_io_auto_variables(type, expr, data, index)
|
255
|
+
expr = expr.eval(self)
|
256
|
+
prefix = (type == :input ? "I" : "O")
|
257
|
+
case expr.modifier
|
258
|
+
when :all
|
259
|
+
make_io_auto_variables_by_all(type, prefix, expr, data, index)
|
260
|
+
when :each
|
261
|
+
make_io_auto_variables_by_each(prefix, expr, data, index)
|
262
|
+
end
|
263
|
+
end
|
280
264
|
|
281
|
-
#
|
282
|
-
|
265
|
+
# Make input or output auto variables for 'exist' modified data name
|
266
|
+
# expression.
|
267
|
+
#
|
268
|
+
# @api private
|
269
|
+
def make_io_auto_variables_by_each(prefix, expr, tuple, index)
|
270
|
+
return if tuple.nil?
|
271
|
+
# variable
|
272
|
+
var = Variable.new(prefix)
|
273
|
+
# matched data
|
274
|
+
md = expr.match(tuple.name).to_a
|
275
|
+
|
276
|
+
# setup rule-io list
|
277
|
+
list = get(var)
|
278
|
+
list = RuleIOList.new unless list
|
279
|
+
elt = RuleIOElement.new(PioneString.new(tuple.name))
|
280
|
+
elt.uri = PioneString.new(tuple.location.uri.to_s)
|
281
|
+
elt.match = PioneList.new(*md.map{|d| PioneString.new(d)})
|
283
282
|
|
284
|
-
|
285
|
-
|
286
|
-
list = RuleIOList.new unless list
|
287
|
-
io_list = RuleIOList.new()
|
283
|
+
# update the list
|
284
|
+
set!(var, list.add(elt))
|
288
285
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
elt.match = PioneList.new(
|
294
|
-
*expr.match(tuple.name).to_a.map{|m| PioneString.new(m)}
|
295
|
-
)
|
296
|
-
io_list.add!(elt)
|
286
|
+
# set special variable if index equals 1
|
287
|
+
if prefix == 'I' && index == 1
|
288
|
+
set(Variable.new("*"), PioneString.new(md[1]))
|
289
|
+
end
|
297
290
|
end
|
298
291
|
|
299
|
-
#
|
300
|
-
|
301
|
-
|
292
|
+
# Make input or output auto variables for 'all' modified data name
|
293
|
+
# expression.
|
294
|
+
#
|
295
|
+
# @api private
|
296
|
+
def make_io_auto_variables_by_all(type, prefix, expr, tuples, index)
|
297
|
+
# FIXME: output
|
298
|
+
return if type == :output
|
299
|
+
|
300
|
+
# variable
|
301
|
+
var = Variable.new(prefix)
|
302
|
+
|
303
|
+
# setup rule-io list
|
304
|
+
list = get(var)
|
305
|
+
list = RuleIOList.new unless list
|
306
|
+
io_list = RuleIOList.new()
|
307
|
+
|
308
|
+
asterisk = []
|
309
|
+
|
310
|
+
# convert each tuples
|
311
|
+
tuples.each do |tuple, i|
|
312
|
+
asterisk << expr.match(tuple.name).to_a[1]
|
313
|
+
|
314
|
+
elt = RuleIOElement.new(PioneString.new(tuple.name))
|
315
|
+
elt.uri = PioneString.new(tuple.location.uri.to_s)
|
316
|
+
elt.match = PioneList.new(
|
317
|
+
*expr.match(tuple.name).to_a.map{|m| PioneString.new(m)}
|
318
|
+
)
|
319
|
+
io_list.add!(elt)
|
320
|
+
end
|
302
321
|
|
303
|
-
|
304
|
-
|
305
|
-
|
322
|
+
# set special variable if index equals 1
|
323
|
+
if prefix == 'I' && index == 1
|
324
|
+
set(Variable.new("*"), PioneString.new(asterisk.join(":")))
|
325
|
+
end
|
306
326
|
|
307
|
-
|
308
|
-
|
309
|
-
|
327
|
+
# update
|
328
|
+
set!(var, list.add(io_list))
|
329
|
+
end
|
330
|
+
|
331
|
+
#
|
332
|
+
# pione methods
|
333
|
+
#
|
310
334
|
|
311
|
-
|
312
|
-
|
335
|
+
define_pione_method("get", [TypeString], TypeAny) do |name|
|
336
|
+
get(Variable.new(name.value))
|
337
|
+
end
|
338
|
+
|
339
|
+
define_pione_method("keys", [], TypeList.new(TypeString)) do
|
340
|
+
PioneList.new(@table.keys.map{|var| PioneString.new(var.name)})
|
341
|
+
end
|
313
342
|
end
|
314
343
|
end
|
315
344
|
end
|