pione 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. data/History.txt +13 -0
  2. data/Rakefile +3 -3
  3. data/example/DeferredChoice/DeferredChoice.pione +50 -0
  4. data/example/Fib/Fib.pione +17 -16
  5. data/example/SingleParticlesWithRef/SingleParticlesWithRef.Display2.pione +128 -0
  6. data/lib/pione.rb +1 -0
  7. data/lib/pione/agent/broker.rb +18 -4
  8. data/lib/pione/agent/task-worker.rb +19 -21
  9. data/lib/pione/command-option/task-worker-owner-option.rb +1 -1
  10. data/lib/pione/command/basic-command.rb +13 -8
  11. data/lib/pione/command/front-owner-command.rb +1 -1
  12. data/lib/pione/command/pione-broker.rb +2 -1
  13. data/lib/pione/command/pione-client.rb +41 -2
  14. data/lib/pione/command/pione-syntax-checker.rb +14 -3
  15. data/lib/pione/command/pione-task-worker.rb +4 -1
  16. data/lib/pione/command/pione-tuple-space-provider.rb +6 -7
  17. data/lib/pione/model/assignment.rb +6 -0
  18. data/lib/pione/model/message.rb +7 -3
  19. data/lib/pione/model/variable.rb +11 -0
  20. data/lib/pione/parser/common-parser.rb +36 -14
  21. data/lib/pione/parser/document-parser.rb +82 -5
  22. data/lib/pione/parser/rule-definition-parser.rb +2 -30
  23. data/lib/pione/system/config.rb +54 -6
  24. data/lib/pione/system/document.rb +13 -4
  25. data/lib/pione/system/global.rb +8 -8
  26. data/lib/pione/system/init.rb +3 -0
  27. data/lib/pione/transformer/document-transformer.rb +5 -1
  28. data/lib/pione/transformer/rule-definition-transformer.rb +8 -14
  29. data/lib/pione/tuple-space/tuple-space-receiver.rb +1 -1
  30. data/lib/pione/version.rb +2 -1
  31. data/pione.gemspec +2 -0
  32. data/test/parser/spec_document-parser.rb +5 -0
  33. data/test/parser/spec_document-parser.yml +62 -0
  34. data/test/{spec_document.rb → system/spec_document.rb} +22 -2
  35. data/test/test-util.rb +3 -3
  36. data/test/transformer/spec_rule-definition-transformer.rb +68 -73
  37. metadata +46 -5
  38. data/example/Fib/FibBC.pione +0 -56
@@ -1,19 +1,67 @@
1
1
  module Pione
2
2
  module System
3
- # Config represents a PIONE system configuration.
3
+ # Config is a class for setting PIONE system configuration.
4
4
  class Config < PioneObject
5
5
  extend Forwardable
6
6
 
7
- attr_reader :path
7
+ # This exception class is raised when configuration file is in invalid format.
8
+ class InvalidConfigFormat < StandardError
9
+ # config file path
10
+ # @return [Pathname]
11
+ attr_reader :path
12
+
13
+ # Create an exception.
14
+ #
15
+ # @param path [Pathname]
16
+ # configuration file path
17
+ def initialize(path)
18
+ @path = path
19
+ end
20
+
21
+ # @api private
22
+ def message
23
+ "invalid format configuration file: %s" % @path
24
+ end
25
+ end
26
+
27
+ class << self
28
+ # Load configuration and apply it to global settings.
29
+ #
30
+ # @param path [Pathname or String]
31
+ # configuration file path
32
+ # @return [void]
33
+ def load(path)
34
+ new(path).tap {|x| x.apply}
35
+ end
36
+ end
37
+
8
38
  def_delegator :@table, "[]"
9
39
 
10
- # Creates a new configuration.
11
- # @param [Hash] data
12
- # preset configuration table
40
+ # config file path
41
+ # @return [Pathname]
42
+ attr_reader :path
43
+
44
+ # Create a new configuration.
45
+ #
46
+ # @param path [Pathname or String]
47
+ # configuration file path
13
48
  def initialize(path)
14
49
  @path = Pathname.new(path)
15
50
  @table = @path.exist? ? YAML.load(@path.read) : {}
