pione 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -73,6 +73,11 @@ module Pione
73
73
  @name = name
74
74
  end
75
75
 
76
+ # --list-parameters
77
+ define_option('--list-params', 'show user parameter list in the document') do
78
+ @list_params = true
79
+ end
80
+
76
81
  attr_reader :tuple_space_server
77
82
  attr_reader :name
78
83
 
@@ -91,6 +96,8 @@ module Pione
91
96
  @relay = nil
92
97
  @filename = "-"
93
98
  @without_tuple_space_provider = false
99
+ @features = "^Interactive"
100
+ @list_params = false
94
101
  end
95
102
 
96
103
  private
@@ -172,10 +179,24 @@ module Pione
172
179
 
173
180
  def start
174
181
  read_process_document
182
+
183
+ if @list_params
184
+ print_parameter_list
185
+ exit
186
+ end
187
+
175
188
  write_tuples
176
189
  connect_relay if @relay
177
190
  start_agents
178
- start_tuple_space_provider unless @without_tuple_space_provider
191
+
192
+ # start tuple space provider with thread
193
+ # the thread is terminated when the client terminated
194
+ unless @without_tuple_space_provider
195
+ @start_tuple_space_provider_thread = Thread.new do
196
+ start_tuple_space_provider
197
+ end
198
+ end
199
+
179
200
  start_workers
180
201
  @agent = Agent[:process_manager].start(@tuple_space_server, @document, @params, @stream)
181
202
  @agent.running_thread.join
@@ -183,6 +204,14 @@ module Pione
183
204
  end
184
205
 
185
206
  def terminate
207
+ # kill the thread for starting tuple space provider
208
+ if @start_tuple_space_provider_thread
209
+ if @start_tuple_space_provider_thread.alive?
210
+ @start_tuple_space_provider_thread.kill
211
+ end
212
+ end
213
+
214
+ # terminate tuple space provider
186
215
  if @tuple_space_provider
187
216
  @tuple_space_provider.terminate
188
217
  end
@@ -244,7 +273,7 @@ module Pione
244
273
 
245
274
  def start_workers
246
275
  @task_worker.times do
247
- Agent[:task_worker].spawn(Global.front, Util.generate_uuid, @features)
276
+ Thread.new { Agent[:task_worker].spawn(Global.front, Util.generate_uuid, @features) }
248
277
  end
249
278
  end
250
279
 
@@ -268,6 +297,16 @@ module Pione
268
297
  rescue Relay::RelaySocket::AuthError
269
298
  abort("You failed authentication to connect the relay server: %s" % @relay_ref.__drburi)
270
299
  end
300
+
301
+ # Print parameter list of the document.
302
+ #
303
+ # @return [void]
304
+ def print_parameter_list
305
+ puts "Parameters:"
306
+ @document.params.data.select{|var, val| var.user_param}.each do |var, val|
307
+ puts " %s := %s" % [var.name, val.textize]
308
+ end
309
+ end
271
310
  end
272
311
  end
273
312
  end
@@ -30,16 +30,27 @@ TXT
30
30
  if @readline_mode
31
31
  require 'readline'
32
32
  restore_history
33
+ buf = ""
34
+ mark = ">"
33
35
 
34
36
  # start loop
35
- while buf = Readline.readline(Terminal.red("> "), true)
37
+ while buf += Readline.readline(Terminal.red("#{mark} "), true)
36
38
  if /[^\s]/.match(buf)
37
39
  # don't record if previous line is the same
38
40
  if Readline::HISTORY.size > 1 && Readline::HISTORY[-2] == buf
39
41
  Readline::HISTORY.pop
40
42
  end
41
- # print parsing result
42
- print_result(buf)
43
+ if buf[-1] == "\\"
44
+ buf[-1] = "\n"
45
+ mark = "+"
46
+ next
47
+ else
48
+ # print parsing result
49
+ puts buf
50
+ print_result(buf)
51
+ buf = ""
52
+ mark = ">"
53
+ end
43
54
  else
