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/message.rb
CHANGED
@@ -1,84 +1,91 @@
|
|
1
|
-
module Pione
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# @param [String] name
|
14
|
-
# message name
|
15
|
-
# @param [BasicModel] receiver
|
16
|
-
# message receiver
|
17
|
-
# @param [BasicModel] arguments
|
18
|
-
# message arguments
|
19
|
-
def initialize(name, receiver, *arguments)
|
20
|
-
@name = name
|
21
|
-
@receiver = receiver.to_pione
|
22
|
-
@arguments = arguments.map{|arg| arg.to_pione}
|
23
|
-
super()
|
24
|
-
end
|
1
|
+
module Pione
|
2
|
+
module Model
|
3
|
+
# Message represents method callers for PIONE model objects.
|
4
|
+
#
|
5
|
+
# @example
|
6
|
+
# 1.as_string()
|
7
|
+
# @example
|
8
|
+
# '*.txt'.except('a*')
|
9
|
+
class Message < BasicModel
|
10
|
+
attr_reader :name
|
11
|
+
attr_reader :receiver
|
12
|
+
attr_reader :arguments
|
25
13
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
14
|
+
# Create a message.
|
15
|
+
#
|
16
|
+
# @param name [String]
|
17
|
+
# message name
|
18
|
+
# @param receiver [BasicModel]
|
19
|
+
# message receiver
|
20
|
+
# @param arguments [BasicModel]
|
21
|
+
# message arguments
|
22
|
+
def initialize(name, receiver, *arguments)
|
23
|
+
@name = name
|
24
|
+
@receiver = receiver.to_pione
|
25
|
+
@arguments = arguments.map{|arg| arg.to_pione}
|
26
|
+
super()
|
27
|
+
end
|
32
28
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
interface.output
|
40
|
-
else
|
41
|
-
raise MethodNotFound.new(@name.to_s, self)
|
29
|
+
# Return false because Message is a complex form.
|
30
|
+
#
|
31
|
+
# @return [Boolean]
|
32
|
+
# false
|
33
|
+
def atomic?
|
34
|
+
false
|
42
35
|
end
|
43
|
-
end
|
44
36
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
37
|
+
# Return PIONE model type of the message result according to type interface.
|
38
|
+
#
|
39
|
+
# @return [Symbol]
|
40
|
+
# PIONE model type
|
41
|
+
def pione_model_type
|
42
|
+
if interface = @receiver.pione_model_type.method_interface[@name.to_s]
|
43
|
+
interface.output
|
44
|
+
else
|
45
|
+
raise MethodNotFound.new(@name.to_s, self)
|
46
|
+
end
|
47
|
+
end
|
54
48
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
49
|
+
# Evaluate the application expression and returns application result.
|
50
|
+
#
|
51
|
+
# @param vtable [VariableTable]
|
52
|
+
# variable table for the evaluation
|
53
|
+
# @return [BasicModel]
|
54
|
+
# evaluation result
|
55
|
+
def eval(vtable)
|
56
|
+
receiver = @receiver.eval(vtable)
|
57
|
+
arguments = @arguments.map{|arg| arg.eval(vtable)}
|
58
|
+
receiver.call_pione_method(@name, *arguments)
|
59
|
+
end
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
# Return true if the receiver or arguments include variables.
|
62
|
+
#
|
63
|
+
# @return [Boolean]
|
64
|
+
# true if the receiver or arguments include variables
|
65
|
+
def include_variable?
|
66
|
+
@receiver.include_variable? or @arguments.any?{|arg| arg.include_variable?}
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
return false unless @arguments == other.arguments
|
74
|
-
return true
|
75
|
-
end
|
69
|
+
# @api private
|
70
|
+
def textize
|
71
|
+
args = [@name, @receiver.textize, @arguments.textize]
|
72
|
+
"message(\"%s\",%s,[%s])" % args
|
73
|
+
end
|
76
74
|
|
77
|
-
|
75
|
+
# @api private
|
76
|
+
def ==(other)
|
77
|
+
return false unless other.kind_of?(self.class)
|
78
|
+
return false unless @name == other.name
|
79
|
+
return false unless @receiver == other.receiver
|
80
|
+
return false unless @arguments == other.arguments
|
81
|
+
return true
|
82
|
+
end
|
83
|
+
alias :eql? :"=="
|
78
84
|
|
79
|
-
|
80
|
-
|
81
|
-
|
85
|
+
# @api private
|
86
|
+
def hash
|
87
|
+
@name.hash + @receiver.hash + @arguments.hash
|
88
|
+
end
|
82
89
|
end
|
83
90
|
end
|
84
91
|
end
|
data/lib/pione/model/package.rb
CHANGED
@@ -1,48 +1,52 @@
|
|
1
|
-
module Pione
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Pione
|
2
|
+
module Model
|
3
|
+
# Package is a PIONE model class for rule package.
|
4
|
+
class Package < BasicModel
|
5
|
+
attr_reader :name
|
6
|
+
set_pione_model_type TypePackage
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
# Create a package with name.
|
9
|
+
#
|
10
|
+
# @param name [String]
|
11
|
+
# package name
|
12
|
+
def initialize(name)
|
13
|
+
@name = name
|
14
|
+
super()
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
# @api private
|
18
|
+
def task_id_string
|
19
|
+
"Package<#{@name}>"
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
# @api private
|
23
|
+
def textize
|
24
|
+
"package(\"%s\")" % [@name]
|
25
|
+
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
# Return a rule path.
|
28
|
+
#
|
29
|
+
# @param other [RuleExpr]
|
30
|
+
# rule expression
|
31
|
+
# @return [String]
|
32
|
+
# rule path string
|
33
|
+
def +(other)
|
34
|
+
raise ArgumentError.new(other) unless other.kind_of?(RuleExpr)
|
35
|
+
"#{@name}:#{other.name}"
|
36
|
+
end
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
# @api private
|
39
|
+
def ==(other)
|
40
|
+
return false unless other.kind_of?(self.class)
|
41
|
+
@name == other.name
|
42
|
+
end
|
40
43
|
|
41
|
-
|
44
|
+
alias :eql? :"=="
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
# @api private
|
47
|
+
def hash
|
48
|
+
@value.hash
|
49
|
+
end
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
@@ -1,282 +1,311 @@
|
|
1
|
-
module Pione
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
module Pione
|
2
|
+
module Model
|
3
|
+
# Parameters is a PIONE mode class for parameters.
|
4
|
+
class Parameters < BasicModel
|
5
|
+
# InvalidParameter is raised when you specify invalid parameter.
|
6
|
+
class InvalidParameter < TypeError
|
7
|
+
# Create a error.
|
8
|
+
#
|
9
|
+
# @param [Object] key
|
10
|
+
# specified key
|
11
|
+
def initialize(key)
|
12
|
+
@key = key
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
# @api private
|
16
|
+
def message
|
17
|
+
"invalid parameter key: %s" % [@key.inspect]
|
18
|
+
end
|
16
19
|
end
|
17
|
-
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
# InvalidArgument is raised when you specify invalid argument.
|
22
|
+
class InvalidArgument < TypeError
|
23
|
+
# Create a error.
|
24
|
+
#
|
25
|
+
# @param [Object] val
|
26
|
+
# specified value
|
27
|
+
def initialize(val)
|
28
|
+
@val = val
|
29
|
+
end
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
# @api private
|
32
|
+
def message
|
33
|
+
"invalid argument value: %s" % [@val.inspect]
|
34
|
+
end
|
31
35
|
end
|
32
|
-
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
class << self
|
38
|
+
# Create a empty parameters object.
|
39
|
+
#
|
40
|
+
# @return [Parameters]
|
41
|
+
# empty parameters
|
42
|
+
def empty
|
43
|
+
self.new({})
|
44
|
+
end
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
# Merge arguments' parameters.
|
47
|
+
#
|
48
|
+
# @param list [Array<Parameters>]
|
49
|
+
# merge target elements
|
50
|
+
# @return [Parameters]
|
51
|
+
# merged result
|
52
|
+
def merge(*list)
|
53
|
+
new_params = empty
|
54
|
+
list.each do |params|
|
55
|
+
new_params = new_params.merge(params)
|
56
|
+
end
|
57
|
+
return new_params
|
51
58
|
end
|
52
|
-
return new_params
|
53
59
|
end
|
54
|
-
end
|
55
60
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
attr_reader :data
|
62
|
+
set_pione_model_type TypeParameters
|
63
|
+
|
64
|
+
# Create a parameters object.
|
65
|
+
#
|
66
|
+
# @param [Hash{Variable => BasicModel}] data
|
67
|
+
# parameters data table
|
68
|
+
def initialize(data)
|
69
|
+
raise TypeError.new(data) unless data.kind_of?(Hash)
|
70
|
+
data.each do |key, val|
|
71
|
+
raise InvalidParameter.new(key) unless key.kind_of?(Variable)
|
72
|
+
raise InvalidArgument.new(val) unless val.kind_of?(BasicModel)
|
73
|
+
end
|
74
|
+
@data = data
|
75
|
+
super()
|
67
76
|
end
|
68
|
-
@data = data
|
69
|
-
super()
|
70
|
-
end
|
71
77
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
# Evaluate the object with variable table.
|
79
|
+
#
|
80
|
+
# @param vtable [VariableTable]
|
81
|
+
# variable tabale for evaluation
|
82
|
+
# @return [BasicModel]
|
83
|
+
# evaluated result
|
84
|
+
def eval(vtable)
|
85
|
+
return self.class.empty if empty?
|
86
|
+
data = @data.map{|key, val| [key, val.eval(vtable)]}.flatten(1)
|
87
|
+
self.class.new(Hash[*data])
|
88
|
+
end
|
82
89
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
90
|
+
# Return true if parameters include variables.
|
91
|
+
#
|
92
|
+
# @return [Boolean]
|
93
|
+
# true if parameters include variables
|
94
|
+
def include_variable?
|
95
|
+
@data.any? {|_, val| val.include_variable?}
|
96
|
+
end
|
89
97
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
98
|
+
# @api private
|
99
|
+
def textize
|
100
|
+
"{" + @data.map{|k,v| "%s:%s" % [k.textize[1..-1], v.textize]}.join(", ") + "}"
|
101
|
+
end
|
94
102
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
+
# Return value of parameter name.
|
104
|
+
#
|
105
|
+
# @param name [String]
|
106
|
+
# parameter name to get the value
|
107
|
+
# @return [BasicModel]
|
108
|
+
# the value
|
109
|
+
def [](name)
|
110
|
+
@data[Variable.new(name)]
|
111
|
+
end
|
103
112
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
113
|
+
# Return the value corresponding to the parameter name. Raises an error
|
114
|
+
# when the parameter name is kind of a variable.
|
115
|
+
#
|
116
|
+
# @param name [Variable]
|
117
|
+
# variable to get the value
|
118
|
+
# @return [BasicModel]
|
119
|
+
# the value
|
120
|
+
def get(name)
|
121
|
+
raise InvalidParameter.new(name) unless name.kind_of?(Variable)
|
122
|
+
@data[name]
|
123
|
+
end
|
114
124
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
+
# Add the parameter value and return new parameters.
|
126
|
+
#
|
127
|
+
# @param name [Variable]
|
128
|
+
# variable
|
129
|
+
# @param value [BasicModel]
|
130
|
+
# value
|
131
|
+
# @return [Parameters]
|
132
|
+
# new parameters with the parameter
|
133
|
+
def set(name, value)
|
134
|
+
raise InvalidParameter.new(name) unless name.kind_of?(Variable)
|
135
|
+
raise InvalidArgument.new(value) unless value.kind_of?(BasicModel)
|
136
|
+
self.class.new(@data.merge({name => value}))
|
137
|
+
end
|
125
138
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
139
|
+
# Add the parameter value.
|
140
|
+
#
|
141
|
+
# @param name [Variable]
|
142
|
+
# variable
|
143
|
+
# @param value [BasicModel]
|
144
|
+
# value
|
145
|
+
# @return [void]
|
146
|
+
def set!(name, value)
|
147
|
+
raise InvalidParameter.new(name) unless name.kind_of?(Variable)
|
148
|
+
raise InvalidArgument.new(value) unless value.kind_of?(BasicModel)
|
149
|
+
@data.merge!({name => value})
|
150
|
+
end
|
135
151
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
152
|
+
# Add the parameter value safety and return new parameters.
|
153
|
+
#
|
154
|
+
# @param name [Variable]
|
155
|
+
# variable
|
156
|
+
# @param value [BasicModel]
|
157
|
+
# vlaue
|
158
|
+
# @return [Parameters]
|
159
|
+
# new parameters with the parameter
|
160
|
+
def set_safety(name, value)
|
161
|
+
if not(@data.has_key?(name)) or @data[name].kind_of?(UndefinedValue)
|
162
|
+
set(name, value)
|
163
|
+
end
|
144
164
|
end
|
145
|
-
end
|
146
165
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
166
|
+
# Add the parameter value safety.
|
167
|
+
#
|
168
|
+
# @param name [Variable]
|
169
|
+
# variable
|
170
|
+
# @param value [BasicModel]
|
171
|
+
# value
|
172
|
+
# @return [void]
|
173
|
+
def set_safety!(name, value)
|
174
|
+
if not(@data.has_key?(name)) or @data[name].kind_of?(UndefinedValue)
|
175
|
+
set!(name, value)
|
176
|
+
end
|
154
177
|
end
|
155
|
-
end
|
156
178
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
179
|
+
# Delete the parameter by name.
|
180
|
+
#
|
181
|
+
# @param name [Variable]
|
182
|
+
# target's name
|
183
|
+
# @return [Parameters]
|
184
|
+
# new parameters that deleted the target
|
185
|
+
def delete(name)
|
186
|
+
raise InvalidParameter.new(name) unless name.kind_of?(Variable)
|
187
|
+
new_data = @data.clone
|
188
|
+
new_data.delete(name)
|
189
|
+
self.class.new(new_data)
|
190
|
+
end
|
168
191
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
192
|
+
# Return true if the parameters is empty.
|
193
|
+
#
|
194
|
+
# @return [Boolean]
|
195
|
+
# true if the parameters is empty
|
196
|
+
def empty?
|
197
|
+
@data.empty?
|
198
|
+
end
|
175
199
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
200
|
+
# Update parameters with the argument and return new parameters with it.
|
201
|
+
#
|
202
|
+
# @param other [BasicModel]
|
203
|
+
# merge target
|
204
|
+
# @return [Parameters]
|
205
|
+
# new parameters that merged the target
|
206
|
+
def merge(other)
|
207
|
+
case other
|
208
|
+
when Parameters
|
209
|
+
self.class.new(@data.merge(other.data))
|
210
|
+
when Variable
|
211
|
+
self.class.new(@data.merge({other => UndefinedValue.new}))
|
212
|
+
when Assignment
|
213
|
+
self.class.new(@data.merge({other.variable => other.expr}))
|
214
|
+
else
|
215
|
+
raise TypeError.new(other)
|
216
|
+
end
|
191
217
|
end
|
192
|
-
end
|
193
218
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
219
|
+
# Update parameters with the argument destructively.
|
220
|
+
#
|
221
|
+
# @param [BasicModel] other
|
222
|
+
# merge target
|
223
|
+
# @return [void]
|
224
|
+
def merge!(other)
|
225
|
+
case other
|
226
|
+
when Parameters
|
227
|
+
@data.merge!(other.data)
|
228
|
+
when Variable
|
229
|
+
@data.merge!({other => UndefinedValue.new})
|
230
|
+
when Assignment
|
231
|
+
@data.merge!({other.variable => other.expr})
|
232
|
+
else
|
233
|
+
raise TypeError.new(other)
|
234
|
+
end
|
208
235
|
end
|
209
|
-
end
|
210
236
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
237
|
+
# Convert into variable table.
|
238
|
+
#
|
239
|
+
# @return [VariableTable]
|
240
|
+
# variable table which values are same as the parameters.
|
241
|
+
def as_variable_table
|
242
|
+
VariableTable.new(@data)
|
243
|
+
end
|
217
244
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
245
|
+
# Return key list.
|
246
|
+
#
|
247
|
+
# @return [Array<Variable>]
|
248
|
+
# parameter key list
|
249
|
+
def keys
|
250
|
+
@data.keys.sort
|
251
|
+
end
|
224
252
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
253
|
+
# @api private
|
254
|
+
def string_form
|
255
|
+
"{" + @data.map{|k,v| "#{k}: #{v}"}.join(", ") + "}"
|
256
|
+
end
|
229
257
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
258
|
+
# @api private
|
259
|
+
def to_json(*args)
|
260
|
+
@data.to_json(*args)
|
261
|
+
end
|
234
262
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
263
|
+
# @api private
|
264
|
+
def ==(other)
|
265
|
+
return false unless other.kind_of?(self.class)
|
266
|
+
@data == other.data
|
267
|
+
end
|
240
268
|
|
241
|
-
|
269
|
+
alias :eql? :"=="
|
242
270
|
|
243
|
-
|
244
|
-
|
245
|
-
|
271
|
+
# @api private
|
272
|
+
def hash
|
273
|
+
@data.hash
|
274
|
+
end
|
246
275
|
end
|
247
|
-
end
|
248
276
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
277
|
+
TypeParameters.instance_eval do
|
278
|
+
define_pione_method('==', [TypeParameters], TypeBoolean) do |rec, other|
|
279
|
+
PioneBoolean.new(rec.data == other.data)
|
280
|
+
end
|
253
281
|
|
254
|
-
|
255
|
-
|
256
|
-
|
282
|
+
define_pione_method("!=", [TypeParameters], TypeBoolean) do |rec, other|
|
283
|
+
PioneBoolean.not(rec.call_pione_method("==", other))
|
284
|
+
end
|
257
285
|
|
258
|
-
|
259
|
-
|
260
|
-
|
286
|
+
define_pione_method("[]", [TypeString], TypeAny) do |rec, name|
|
287
|
+
rec.get(Variable.new(name.value))
|
288
|
+
end
|
261
289
|
|
262
|
-
|
263
|
-
|
264
|
-
|
290
|
+
define_pione_method("get", [TypeString], TypeAny) do |rec, name|
|
291
|
+
rec.get(Variable.new(name.value))
|
292
|
+
end
|
265
293
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
294
|
+
define_pione_method(
|
295
|
+
"set",
|
296
|
+
[TypeString, TypeAny],
|
297
|
+
TypeParameters
|
298
|
+
) do |rec, name, val|
|
299
|
+
rec.set(Variable.new(name.value), val)
|
300
|
+
end
|
273
301
|
|
274
|
-
|
275
|
-
|
276
|
-
|
302
|
+
define_pione_method("empty?", [], TypeBoolean) do |rec|
|
303
|
+
PioneBoolean.new(rec.empty?)
|
304
|
+
end
|
277
305
|
|
278
|
-
|
279
|
-
|
306
|
+
define_pione_method("as_string", [], TypeString) do |rec|
|
307
|
+
PioneString.new(rec.string_form)
|
308
|
+
end
|
280
309
|
end
|
281
310
|
end
|
282
311
|
end
|