16
- raise TypeError.new(@path) unless @table.kind_of?(Hash)
51
+ raise InvalidConfigFormat.new(@path) unless @table.kind_of?(Hash)
52
+ end
53
+
54
+ # Apply config date to global settings.
55
+ #
56
+ # @return [void]
57
+ def apply
58
+ # set values
59
+ keys = Global.all_names
60
+ @table.each do |key, val|
61
+ Global.send("set_%s" % key, val) if keys.include?(key.to_sym)
62
+ end
63
+ # initialize global settings with new configuration
64
+ Global.init
17
65
  end
18
66
  end
19
67
  end
@@ -24,6 +24,16 @@ module Pione
24
24
  rules = toplevels.select{|elt| elt.kind_of?(Rule)}
25
25
  assignments = toplevels.select{|elt| elt.kind_of?(Assignment)}
26
26
  assignments.each {|assignment| assignment.set_toplevel(true)}
27
+ user_params = Naming::ParamLine.values(toplevels)
28
+ Naming::ParamBlock.values(toplevels).each do |elts|
29
+ user_params += elts
30
+ end
31
+ assignments += user_params.map do |param|
32
+ param.tap do |x|
33
+ x.set_toplevel(true)
34
+ x.set_user_param(true)
35
+ end
36
+ end
27
37
 
28
38
  # make document parameters
29
39
  params = assignments.inject(VariableTable.empty) do |vtable, a|
@@ -31,9 +41,7 @@ module Pione
31
41
  end.to_params
32
42
 
33
43
  # set document parameters into rules
34
- rules.each do |rule|
35
- rule.params.merge!(params)
36
- end
44
+ rules.each {|rule| rule.params.merge!(params)}
37
45
 
38
46
  # make rule table
39
47
  table = rules.inject({}) do |tbl, rule|
@@ -43,6 +51,7 @@ module Pione
43
51
  end
44
52
 
45
53
  attr_reader :rules
54
+ attr_reader :params
46
55
 
47
56
  # Creates a document.
48
57
  def initialize(rules, params)
@@ -74,7 +83,7 @@ module Pione
74
83
  # @return [RootRule]
75
84
  # root rule
76
85
  def root_rule(params)
77
- Rule::RootRule.new(main, params.merge(@params))
86
+ Rule::RootRule.new(main, @params.merge(params))
78
87
  end
79
88
  end
80
89
  end
@@ -49,6 +49,7 @@ module Pione
49
49
  end
50
50
 
51
51
  # Returns all item names.
52
+ #
52
53
  # @return [Symbol]
53
54
  # all item names
54
55
  def all_names
@@ -58,18 +59,19 @@ module Pione
58
59
  # Initializes global values.
59
60
  # @return [void]
60
61
  def init
61
- @__config__.each do |name, config_name|
62
- if val = Global.config[config_name]
63
- instance_variable_set("@%s" % name, val)
64
- end
65
- end
66
-
67
62
  @__initializer__.each do |name, action|
68
63
  unless instance_variable_get("@%s" % name)
69
64
  instance_variable_set("@%s" % name, action.call)
70
65
  end
71
66
  end
72
67
  end
68
+
69
+ # Return the table of all configurations.
70
+ #
71
+ # @return [Hash<Symbol, Object>]
72
+ def all
73
+ Hash[all_names.map {|name| [name, Global.send(name)]}]
74
+ end
73
75
  end
74
76
 
75
77
  extend GlobalInterface
@@ -88,8 +90,6 @@ module Pione
88
90
  # system
89
91
  #
90
92
 
91
- define_item(:config, true, Config.new("~/.pione/config.yml"))
92
-
93
93
  # .pione dir
94
94
  define_item(:dot_pione_dir, true) do
