pione 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitignore +2 -1
  2. data/History.txt +11 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +1 -1
  5. data/bin/pione-log +5 -0
  6. data/example/CountChar/CountChar.pione +1 -1
  7. data/example/SieveOfEratosthenes/SieveOfEratosthenes.pione +39 -38
  8. data/lib/pione.rb +14 -35
  9. data/lib/pione/agent/input-generator.rb +38 -40
  10. data/lib/pione/agent/logger.rb +52 -19
  11. data/lib/pione/agent/rule-provider.rb +5 -8
  12. data/lib/pione/agent/task-worker.rb +25 -32
  13. data/lib/pione/agent/tuple-space-client.rb +22 -14
  14. data/lib/pione/command.rb +21 -0
  15. data/lib/pione/command/basic-command.rb +267 -84
  16. data/lib/pione/command/child-process.rb +21 -18
  17. data/lib/pione/command/daemon-process.rb +9 -8
  18. data/lib/pione/command/front-owner-command.rb +8 -25
  19. data/lib/pione/command/pione-broker.rb +27 -24
  20. data/lib/pione/command/pione-clean.rb +6 -6
  21. data/lib/pione/command/pione-client.rb +143 -128
  22. data/lib/pione/command/pione-log.rb +61 -0
  23. data/lib/pione/command/pione-relay-account-db.rb +40 -38
  24. data/lib/pione/command/pione-relay-client-db.rb +38 -42
  25. data/lib/pione/command/pione-relay.rb +19 -20
  26. data/lib/pione/command/pione-syntax-checker.rb +70 -45
  27. data/lib/pione/command/pione-task-worker.rb +56 -66
  28. data/lib/pione/command/pione-tuple-space-provider.rb +36 -45
  29. data/lib/pione/command/pione-tuple-space-receiver.rb +34 -32
  30. data/lib/pione/command/pione-tuple-space-viewer.rb +63 -47
  31. data/lib/pione/location.rb +10 -0
  32. data/lib/pione/location/basic-location.rb +272 -0
  33. data/lib/pione/location/dropbox-location.rb +139 -0
  34. data/lib/pione/location/ftp-location.rb +156 -0
  35. data/lib/pione/location/local-location.rb +116 -0
  36. data/lib/pione/log.rb +10 -0
  37. data/lib/pione/log/domain-info.rb +72 -0
  38. data/lib/pione/log/process-log.rb +176 -0
  39. data/lib/pione/log/process-record.rb +189 -0
  40. data/lib/pione/log/xes-log.rb +105 -0
  41. data/lib/pione/model/assignment.rb +88 -80
  42. data/lib/pione/model/binary-operator.rb +74 -68
  43. data/lib/pione/model/block.rb +218 -207
  44. data/lib/pione/model/boolean.rb +123 -112
  45. data/lib/pione/model/call-rule.rb +72 -65
  46. data/lib/pione/model/data-expr.rb +596 -290
  47. data/lib/pione/model/float.rb +108 -103
  48. data/lib/pione/model/integer.rb +133 -129
  49. data/lib/pione/model/message.rb +79 -72
  50. data/lib/pione/model/package.rb +42 -38
  51. data/lib/pione/model/parameters.rb +265 -236
  52. data/lib/pione/model/rule-expr.rb +247 -242
  53. data/lib/pione/model/rule-io.rb +137 -133
  54. data/lib/pione/model/rule.rb +307 -292
  55. data/lib/pione/model/string.rb +110 -99
  56. data/lib/pione/model/variable-table.rb +300 -271
  57. data/lib/pione/model/variable.rb +88 -83
  58. data/lib/pione/option.rb +13 -0
  59. data/lib/pione/option/child-process-option.rb +19 -0
  60. data/lib/pione/{command-option → option}/common-option.rb +6 -5
  61. data/lib/pione/option/option-interface.rb +73 -0
  62. data/lib/pione/{command-option → option}/presence-notifier-option.rb +4 -3
  63. data/lib/pione/option/task-worker-owner-option.rb +24 -0
  64. data/lib/pione/{command-option → option}/tuple-space-provider-option.rb +6 -4
  65. data/lib/pione/option/tuple-space-provider-owner-option.rb +18 -0
  66. data/lib/pione/option/tuple-space-receiver-option.rb +8 -0
  67. data/lib/pione/parser/common-parser.rb +3 -2
  68. data/lib/pione/parser/expr-parser.rb +6 -1
  69. data/lib/pione/patch/em-ftpd-patch.rb +21 -0
  70. data/lib/pione/patch/rinda-patch.rb +31 -23
  71. data/lib/pione/rule-handler/action-handler.rb +35 -25
  72. data/lib/pione/rule-handler/basic-handler.rb +92 -18
  73. data/lib/pione/rule-handler/flow-handler.rb +104 -98
  74. data/lib/pione/rule-handler/root-handler.rb +11 -0
  75. data/lib/pione/system/common.rb +10 -0
  76. data/lib/pione/system/file-cache.rb +103 -84
  77. data/lib/pione/system/global.rb +67 -12
  78. data/lib/pione/system/init.rb +20 -0
  79. data/lib/pione/transformer/expr-transformer.rb +6 -1
  80. data/lib/pione/tuple-space/data-finder.rb +33 -6
  81. data/lib/pione/tuple-space/tuple-space-receiver.rb +4 -3
  82. data/lib/pione/tuple-space/tuple-space-server-interface.rb +58 -13
  83. data/lib/pione/tuple-space/tuple-space-server.rb +13 -11
  84. data/lib/pione/tuple-space/update-criteria.rb +8 -7
  85. data/lib/pione/tuple/base-location-tuple.rb +9 -0
  86. data/lib/pione/tuple/basic-tuple.rb +7 -7
  87. data/lib/pione/tuple/data-tuple.rb +5 -2
  88. data/lib/pione/tuple/lift-tuple.rb +14 -0
  89. data/lib/pione/tuple/rule-tuple.rb +1 -1
  90. data/lib/pione/tuple/task-tuple.rb +5 -1
  91. data/lib/pione/version.rb +1 -1
  92. data/pione.gemspec +5 -1
  93. data/test/location/spec_basic-location.rb +35 -0
  94. data/test/location/spec_ftp-location.rb +100 -0
  95. data/test/location/spec_local-location.rb +99 -0
  96. data/test/log/data/sample.log +1003 -0
  97. data/test/log/spec_xes-log.rb +11 -0
  98. data/test/model/spec_data-expr.rb +249 -6
  99. data/test/model/spec_data-expr.yml +45 -0
  100. data/test/parser/spec_expr-parser.yml +4 -0
  101. data/test/spec_data-finder.rb +13 -7
  102. data/test/spec_data-finder.yml +42 -13
  103. data/test/system/spec_file-cache.rb +39 -0
  104. data/test/test-util.rb +226 -1
  105. data/test/transformer/spec_expr-transformer.rb +12 -1
  106. metadata +107 -24
  107. data/bin/pione-search-log +0 -30
  108. data/lib/pione/command-option/basic-option.rb +0 -42
  109. data/lib/pione/command-option/child-process-option.rb +0 -17
  110. data/lib/pione/command-option/daemon-option.rb +0 -12
  111. data/lib/pione/command-option/task-worker-owner-option.rb +0 -17
  112. data/lib/pione/command-option/tuple-space-provider-owner-option.rb +0 -16
  113. data/lib/pione/command-option/tuple-space-receiver-option.rb +0 -12
  114. data/lib/pione/command/tuple-space-provider-owner.rb +0 -6
  115. data/lib/pione/resource/basic-resource.rb +0 -92
  116. data/lib/pione/resource/dropbox-resource.rb +0 -106
  117. data/lib/pione/resource/ftp.rb +0 -84
  118. data/lib/pione/resource/local.rb +0 -113
  119. data/lib/pione/tuple/base-uri-tuple.rb +0 -9
  120. data/lib/pione/tuple/shift-tuple.rb +0 -13
  121. data/lib/pione/util/log.rb +0 -79
  122. data/test/spec_resource.rb +0 -73