44
55
  # don't record if it is an empty line
45
56
  Readline::HISTORY.pop
@@ -56,7 +56,10 @@ TXT
56
56
  begin
57
57
  @parent_front.uuid
58
58
  rescue => e
59
- abort("pione-task-worker cannot get the parent front server: %s" % e)
59
+ if Pione.debug_mode?
60
+ debug_message "pione-task-worker cannot get the parent front server: %s" % e
61
+ end
62
+ abort
60
63
  end
61
64
  end
62
65
 
@@ -61,13 +61,13 @@ TXT
61
61
  # start provider activity
62
62
  @tuple_space_provider.start
63
63
 
64
- # set my URI to caller front as its provider
65
- unless @no_parent_mode
66
- @parent_front.set_tuple_space_provider(Global.front.uri)
67
- end
68
-
69
- # wait
70
64
  begin
65
+ # set my URI to caller front as its provider
66
+ unless @no_parent_mode
67
+ @parent_front.set_tuple_space_provider(Global.front.uri)
68
+ end
69
+
70
+ # wait
71
71
  DRb.thread.join
72
72
  rescue DRb::DRbConnError, DRb::ReplyReaderThreadError
73
73
  terminate
@@ -76,7 +76,6 @@ TXT
76
76
 
77
77
  # @api private
78
78
  def terminate
79
- puts "terminate %s" % program_name
80
79
  @tuple_space_provider.terminate
81
80
  super
82
81
  rescue DRb::DRbConnError, DRb::ReplyReaderThreadError
@@ -41,10 +41,16 @@ module Pione::Model
41
41
  vtable.set(@variable, @expr)
42
42
  end
43
43
 
44
+ # Set truth of toplevel assignment.
44
45
  def set_toplevel(b)
45
46
  @variable.set_toplevel(b)
46
47
  end
47
48
 
49
+ # Set truth of user parameter.
50
+ def set_user_param(b)
51
+ @variable.set_user_param(b)
52
+ end
53
+
48
54
  # Returns true if the assignment is defined in toplevel.
49
55
  # @return [Boolean]
50
56
  # true if the assignment is defined in toplevel
@@ -30,12 +30,16 @@ module Pione::Model
30
30
  false
31
31
  end
32
32
 
33
- # Returns PIONE model type of the message result according to type
34
- # interface.
33
+ # Return PIONE model type of the message result according to type interface.
34
+ #
35
35
  # @return [Symbol]
36
36
  # PIONE model type
37
37
  def pione_model_type
38
- @receiver.pione_model_type.method_interface[@name.to_s].output
38
+ if interface = @receiver.pione_model_type.method_interface[@name.to_s]
39
+ interface.output
40
+ else
41
+ raise MethodNotFound.new(@name.to_s, self)
42
+ end
39
43
  end
40
44
 
41
45
  # Evaluates the application expression and returns application result.
@@ -6,11 +6,16 @@ module Pione::Model
6
6
 
7
7
  attr_reader :name
8
8
 
9
+ # true if the variable is user parameter
10
+ attr_reader :user_param
11
+
9
12
  # Creates a variable with name.
10
13
  # @param [String] name
11
14
  # variable name
12
15
  def initialize(name)
13
16
  @name = name.to_s
17
+ @toplevel = nil
18
+ @user_param = nil
14
19
  super()
15
20
  end
16
21
 
@@ -33,10 +38,16 @@ module Pione::Model
33
38
  true
34
39
  end
35
40
 
41
+ # Set truth of toplevel variable.
36
42
  def set_toplevel(b)
37
43
  @toplevel = b
38
44
  end
39
45
 
46
+ # Set truth of user parameter.
47
+ def set_user_param(b)
48
+ @user_param = b
49
+ end
50
+
40
51
  # Returns true if the variable is defined in toplevel.
41
52
  # @return [Boolean]