95
95
  Pathname.new("~/.pione").expand_path.tap {|path|
@@ -5,6 +5,9 @@ module Pione
5
5
  # init globals
6
6
  Global.init
7
7
 
8
+ # load configration file
9
+ System::Config.load(Global.config_path)
10
+
8
11
  # relay client database
9
12
  Global.relay_client_db = Relay::RelayClientDB.new(Global.relay_client_db_path)
10
13
 
@@ -27,9 +27,13 @@ module Pione
27
27
  # statement
28
28
  #
29
29
 
30
+ rule(:param_block => sequence(:assignment_list)) {
31
+ Naming.ParamBlock(assignment_list)
32
+ }
33
+
30
34
  # package
31
35
  rule(:package => subtree(:tree)) {
32
- @current_package = Package.new(tree[:package_name].to_s)
36
+ @current_package = Naming.Package(tree[:package_name].to_s)
33
37
  }
34
38
  end
35
39
  end
@@ -13,14 +13,10 @@ module Pione
13
13
  :rule_header => simple(:rule_expr),
14
14
  :rule_conditions => sequence(:conditions),
15
15
  :block => simple(:block) }) {
16
- inputs = conditions.select{|c| c.type == :input}.map{|c| c.obj}
17
- outputs = conditions.select{|c| c.type == :output}.map{|c| c.obj}
18
- params = Parameters.merge(
19
- *conditions.select{|c| c.type == :param}.map{|c| c.obj}
20
- )
21
- features = Feature::AndExpr.new(
22
- *conditions.select{|c| c.type == :feature}.map{|c| c.obj}
23
- )
16
+ inputs = Naming::InputLine.values(conditions)
17
+ outputs = Naming::OutputLine.values(conditions)
18
+ params = Parameters.merge(*Naming::ParamLine.values(conditions))
19
+ features = Feature::AndExpr.new(*Naming::FeatureLine.values(conditions))
24
20
  condition = RuleCondition.new(inputs, outputs, params, features)
25
21
  case block
26
22
  when ActionBlock
@@ -30,18 +26,16 @@ module Pione
30
26
  end.new(rule_expr, condition, block)
31
27
  }
32
28
 
33
- ConditionLine = Struct.new(:type, :obj)
34
-
35
29
  # input_line
36
30
  rule(:input_line => simple(:data_expr)) {
37
31
  TypeDataExpr.check(data_expr)
38
- ConditionLine.new(:input, data_expr)
32
+ Naming.InputLine(data_expr)
39
33
  }
40
34
 
41
35
  # output_line
42
36
  rule(:output_line => simple(:data_expr)) {
43
37
  TypeDataExpr.check(data_expr)
44
- ConditionLine.new(:output, data_expr)
38
+ Naming.OutputLine(data_expr)
45
39
  }
46
40
 
47
41
  # param_line
@@ -49,13 +43,13 @@ module Pione
49
43
  unless TypeAssignment.match(param) or TypeParameters.match(param)
50
44
  raise PioneModelTypeError.new(param, TypeAssignment)
51
45
  end
52
- ConditionLine.new(:param, param)
46
+ Naming.ParamLine(param)
53
47
  }
54
48
 
55
49
  # feature_line
56
50
  rule(:feature_line => simple(:feature)) {
57
51
  TypeFeature.check(feature)
58
- ConditionLine.new(:feature, feature)
52
+ Naming.FeatureLine(feature)
59
53
  }
60
54
  end
61
55
  end
@@ -95,7 +95,7 @@ module Pione
95
95
  @socket.close
96
96
  @socket = open_socket
97
97
  if Global.show_presence_notifier
98
- puts "tuple space receiver disconnected"
98
+ puts "tuple space receiver disconnected: %s" % e
99
99
  end
100
100
  rescue Exception
101
101
  # ignore
@@ -1,3 +1,4 @@
1
1
  module Pione
2
- VERSION = "0.1.0"
2
+ # version of pione
3
+ VERSION = "0.1.1"
3
4
  end
@@ -29,6 +29,7 @@ Gem::Specification.new do |gem|
29
29
  gem.add_dependency "parslet", "~> 1.4.0"
30
30
  gem.add_dependency "uuidtools", "~> 2.1.3"
31
31
  gem.add_dependency "highline", "~> 1.6.15"
32
+ gem.add_dependency "naming"
32
33
 
33
34
  # for dropbox resource
34
35
  gem.add_dependency "dropbox-sdk"
@@ -46,4 +47,5 @@ Gem::Specification.new do |gem|
46
47
 
47
48
  # for documentation
48
49
  gem.add_development_dependency "yard"