@@ -1,108 +1,119 @@
1
- module Pione::Model
2
- # PioneString is a string value in PIONE system.
3
- class PioneString < BasicModel
4
- set_pione_model_type TypeString
5
- attr_reader :value
6
-
7
- # Creates a string with the value.
8
- # @param [String] value
9
- # string value
10
- def initialize(value)
11
- @value = value
12
- super()
13
- end
14
-
15
- # Evaluates the object with the variable table.
16
- # @param [VariableTable] vtable
17
- # variable table for evaluation
18
- # @return [BasicModel]
19
- # evaluation result
20
- def eval(vtable)
21
- self.class.new(vtable.expand(@value))
22
- end
23
-
24
- # Returns true if the value includes variables.
25
- # @return [Boolean]
26
- # true if the value includes variables
27
- def include_variable?
28
- VariableTable.check_include_variable(@value)
29
- end
30
-
31
- # @api private
32
- def task_id_string
33
- "String<#{@value}>"
34
- end
35
-
36
- # @api private
37
- def textize
38
- "\"%s\"" % [@value]
39
- end
40
-
41
- # Returns ruby's value.
42
- # @return [String]
43
- # the value in ruby
44
- def to_ruby
45
- return @value
46
- end
47
-
48
- # @api private
49
- def ==(other)
50
- return false unless other.kind_of?(self.class)
51
- @value == other.value
52
- end
53
-
54
- alias :eql? :"=="
55
-
56
- # @api private
57
- def hash
58
- @value.hash
59
- end
60
- end
61
-
62
- TypeString.instance_eval do
63
- define_pione_method("==", [TypeString], TypeBoolean) do |rec, other|
64
- PioneBoolean.new(rec.value == other.value)
65
- end
66
-
67
- define_pione_method("!=", [TypeString], TypeBoolean) do |rec, other|
68
- PioneBoolean.not(rec.call_pione_method("==", other))
69
- end
70
-
71
- define_pione_method("+", [TypeString], TypeString) do |rec, other|
72
- PioneString.new(rec.value + other.value)
73
- end
74
-
75
- define_pione_method("as_string", [], TypeString) do |rec|
76
- rec
77
- end
78
-
79
- define_pione_method("as_int", [], TypeInteger) do |rec|
80
- PioneInteger.new(rec.value.to_i)
81
- end
82
-
83
- define_pione_method("as_float", [], TypeFloat) do |rec|
84
- PioneFloat.new(rec.value.to_f)
85
- end
86
-
87
- define_pione_method("length", [], TypeInteger) do |rec|
88
- PioneInteger.new(rec.value.size)
89
- end
90
-
91
- define_pione_method("include?", [TypeString], TypeBoolean) do |rec, str|
92
- PioneBoolean.new(rec.value.include?(str.value))
93
- end
94
-
95
- define_pione_method("substring",
96
- [TypeInteger, TypeInteger],
97
- TypeString) do |rec, nth, len|
98
- PioneString.new(rec.value[nth.value, len.value])
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
- # Returns PIONE's value.
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::Model
2
- # UnboundVariableError represents an unknown variable reference.
3
- class UnboundVariableError < StandardError
4
- attr_reader :variable
5
-
6
- # Creates an error.
7
- # @param [Variable] variable
8
- # unbound variable
9
- def initialize(variable)
10
- @variable = variable
11
- end
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
- # @api private
14
- def message
15
- "Refferred unbound variable '%s' in the context." % @variable.name
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
- # VariableBindingError represents an error that you try to bind different value
20
- # to a variable.
21
- class VariableBindingError < StandardError
22
- attr_reader :variable
23
- attr_reader :new_value
24
- attr_reader :old_value
25
-
26
- # Creates an error.
27
- # @param [Variable] variable
28
- # double bound variable
29
- # @param [BasicModel] new_value
30
- # new value
31
- # @param [BasicModel] old_value
32
- # old value
33
- def initialize(variable, new_value, old_value)
34
- @variable = variable
35
- @new_value = new_value
36
- @old_value = old_value
37
- end
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
- # @api private
40
- def message
41
- args = [
42
- @new_value.textize,
43
- @variable.name,
44
- @old_value.textize,
45
- @variable.line,
46
- @variable.column
47
- ]
48
- message = [
49
- "Try to bind the value '%s' as variable %s, ",
50
- "but already bound the value '%s'",
51
- "(line: %s, column: %s)"
52
- ] % args
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
- # VariableTable represents variable tables for rule context.
57
- class VariableTable < BasicModel
58
- set_pione_model_type TypeVariableTable
59
+ # VariableTable represents variable tables for rule context.
60
+ class VariableTable < BasicModel
61
+ set_pione_model_type TypeVariableTable
59
62
 
