pione 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -2
- data/Rakefile +1 -1
- data/example/Fib/Fib.pione +5 -5
- data/example/SequentialProcess/SequentialProcess.pione +69 -0
- data/lib/pione.rb +7 -11
- data/lib/pione/agent/input-generator.rb +3 -2
- data/lib/pione/agent/task-worker.rb +6 -3
- data/lib/pione/agent/trivial-routine-worker.rb +6 -5
- data/lib/pione/command/basic-command.rb +7 -1
- data/lib/pione/command/child-process.rb +5 -1
- data/lib/pione/command/front-owner-command.rb +15 -4
- data/lib/pione/command/pione-client.rb +16 -9
- data/lib/pione/command/pione-syntax-checker.rb +45 -30
- data/lib/pione/command/pione-task-worker.rb +22 -13
- data/lib/pione/command/pione-tuple-space-provider.rb +4 -2
- data/lib/pione/command/pione-tuple-space-receiver.rb +10 -5
- data/lib/pione/front/task-worker-owner.rb +1 -0
- data/lib/pione/model/basic-model.rb +3 -0
- data/lib/pione/model/block.rb +2 -1
- data/lib/pione/model/call-rule.rb +10 -0
- data/lib/pione/model/feature-expr.rb +143 -54
- data/lib/pione/model/float.rb +0 -1
- data/lib/pione/model/rule-expr.rb +132 -7
- data/lib/pione/model/rule.rb +53 -17
- data/lib/pione/model/ticket-expr.rb +124 -0
- data/lib/pione/parser/expr-parser.rb +75 -38
- data/lib/pione/parser/literal-parser.rb +14 -0
- data/lib/pione/parser/parslet-extension.rb +143 -0
- data/lib/pione/rule-handler/flow-handler.rb +33 -3
- data/lib/pione/system/global.rb +10 -3
- data/lib/pione/transformer.rb +24 -0
- data/lib/pione/transformer/block-transformer.rb +6 -5
- data/lib/pione/transformer/document-transformer.rb +5 -10
- data/lib/pione/transformer/expr-transformer.rb +56 -30
- data/lib/pione/transformer/feature-expr-transformer.rb +9 -5
- data/lib/pione/transformer/flow-element-transformer.rb +21 -23
- data/lib/pione/transformer/literal-transformer.rb +39 -35
- data/lib/pione/transformer/rule-definition-transformer.rb +8 -6
- data/lib/pione/transformer/transformer-module.rb +7 -5
- data/lib/pione/tuple/ticket-tuple.rb +8 -0
- data/lib/pione/util/{message.rb → console-message.rb} +54 -26
- data/lib/pione/version.rb +1 -1
- data/pione.gemspec +2 -1
- data/test/model/spec_feature-expr.rb +18 -3
- data/test/model/spec_feature-expr.yml +28 -16
- data/test/model/spec_ticket-expr.rb +67 -0
- data/test/parser/spec_expr-parser.yml +74 -25
- data/test/parser/spec_literal-parser.yml +11 -0
- data/test/test-util.rb +1 -1
- data/test/transformer/spec_expr-transformer.rb +27 -54
- data/test/transformer/spec_literal-transformer.rb +6 -0
- metadata +29 -7
- data/lib/pione/parser/syntax-error.rb +0 -61
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'pione/transformer/transformer-module'
|
2
|
+
require 'pione/transformer/literal-transformer'
|
3
|
+
require 'pione/transformer/feature-expr-transformer'
|
4
|
+
require 'pione/transformer/expr-transformer'
|
5
|
+
require 'pione/transformer/flow-element-transformer'
|
6
|
+
require 'pione/transformer/block-transformer'
|
7
|
+
require 'pione/transformer/rule-definition-transformer'
|
8
|
+
require 'pione/transformer/document-transformer'
|
9
|
+
|
10
|
+
module Pione
|
11
|
+
# Transformer is a name space for PIONE document transformers and provides
|
12
|
+
# utilities.
|
13
|
+
module Transformer
|
14
|
+
# Transform by applying DocumentTransformer.
|
15
|
+
#
|
16
|
+
# @param syntax_tree [Hash]
|
17
|
+
# target syntax tree
|
18
|
+
# @return [Object]
|
19
|
+
# transformed object
|
20
|
+
def self.document(syntax_tree)
|
21
|
+
DocumentTransformer.new.apply(syntax_tree)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,21 +1,22 @@
|
|
1
1
|
module Pione
|
2
2
|
module Transformer
|
3
|
+
# BlockTransformer is a transformer for syntax tree of blocks.
|
3
4
|
module BlockTransformer
|
4
5
|
include TransformerModule
|
5
6
|
|
6
|
-
# flow_block
|
7
|
+
# Transform +:flow_block+ as Model::FlowBlock.
|
7
8
|
rule(:flow_block => sequence(:elements)) {
|
8
9
|
FlowBlock.new(*elements)
|
9
10
|
}
|
10
11
|
|
11
|
-
# action_block
|
12
|
+
# Transform +:action_block+ as Model::ActionBlock.
|
12
13
|
rule(:action_block =>
|
13
14
|
{ :key => simple(:keyword_Action),
|
14
15
|
:content => simple(:content) }
|
15
16
|
) {
|
16
|
-
|
17
|
-
ActionBlock.new(
|
18
|
-
set_line_and_column(line_and_column)
|
17
|
+
val = content.str
|
18
|
+
ActionBlock.new(val).tap do |x|
|
19
|
+
x.set_line_and_column(keyword_Action.line_and_column)
|
19
20
|
end
|
20
21
|
}
|
21
22
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Pione
|
2
2
|
module Transformer
|
3
|
+
# DocumentTransformer is a transformer for syntax tree of document.
|
3
4
|
class DocumentTransformer < Parslet::Transform
|
4
5
|
include LiteralTransformer
|
5
6
|
include FeatureExprTransformer
|
@@ -8,30 +9,24 @@ module Pione
|
|
8
9
|
include BlockTransformer
|
9
10
|
include RuleDefinitionTransformer
|
10
11
|
|
12
|
+
# @param package_name [String]
|
13
|
+
# package name of the document
|
11
14
|
def initialize(package_name="main")
|
12
15
|
super()
|
13
16
|
@current_package_name = package_name
|
14
17
|
Thread.current[:current_package_name] = @current_package_name
|
15
18
|
end
|
16
19
|
|
17
|
-
def apply(*args)
|
18
|
-
res = super
|
19
|
-
return res
|
20
|
-
end
|
21
|
-
|
22
20
|
def check_model_type(data, type)
|
23
21
|
data.pione_model_type == type
|
24
22
|
end
|
25
23
|
|
26
|
-
#
|
27
|
-
# statement
|
28
|
-
#
|
29
|
-
|
24
|
+
# Transform +:param_block+ as Naming::ParamBlock.
|
30
25
|
rule(:param_block => sequence(:assignment_list)) {
|
31
26
|
Naming.ParamBlock(assignment_list)
|
32
27
|
}
|
33
28
|
|
34
|
-
# package
|
29
|
+
# Transform +:package+ as Naming::Package.
|
35
30
|
rule(:package => subtree(:tree)) {
|
36
31
|
@current_package = Naming.Package(tree[:package_name].to_s)
|
37
32
|
}
|
@@ -1,62 +1,74 @@
|
|
1
1
|
module Pione
|
2
2
|
module Transformer
|
3
|
-
|
4
|
-
ParametersElement = Struct.new(:key, :value)
|
5
|
-
|
3
|
+
# ExprTransformer is a transformer for syntax tree of expressions.
|
6
4
|
module ExprTransformer
|
7
5
|
include TransformerModule
|
8
6
|
|
9
|
-
# expr_operator_application
|
7
|
+
# Transform +:expr_operator_application+ as Model::BinaryOperator.
|
10
8
|
rule(:expr_operator_application =>
|
11
9
|
{ :left => simple(:left),
|
12
10
|
:operator => simple(:operator),
|
13
11
|
:right => simple(:right) }) {
|
14
|
-
Model::BinaryOperator.new(operator, left, right)
|
12
|
+
Model::BinaryOperator.new(operator.to_s, left, right)
|
15
13
|
}
|
16
14
|
|
17
|
-
# expr
|
15
|
+
# Extract the content of +:expr+.
|
18
16
|
rule(:expr => simple(:obj)) { obj }
|
19
17
|
|
20
|
-
# receiver
|
18
|
+
# Transform receiver and messages as Model::Message.
|
21
19
|
rule({ :receiver => simple(:receiver),
|
22
20
|
:messages => sequence(:messages) }) {
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
messages.inject(receiver) do |rec, msg|
|
22
|
+
Model::Message.new(msg.name, rec, *msg.parameters)
|
23
|
+
end
|
24
|
+
}
|
25
|
+
|
26
|
+
# Transform receiver and reverse message as Model::Message.
|
27
|
+
rule({ :receiver => simple(:receiver),
|
28
|
+
:reverse_messages => sequence(:messages) }) {
|
29
|
+
messages.reverse.inject(receiver) do |obj, msg|
|
30
|
+
Model::Message.new(msg.name, obj, *msg.parameters)
|
26
31
|
end
|
27
|
-
obj
|
28
32
|
}
|
33
|
+
|
34
|
+
# Transform receiver and indexes as Model::Message.
|
29
35
|
rule({ :receiver => simple(:receiver),
|
30
36
|
:indexes => sequence(:indexes) }) {
|
31
|
-
|
32
|
-
|
33
|
-
obj = Model::Message.new("[]", obj, *msg.parameters)
|
37
|
+
indexes.inject(receiver) do |rec, msg|
|
38
|
+
Model::Message.new("[]", rec, *msg.parameters)
|
34
39
|
end
|
35
|
-
obj
|
36
40
|
}
|
37
41
|
|
38
|
-
# message
|
42
|
+
# Transform +:message+ with no parameters as OpenStruct.
|
39
43
|
rule(:message => {:message_name => simple(:name)}) {
|
40
|
-
|
44
|
+
OpenStruct.new(name: name)
|
41
45
|
}
|
46
|
+
|
47
|
+
# Transform +:message+ with no parameters as OpenStruct.
|
42
48
|
rule(:message =>
|
43
|
-
|
44
|
-
|
45
|
-
|
49
|
+
{ :message_name => simple(:name),
|
50
|
+
:message_parameters => nil }) {
|
51
|
+
OpenStruct.new(name: name)
|
46
52
|
}
|
53
|
+
|
54
|
+
# Transform +:message+ with parameters as OpenStruct.
|
47
55
|
rule(:message =>
|
48
|
-
|
49
|
-
|
50
|
-
|
56
|
+
{ :message_name => simple(:name),
|
57
|
+
:message_parameters => sequence(:parameters) }) {
|
58
|
+
OpenStruct.new(name, parameters)
|
51
59
|
}
|
60
|
+
|
61
|
+
# Transform +:message+ with parameters as OpenStruct.
|
52
62
|
rule(:message =>
|
53
|
-
|
54
|
-
|
55
|
-
|
63
|
+
{ :message_name => simple(:name),
|
64
|
+
:message_parameters => simple(:arg) }) {
|
65
|
+
OpenStruct.new(name: name, parameters: arg)
|
56
66
|
}
|
57
67
|
|
58
|
-
# rule_expr
|
68
|
+
# Extract the content of +:rule_expr+.
|
59
69
|
rule(:rule_expr => simple(:rule)) { rule }
|
70
|
+
|
71
|
+
# Extract the content of +:rule_expr+ and set the package.
|
60
72
|
rule(:rule_expr => {
|
61
73
|
:package => simple(:package),
|
62
74
|
:expr => simple(:expr)
|
@@ -64,25 +76,39 @@ module Pione
|
|
64
76
|
expr.set_package(package)
|
65
77
|
}
|
66
78
|
|
67
|
-
# parameters
|
79
|
+
# Transform +:parameters+ as emtpy parameters.
|
68
80
|
rule(:parameters => nil) { Parameters.new({}) }
|
81
|
+
|
82
|
+
# Transform +:parameters+ as emtpy parameters.
|
69
83
|
rule(:parameters => simple(:elt)) {
|
70
84
|
Parameters.new({elt.key => elt.value})
|
71
85
|
}
|
86
|
+
|
87
|
+
# Transform +:parameters+ as parameters.
|
72
88
|
rule(:parameters => sequence(:list)) {
|
73
89
|
elts = Hash[*list.map{|elt| [elt.key, elt.value]}.flatten(1)]
|
74
90
|
Parameters.new(elts)
|
75
91
|
}
|
76
92
|
|
93
|
+
# Transform +:parameters_element+ as key and value pair.
|
77
94
|
rule(:parameters_element => {
|
78
95
|
:key => simple(:key),
|
79
96
|
:value => simple(:value)
|
80
97
|
}) {
|
81
|
-
|
98
|
+
var = Variable.new(key.str).tap do |x|
|
99
|
+
x.set_line_and_column(key.line_and_column)
|
100
|
+
end
|
101
|
+
OpenStruct.new(key: var, value: value)
|
82
102
|
}
|
83
103
|
|
104
|
+
# Transform +:index+ as name and parameters structure.
|
84
105
|
rule(:index => sequence(:args)) {
|
85
|
-
|
106
|
+
OpenStruct.new(name: "[]", parameters: args)
|
107
|
+
}
|
108
|
+
|
109
|
+
# Transform +:postpositional_parameters+ as parameters structure.
|
110
|
+
rule(:postpositional_parameters => simple(:parameters)) {
|
111
|
+
OpenStruct.new(name: "params", parameters: parameters)
|
86
112
|
}
|
87
113
|
end
|
88
114
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module Pione
|
2
2
|
module Transformer
|
3
|
+
# FeatureExprTransformer is a transformer for syntax tree of feature
|
4
|
+
# expressions.
|
3
5
|
module FeatureExprTransformer
|
4
6
|
include TransformerModule
|
5
7
|
|
6
|
-
# feature_name
|
7
|
-
#
|
8
|
+
# Transform +:feature_name+ as feature expression model corresponding to
|
9
|
+
# the operator.
|
8
10
|
rule(:atomic_feature =>
|
9
11
|
{ :operator => simple(:operator),
|
10
12
|
:symbol => simple(:symbol) }
|
@@ -22,6 +24,8 @@ module Pione
|
|
22
24
|
Feature::RestrictiveExpr.new(symbol.str)
|
23
25
|
end
|
24
26
|
end
|
27
|
+
|
28
|
+
# Transform +:atomic_feature+ as empty feature or boundless feature.
|
25
29
|
rule(:atomic_feature => {:symbol => simple(:symbol)}) {
|
26
30
|
case symbol
|
27
31
|
when "*"
|
@@ -31,12 +35,12 @@ module Pione
|
|
31
35
|
end
|
32
36
|
}
|
33
37
|
|
34
|
-
#
|
38
|
+
# Extract the content of +:feature_expr+.
|
35
39
|
rule(:feature_expr => simple(:expr)) do
|
36
40
|
expr
|
37
41
|
end
|
38
42
|
|
39
|
-
# feature conjunction
|
43
|
+
# Transform +:feature conjunction+ as Feature::AndExpr.
|
40
44
|
rule(:feature_conjunction => {
|
41
45
|
:left => simple(:left),
|
42
46
|
:right => simple(:right)
|
@@ -44,7 +48,7 @@ module Pione
|
|
44
48
|
Feature::AndExpr.new(left, right)
|
45
49
|
end
|
46
50
|
|
47
|
-
#
|
51
|
+
# Transform +:feature_disjunction+ as Feature::OrExpr.
|
48
52
|
rule(:feature_disjunction => {
|
49
53
|
:left => simple(:left),
|
50
54
|
:right => simple(:right)
|
@@ -1,37 +1,37 @@
|
|
1
1
|
module Pione
|
2
2
|
module Transformer
|
3
|
+
# FlowElementTransformer is a transformer for syntax tree of flow elements.
|
3
4
|
module FlowElementTransformer
|
4
5
|
include TransformerModule
|
5
6
|
|
6
|
-
#
|
7
|
+
# Extract the content of +:flow_elements+.
|
7
8
|
rule(:flow_elements => sequence(:elements)) {
|
8
9
|
elements
|
9
10
|
}
|
10
11
|
|
11
|
-
# call_rule
|
12
|
+
# Transform +:call_rule: as Model::CallRule.
|
12
13
|
rule(:call_rule => subtree(:rule_expr)) {
|
13
14
|
TypeRuleExpr.check(rule_expr)
|
14
15
|
CallRule.new(rule_expr)
|
15
16
|
}
|
16
17
|
|
17
|
-
# if_block
|
18
|
+
# Trasnform +:if_block+ as Model::ConditionalBlock.
|
18
19
|
rule(:if_block =>
|
19
20
|
{ :condition => simple(:condition),
|
20
21
|
:if_true_elements => sequence(:if_true),
|
21
22
|
:if_else_block => simple(:if_false)
|
22
23
|
}) {
|
23
|
-
block = { PioneBoolean.true => FlowBlock.new(*if_true) }
|
24
|
+
block = { Model::PioneBoolean.true => Model::FlowBlock.new(*if_true) }
|
24
25
|
block[:else] = if_false if if_false
|
25
|
-
ConditionalBlock.new(condition, block)
|
26
|
+
Model::ConditionalBlock.new(condition, block)
|
26
27
|
}
|
27
28
|
|
28
|
-
# else_block
|
29
|
-
rule(:else_block =>
|
30
|
-
|
31
|
-
FlowBlock.new(*elements)
|
29
|
+
# Transform +:else_block+ as Model::FlowBlock.
|
30
|
+
rule(:else_block => {:elements => sequence(:elements)}) {
|
31
|
+
Model::FlowBlock.new(*elements)
|
32
32
|
}
|
33
33
|
|
34
|
-
# case_block
|
34
|
+
# Transform +:case_block+ as Model::ConditionalBlock.
|
35
35
|
rule(:case_block =>
|
36
36
|
{ :condition => simple(:condition),
|
37
37
|
:when_blocks => sequence(:when_blocks),
|
@@ -41,26 +41,24 @@ module Pione
|
|
41
41
|
block[when_block.value] = when_block.body
|
42
42
|
end
|
43
43
|
block[:else] = else_block if else_block
|
44
|
-
ConditionalBlock.new(condition, block)
|
44
|
+
Model::ConditionalBlock.new(condition, block)
|
45
45
|
}
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
# when_block
|
47
|
+
# Transform +:when_block+ as Model::WhenBlock.
|
50
48
|
rule(:when_block =>
|
51
49
|
{ :value => simple(:value),
|
52
|
-
|
50
|
+
:elements => sequence(:elements) }
|
53
51
|
) {
|
54
|
-
|
52
|
+
OpenStruct.new(value: value, body: Model::FlowBlock.new(*elements))
|
55
53
|
}
|
56
54
|
|
57
|
-
# assignment
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
55
|
+
# Transform +:assignment+ as Model::Assignment.
|
56
|
+
rule(:assignment =>
|
57
|
+
{ :symbol => simple(:symbol),
|
58
|
+
:value => simple(:value) }
|
59
|
+
) {
|
60
|
+
Model::Assignment.new(symbol, value)
|
61
|
+
}
|
64
62
|
end
|
65
63
|
end
|
66
64
|
end
|
@@ -1,73 +1,77 @@
|
|
1
1
|
module Pione
|
2
2
|
module Transformer
|
3
|
+
# LiteralTransformer is a transformer for syntax tree of literals.
|
3
4
|
module LiteralTransformer
|
4
5
|
include TransformerModule
|
5
6
|
|
6
|
-
# boolean
|
7
|
+
# Tranform +:boolean+ as Model::PioneBoolean.
|
7
8
|
rule(:boolean => simple(:s)) do
|
8
|
-
line_and_column = s.line_and_column
|
9
9
|
val = (s == "true")
|
10
|
-
Model::PioneBoolean.new(val) do
|
11
|
-
set_line_and_column(line_and_column)
|
10
|
+
Model::PioneBoolean.new(val).tap do |x|
|
11
|
+
x.set_line_and_column(s.line_and_column)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
# string
|
15
|
+
# Transform +:string+ as Model::PioneString.
|
16
16
|
rule(:string => simple(:s)) do
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
# convert backslash notations
|
18
|
+
val = s.str.gsub(/\\(.)/){$1}
|
19
|
+
Model::PioneString.new(val).tap do |x|
|
20
|
+
x.set_line_and_column(s.line_and_column)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
# integer
|
24
|
+
# Transform +:integer+ as Model::PioneInteger.
|
24
25
|
rule(:integer => simple(:i)) do
|
25
|
-
|
26
|
-
|
27
|
-
set_line_and_column(line_and_column)
|
26
|
+
Model::PioneInteger.new(i.to_i).tap do |x|
|
27
|
+
x.set_line_and_column(i.line_and_column)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
# float
|
31
|
+
# Transform +:float+ as Model::PioneFloat.
|
32
32
|
rule(:float => simple(:f)) do
|
33
|
-
|
34
|
-
|
35
|
-
set_line_and_column(line_and_column)
|
33
|
+
Model::PioneFloat.new(f.to_f).tap do |x|
|
34
|
+
x.set_line_and_column(f.line_and_column)
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
|
-
# variable
|
40
|
-
rule(:variable => simple(:
|
41
|
-
|
42
|
-
|
43
|
-
set_line_and_column(line_and_column)
|
38
|
+
# Transform +:variable+ as Model::Variable.
|
39
|
+
rule(:variable => simple(:var)) do
|
40
|
+
Model::Variable.new(var.str).tap do |x|
|
41
|
+
x.set_line_and_column(var.line_and_column)
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
|
-
# data_name
|
48
|
-
# escape characters are substituted
|
45
|
+
# Transform +:data_name+ as Model::DataExpr.
|
49
46
|
rule(:data_name => simple(:name)) do
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
# convert backslash notations
|
48
|
+
val = name.str.gsub(/\\(.)/){$1}
|
49
|
+
Model::DataExpr.new(val).tap do |x|
|
50
|
+
x.set_line_and_column(name.line_and_column)
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
56
|
-
# package_name
|
54
|
+
# Transform +:package_name+ as Model::Package.
|
57
55
|
rule(:package_name => simple(:name)) do
|
58
|
-
|
59
|
-
Model::Package.new(
|
60
|
-
set_line_and_column(line_and_column)
|
56
|
+
val = name.str
|
57
|
+
Model::Package.new(val).tap do |x|
|
58
|
+
x.set_line_and_column(name.line_and_column)
|
61
59
|
end
|
62
60
|
end
|
63
61
|
|
64
|
-
# rule_name
|
62
|
+
# Transform +:rule_name+ as Model::RuleExpr.
|
65
63
|
rule(:rule_name => simple(:name)) do
|
64
|
+
package = Package.new(Thread.current[:current_package_name])
|
65
|
+
val = name.str
|
66
|
+
RuleExpr.new(package, val, Parameters.empty, TicketExpr.empty, TicketExpr.empty).tap do |x|
|
67
|
+
x.set_line_and_column(name.line_and_column)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# ticket
|
72
|
+
rule(:ticket => simple(:name)) do
|
66
73
|
line_and_column = name.line_and_column
|
67
|
-
|
68
|
-
Package.new(Thread.current[:current_package_name]),
|
69
|
-
name
|
70
|
-
) do
|
74
|
+
TicketExpr.new([name.to_s]) do
|
71
75
|
set_line_and_column(line_and_column)
|
72
76
|
end
|
73
77
|
end
|