50
+ gem.add_development_dependency "redcarpet"
49
51
  end
@@ -0,0 +1,5 @@
1
+ require_relative '../test-util'
2
+
3
+ describe 'Pione::Parser::DocumentParser' do
4
+ TestUtil::Parser.spec(Pione::Parser::DocumentParser, __FILE__, self)
5
+ end
@@ -0,0 +1,62 @@
1
+ toplevel_element:
2
+ valid:
3
+ # parameter line
4
+ - "param $X := 1"
5
+ # parameter block
6
+ - |
7
+ Param
8
+ $X := 1
9
+ $Y := 2
10
+ $Z := 3
11
+ End
12
+ # rule definition
13
+ - |
14
+ Rule Test
15
+ input '*.txt'
16
+ output '{$*}.result'
17
+ Action
18
+ rev {$I[1]} > {$O[1]}
19
+ End
20
+ # assignment
21
+ - "$X := 1"
22
+ param_block:
23
+ valid:
24
+ # empty block
25
+ - |
26
+ Param
27
+ End
28
+ # one line block
29
+ - |
30
+ Param
31
+ $X := 1
32
+ End
33
+ # multi line block
34
+ - |
35
+ Param
36
+ $X := 1
37
+ $Y := 2
38
+ $Z := 3
39
+ End
40
+ # multi line with empty line
41
+ - |
42
+ Param
43
+ $X := 1
44
+
45
+ $Y := 2
46
+ End
47
+ # one line with comment
48
+ - |
49
+ Param
50
+ # param $X := 1
51
+ $X := 1
52
+ End
53
+ # multi line with comments
54
+ - |
55
+ Param
56
+ # param $X := 1
57
+ $X := 1
58
+ # param $Y := 2
59
+ $Y := 2
60
+ # param $Z := 3
61
+ $Z := 3
62
+ End
@@ -1,6 +1,15 @@
1
- require_relative 'test-util'
1
+ require_relative '../test-util'
2
2
 
3
3
  src = <<DOCUMENT
4
+ Param
5
+ $P1 := "a"
6
+ $P2 := "b"
7
+ $P3 := "c"
8
+ End
9
+
10
+ param $P4 := "d"
11
+ param $P5 := "e"
12
+
4
13
  $X := 1
5
14
 
6
15
  Rule Main
@@ -57,7 +66,18 @@ describe 'Document' do
57
66
  doc["&main:RuleC"].should.kind_of(Model::Rule)
58
67
  end
59
68
 
60
- it 'should have global variable' do
69
+ it 'should have document parameters' do
70
+ doc = Document.parse(src)
71
+ doc.params["P1"].should == "a".to_pione
72
+ doc.params["P2"].should == "b".to_pione
73
+ doc.params["P3"].should == "c".to_pione
74
+ doc.params["P4"].should == "d".to_pione
75
+ doc.params["P5"].should == "e".to_pione
76
+ user_params = doc.params.data.select{|var, val| var.user_param}.map{|var, val| var.name}
77
+ user_params.sort.should == ["P1", "P2", "P3", "P4", "P5"]
78
+ end
79
+
80
+ it 'should have document variable bindings' do
61
81
  doc = Document.parse(src)
62
82
  doc["&main:Main"].params["X"].should == 1.to_pione
63
83
  doc["&main:RuleA"].params["X"].should == 1.to_pione
@@ -79,7 +79,7 @@ module TestUtil::Parser
79
79
  context.describe name do
80
80
  if strings = testcase["valid"]
81
81
  strings.each do |string|
82
- it "should parse as #{name}: #{string}" do
82
+ it "should parse as %s:%s%s" % [name, string.include?("\n") ? "\n" : " ", string.chomp] do
83
83
  should.not.raise(Parslet::ParseFailed) do
84
84
  parser.new.send(name).parse(string)
85
85
  end
@@ -89,7 +89,7 @@ module TestUtil::Parser
89
89
 
90
90
  if strings = testcase["invalid"]
91
91
  strings.each do |string|
92
- it "should fail when parsing as #{name}: #{string}" do
92
+ it "should fail when parsing as %s:%s%s" % [name, string.include?("\n") ? "\n" : "", string.chomp] do
93
93
  should.raise(Parslet::ParseFailed) do