60
- # Returns empty variable table.
61
- # @return [VariableTable]
62
- # empty variable table
63
- def self.empty
64
- new
65
- end
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
- # Returns the variable table as hash.
76
- # @return [Hash{Variable => BasicModel}]
77
- # hash form of the variable table
78
- def to_hash
79
- @table
80
- end
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
- # Returns the parameters form.
83
- # @return [Parameters]
84
- # parameters form of the variable table
85
- def to_params
86
- Parameters.new(to_hash)
87
- end
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
- # Returns true if the table is empty.
90
- # @return [Boolean]
91
- # true if the table is empty
92
- def empty?
93
- @table.empty?
94
- end
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
- # Gets the variable value and evaluates the value if the value is not
97
- # atomic.
98
- # @param [Variable] var
99
- # table key to get the value
100
- # @return [BasicModel]
101
- # the value
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
- # Sets a new variable. This method raises an exception when the variable has
116
- # its value already.
117
- # @param [Variable] variable
118
- # table key
119
- # @param [BasicModel] new_value
120
- # new value
121
- # @return [VariableTable]
122
- # new variable table
123
- def set(variable, new_value)
124
- check_argument_type(variable, Variable)
125
- check_argument_type(new_value, BasicModel)
126
- if old_value = @table[variable]
127
- unless old_value.kind_of?(UndefinedValue) or new_value == old_value
128
- raise VariableBindingError.new(variable, new_value, old_value)
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
- # Expands variables in the string.
147
- # @param [String] str
148
- # string
149
- # @return [String]
150
- # expanded string
151
- def expand(str)
152
- variables = to_hash
153
- new_str = str.to_s.gsub(/\{(\$.+?)\}/) do
154
- expr = DocumentTransformer.new.apply(DocumentParser.new.expr.parse($1))
155
- expr.eval(self).call_pione_method("as_string").to_ruby
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
- new_str.gsub(/\<\?\s*(.+?)\s*\?\>/) do
158
- expr = DocumentTransformer.new.apply(DocumentParser.new.expr.parse($1))
159
- expr.eval(self).call_pione_method("as_string").to_ruby
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
- # Returns key variables of the table.
164
- # @return [Array<Variable>]
165
- # variable as table keys
166
- def variables
167
- @table.keys
168
- end
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
- # FIXME
171
- # Returns true if the string includes variables.
172
- # @param [String] str
173
- # target string
174
- # @return [Boolean]
175
- # true if the string includes variables
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
- @table.values.any?{|val| val.include_variable?}
192
- end
193
-
194
- # Makes input auto-variables.
195
- # @param [Array<DataExpr>] input_exprs
196
- # input expressions
197
- # @param [Array<Expr>] input_tuples
198
- # input tuples
199
- # @return [void]
200
- def make_input_auto_variables(input_exprs, input_tuples)
201
- set(Variable.new("INPUT"), Variable.new("I"))
202
- input_exprs.each_with_index do |expr, index|
203
- make_io_auto_variables(:input, expr, input_tuples[index], index+1)
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
- # Makes output auto-variables.
208
- # @param [Array<DataExpr>] output_exprs
209
- # output expressions
210
- # @param [Array<DataExpr>] output_tuples
211
- # output tuples
212
- # @return [void]
213
- def make_output_auto_variables(output_exprs, output_tuples)
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
- alias :eql? :"=="
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
- # @api private
229
- def hash
230
- @table.hash
231
- end
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
- private
234
-
235
- # Make input or output auto variables.
236
- # @api private
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
- end
242
+ alias :eql? :"=="
247
243
 