42
53
  # true if the variable is defined in toplevel
@@ -65,6 +65,7 @@ module Pione
65
65
  :keyword_input => 'input',
66
66
  :keyword_output => 'output',
67
67
  :keyword_param => 'param',
68
+ :keyword_Param => 'Param',
68
69
  :keyword_feature => 'feature',
69
70
  :keyword_rule => 'rule',
70
71
  :keyword_if => 'if',
@@ -102,24 +103,45 @@ module Pione
102
103
  # @return [Parslet::Atoms::Entity] +digit+ atom
103
104
  rule(:digit) { match('[0-9]') }
104
105
 
105
- # @!attribute [r] space
106
- # +space+ matches sequences of space character or tab.
107
- # @return [Parslet::Atoms::Entity] +space+ atom
108
- rule(:space) { match("[ \t]").repeat(1) }
106
+ # @!method space
107
+ #
108
+ # Return +space+ parser. +space+ matches sequences of space character,
109
+ # tab, or comment.
110
+ #
111
+ # @return [Parslet::Atoms::Entity] +space+ atom
112
+ rule(:space) {
113
+ ( match("[ \t]") |
114
+ str("#") >> ((str("\n") | any.absent?).absent? >> any).repeat
115
+ ).repeat(1)
116
+ }
109
117
 
110
- # @!attribute [r] space?
111
- # +space?+ matches +space+ atom or empty.
112
- # @return [Parslet::Atoms::Entity] +space?+ atom
118
+ # @!method space?
119
+ #
120
+ # Return +space?+ parser. +space?+ matches +space+ or empty.
121
+ #
122
+ # @return [Parslet::Atoms::Entity]
123
+ # +space?+ parser
113
124
  rule(:space?) { space.maybe }
114
125
 
115
- # @!attribute [r] pad
116
- # +space?+ matches space character, tab, and newline.
117
- # @return [Parslet::Atoms::Entity] +pad+ atom
118
- rule(:pad) { match("[ \t\n]").repeat(1) }
126
+ # @!method pad
127
+ #
128
+ # Return +pad+ parser. +pad+ matches sequences of space character, tab,
129
+ # newline, or comment.
130
+ #
131
+ # @return [Parslet::Atoms::Entity]
132
+ # +pad+ parser
133
+ rule(:pad) {
134
+ ( match("[ \t\n]") |
135
+ str("#") >> ((str("\n") | any.absent?).absent? >> any).repeat
136
+ ).repeat(1)
137
+ }
119
138
 
120
- # @!attribute [r] pad?
121
- # +space?+ matches +pad+ atom or empty.
122
- # @return [Parslet::Atoms::Entity] +pad?+ atom
139
+ # @!method pad?
140
+ #
141
+ # Return +pad?+ parser. +pad?+ matches +pad+ or empty.
142
+ #
143
+ # @return [Parslet::Atoms::Entity]
144
+ # +pad?+ parser
123
145
  rule(:pad?) { pad.maybe }
124
146
 
125
147
  # @!attribute [r] line_end
@@ -10,15 +10,54 @@ module Pione
10
10
  include BlockParser
11
11
  include RuleDefinitionParser
12
12
 