94
94
  parser.new.send(name).parse(string)
95
95
  end
@@ -120,7 +120,7 @@ module TestUtil::Transformer
120
120
  testcases.instance_eval(&b)
121
121
  context.describe name do
122
122
  testcases.each do |tc|
123
- it "should get #{name}: #{tc.string}" do
123
+ it "should get %s:%s%s" % [name, tc.string.include?("\n") ? "\n" : "", tc.string.chomp] do
124
124
  res = DocumentTransformer.new.apply(
125
125
  DocumentParser.new.send(parser).parse(tc.string)
126
126
  )
@@ -1,57 +1,52 @@
1
1
  require_relative '../test-util'
2
2
 
3
- ConditionLine = Transformer::RuleDefinitionTransformer::ConditionLine
4
-
5
3
  describe 'Pione::Transformer::RuleDefinitionTransformer' do
6
4
  transformer_spec("input_line", :input_line) do
7
5
  tc("input '*.txt'") do
8
- ConditionLine.new(:input, DataExpr.new("*.txt"))
6
+ Naming.InputLine(DataExpr.new("*.txt"))
9
7
  end
10
8
  end
11
9
 
12
10
  transformer_spec("output_line", :output_line) do
13
11
  tc("output '*.txt'") do
14
- ConditionLine.new(:output, DataExpr.new("*.txt"))
12
+ Naming.OutputLine(DataExpr.new("*.txt"))
15
13
  end
16
14
  end
17
15
 
18
16
  transformer_spec("param_line", :param_line) do
19
17
  tc("param {var: 1}") do
20
- ConditionLine.new(:param, {"var" => 1}.to_params)
18
+ Naming.ParamLine({"var" => 1}.to_params)
21
19
  end
22
20
  tc("param {var1: 1, var2: 2}") do
23
- ConditionLine.new(:param, {"var1" => 1, "var2" => 2}.to_params)
21
+ Naming.ParamLine({"var1" => 1, "var2" => 2}.to_params)
24
22
  end
25
23
  end
26
24
 
27
25
  transformer_spec("feature_line", :feature_line) do
28
26
  tc("feature +A") do
29
- ConditionLine.new(
30
- :feature,
31
- Feature::RequisiteExpr.new("A")
32
- )
27
+ Naming.FeatureLine(Feature::RequisiteExpr.new("A"))
33
28
  end
34
29
  end
35
30
 
36
- transformer_spec("rule_definition", :rule_definitions) do
37
- tc(<<STRING) do
38
- Rule Test
39
- input '*.a'
40
- output '{$INPUT[1].MATCH[1]}.b'
41
- Action
42
- echo "test" > {$OUTPUT[1].NAME}
43
- End
44
- STRING
45
- [ActionRule.new(
46
- RuleExpr.new(Package.new("main"), "Test"),
47
- RuleCondition.new(
48
- [ DataExpr.new('*.a') ],
49
- [ DataExpr.new('{$INPUT[1].MATCH[1]}.b') ],
50
- Parameters.empty,
51
- Feature.empty
52
- ),
53
- ActionBlock.new("echo \"test\" > {$OUTPUT[1].NAME}\n")
54
- )]
31
+ transformer_spec("rule_definition", :rule_definition) do
32
+ tc(<<-STRING) do
33
+ Rule Test
34
+ input '*.a'
35
+ output '{$INPUT[1].MATCH[1]}.b'
36
+ Action
37
+ echo "test" > {$OUTPUT[1].NAME}
38
+ End
39
+ STRING
40
+ ActionRule.new(
41
+ RuleExpr.new(Package.new("main"), "Test"),
42
+ RuleCondition.new(
43
+ [ DataExpr.new('*.a') ],
44
+ [ DataExpr.new('{$INPUT[1].MATCH[1]}.b') ],
45
+ Parameters.empty,
46
+ Feature.empty
47
+ ),
48
+ ActionBlock.new(" echo \"test\" > {$OUTPUT[1].NAME}\n")
49
+ )
55
50
  end
56
51
 
57
52
  tc(<<-STRING) do