248
- # Make input or output auto variables for 'exist' modified data name
249
- # expression.
250
- # @api private
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
- # Make input or output auto variables for 'all' modified data name
275
- # expression.
276
- # @api private
277
- def make_io_auto_variables_by_all(type, prefix, expr, tuples)
278
- # FIXME: output
279
- return if type == :output
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
- # variable
282
- var = Variable.new(prefix)
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
- # setup rule-io list
285
- list = get(var)
286
- list = RuleIOList.new unless list
287
- io_list = RuleIOList.new()
283
+ # update the list
284
+ set!(var, list.add(elt))
288
285
 
289
- # convert each tuples
290
- tuples.each do |tuple, i|
291
- elt = RuleIOElement.new(PioneString.new(tuple.name))
292
- elt.uri = PioneString.new(tuple.uri)
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
- # update
300
- set!(var, list.add(io_list))
301
- end
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
- # pione methods
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
- define_pione_method("get", [TypeString], TypeAny) do |name|
308
- get(Variable.new(name.value))
309
- end
327
+ # update
328
+ set!(var, list.add(io_list))
329
+ end
330
+
331
+ #
332
+ # pione methods
333
+ #
310
334
 
311
- define_pione_method("keys", [], TypeList.new(TypeString)) do
312
- PioneList.new(@table.keys.map{|var| PioneString.new(var.name)})
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