13
- def parse(str)
14
- super(str.gsub(/^(?!#!)#.*/, ""))
15
- end
16
-
17
13
  #
18
14
  # root
19
15
  #
20
16
 
21
- root(:rule_definitions)
17
+ root(:toplevel_elements)
18
+
19
+ # @!method toplevel_elements
20
+ #
21
+ # Return +toplevel_elements+ parser. This is root parser for reading a
22
+ # document.
23
+ #
24
+ # @return [Parslet::Atoms::Entity]
25
+ # +toplevel_elements+ parser
26
+ rule(:toplevel_elements) {
27
+ (empty_lines? >> space? >> toplevel_element >> empty_lines?).repeat
28
+ }
29
+
30
+ # @!method toplevel_element
31
+ #
32
+ # Return +toplevel_element+ parser.
33
+ #
34
+ # @return [Parslet::Atoms::Entity]
35
+ # +toplevel_element+ parser
36
+ #
37
+ # @example
38
+ # # document toplevel assignment
39
+ # DocumentParser.toplevel_element.parse("$X := 1")
40
+ # @example
41
+ # # define rule
42
+ # DocumentParser.new.toplevel_element.parse <<TXT
43
+ # Rule Main
44
+ # input '*.txt'
45
+ # ...
46
+ # Flow
47
+ # rule SubRule
48
+ # ...
49
+ # End
50
+ # TXT
51
+ # @example
52
+ # # you can write any expressions in toplevel but it is ignored
53
+ # DocumentParser.new.toplevel_element.parse("1 + 1")
54
+ rule(:toplevel_element) {
55
+ rule_definition |
56
+ param_block |
57
+ param_line |
58
+ assignment_line |
59
+ expr
60
+ }
22
61
 
23
62
  #
24
63
  # document statement
@@ -34,6 +73,44 @@ module Pione
34
73
  require_line
35
74
  }
36
75
 
76
+ # @!method assignment_line
77
+ #
78
+ # Return +assignment_line+ parser.
79
+ #
80
+ # @return [Parslet::Atoms::Entity]
81
+ # +assignment_line+ parser
82
+ #
83
+ # @example
84
+ # DocumentParser.new.assignment_line("$X := 1")
85
+ rule(:assignment_line) {
86
+ space? >> assignment >> line_end
87
+ }
88
+
89
+ # @!method param_block
90
+ #
91
+ # Return +param_block+ parser.
92
+ #
93
+ # @return [Parslet::Atoms::Entity]
94
+ # +param block+ parser
95
+ #
96
+ # @example
97
+ # DocumentParser.new.param_block <<TXT
98
+ # Param
99
+ # $X := 1
100
+ # $Y := 2
101
+ # $Z := 3
102
+ # End
103
+ # TXT
104
+ rule(:param_block) {
105
+ ( space? >>
106
+ keyword_Param >>
107
+ line_end >>
108
+ (assignment_line | pad).repeat >>
109
+ (keyword_End | syntax_error("it should be block end", :keyword_End)) >>
110
+ line_end
111
+ ).as(:param_block)
112
+ }
113
+
37
114
  # package_line
38
115
  rule(:package_line) {
39
116
  ( space? >>
@@ -10,35 +10,6 @@ module Pione
10
10
  include FlowElementParser
11
11
  include BlockParser
12
12
 
13
- # @!attribute [r] rule_definitions
14
- # @return [Parslet::Atoms::Entity] toplevel element list
15
- rule(:rule_definitions) {
16
- (empty_lines? >> space? >> toplevel_element >> empty_lines?).repeat
17
- }
18
-
19
- # @!attribute [r] toplevel_element
20
- # @return [Parslet::Atoms::Entity] toplevel element
21
- # @example
22
- # # document toplevel assignment
23
- # $X := 1
24
- # @example
25
- # # define rule
26
- # Rule Main
27
- # input '*.txt'
28
- # ...
29
- # Flow
30
- # rule SubRule
31
- # ...
32
- # End
33
- # @example
34
- # # you can write any expressions in toplevel but it is ignored
35
- # 1 + 1
36
- rule(:toplevel_element) {
37
- rule_definition |
38
- assignment |
39
- expr
40
- }
41
-
42
13
  # @!attribute [r] rule_definition
43
14
  # @return [Parslet::Atoms::Entity] rule definition
44
15
  # @example
@@ -50,7 +21,8 @@ module Pione
50
21
  # ...
51
22
  # End
52
23
  rule(:rule_definition) {
53
- ( rule_header >>
24
+ ( space? >>
25
+ rule_header >>
54
26
  rule_conditions >>
55
27
  block.as(:block)
56
28
  ).as(:rule_definition)