@@ -59,23 +54,23 @@ STRING
59
54
  input '*.a'
60
55
  output '{$INPUT[1].MATCH[1]}.b'
61
56
  Flow
62
- rule TestA
63
- rule TestB
57
+ rule TestA
58
+ rule TestB
64
59
  End
65
60
  STRING
66
- [ FlowRule.new(
67
- RuleExpr.new(Package.new("main"), "Test"),
68
- RuleCondition.new(
69
- [ DataExpr.new('*.a') ],
70
- [ DataExpr.new('{$INPUT[1].MATCH[1]}.b') ],
71
- Parameters.empty,
72
- Feature.empty
73
- ),
74
- FlowBlock.new(
75
- CallRule.new(RuleExpr.new(Package.new("main"), "TestA")),
76
- CallRule.new(RuleExpr.new(Package.new("main"), "TestB"))
77
- )
78
- )]
61
+ FlowRule.new(
62
+ RuleExpr.new(Package.new("main"), "Test"),
63
+ RuleCondition.new(
64
+ [ DataExpr.new('*.a') ],
65
+ [ DataExpr.new('{$INPUT[1].MATCH[1]}.b') ],
66
+ Parameters.empty,
67
+ Feature.empty
68
+ ),
69
+ FlowBlock.new(
70
+ CallRule.new(RuleExpr.new(Package.new("main"), "TestA")),
71
+ CallRule.new(RuleExpr.new(Package.new("main"), "TestB"))
72
+ )
73
+ )
79
74
  end
80
75
 
81
76
  tc(<<-STRING) do
@@ -91,40 +86,40 @@ STRING
91
86
  rule Summarize
92
87
  End
93
88
  STRING
94
- [ FlowRule.new(
95
- RuleExpr.new(Package.new("main"), "Main"),
96
- RuleCondition.new(
97
- [Message.new(
98
- "except",
99
- DataExpr.new("*.txt"),
100
- DataExpr.new("summary.txt"))],
101
- [DataExpr.new("summary.txt")],
102
- Parameters.new({Variable.new("ConvertCharSet") => PioneBoolean.true}),
103
- Feature.empty
89
+ FlowRule.new(
90
+ RuleExpr.new(Package.new("main"), "Main"),
91
+ RuleCondition.new(
92
+ [Message.new(
93
+ "except",
94
+ DataExpr.new("*.txt"),
95
+ DataExpr.new("summary.txt"))],
96
+ [DataExpr.new("summary.txt")],
97
+ Parameters.new({Variable.new("ConvertCharSet") => PioneBoolean.true}),
98
+ Feature.empty
99
+ ),
100
+ FlowBlock.new(
101
+ ConditionalBlock.new(
102
+ Variable.new("ConvertCharset"),
103
+ { PioneBoolean.true => FlowBlock.new(
104
+ CallRule.new(Message.new(
105
+ "params",
106
+ RuleExpr.new(Package.new("main"), "NKF"),
107
+ PioneString.new("-w")
108
+ ))
109
+ )}
104
110
  ),
105
- FlowBlock.new(
106
- ConditionalBlock.new(
107
- Variable.new("ConvertCharset"),
108
- { PioneBoolean.true => FlowBlock.new(
109
- CallRule.new(Message.new(
110
- "params",
111
- RuleExpr.new(Package.new("main"), "NKF"),
112
- PioneString.new("-w")
113
- ))
114
- )}
115
- ),
116
- CallRule.new(
117
- RuleExpr.new(Package.new("main"), "CountChar")
118
- ),
119
- CallRule.new(
120
- RuleExpr.new(Package.new("main"), "Summarize")
121
- )
111
+ CallRule.new(
112
+ RuleExpr.new(Package.new("main"), "CountChar")
113
+ ),
114
+ CallRule.new(
115
+ RuleExpr.new(Package.new("main"), "Summarize")
122
116
  )
123
- )]
117
+ )
118
+ )
124
119
  end
125
120
  end
126
121
 
127
- transformer_spec("rule_definitions", :rule_definitions) do
122
+ transformer_spec("rule_definitions", :toplevel_elements) do
128
123
  tc(<<-STRING) do
129
124
  Rule TestA
130
125
  input '*.a'