pione 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/History.txt +12 -1
  2. data/example/AbstractRule/AbstractRule.pione +40 -0
  3. data/example/Fib/Fib.pione +12 -5
  4. data/example/LucasNumber/LucasNumber.pione +1 -1
  5. data/example/MakePair/MakePair.pione +21 -6
  6. data/example/OddSelector/OddSelector.pione +17 -0
  7. data/example/OddSelector/data/1.i +0 -0
  8. data/example/OddSelector/data/10.i +0 -0
  9. data/example/OddSelector/data/2.i +0 -0
  10. data/example/OddSelector/data/3.i +0 -0
  11. data/example/OddSelector/data/4.i +0 -0
  12. data/example/OddSelector/data/5.i +0 -0
  13. data/example/OddSelector/data/6.i +0 -0
  14. data/example/OddSelector/data/7.i +0 -0
  15. data/example/OddSelector/data/8.i +0 -0
  16. data/example/OddSelector/data/9.i +0 -0
  17. data/example/SequentialParameter/SequentialParameter.pione +4 -0
  18. data/example/SieveOfEratosthenes/SieveOfEratosthenes.pione +31 -43
  19. data/example/SingleParticlesWithRef/SingleParticlesWithRef.pione +1 -1
  20. data/example/Touch/Touch.pione +3 -0
  21. data/lib/pione/command/pione-syntax-checker.rb +4 -4
  22. data/lib/pione/model/assignment.rb +6 -1
  23. data/lib/pione/model/basic-model.rb +92 -278
  24. data/lib/pione/model/binary-operator.rb +5 -1
  25. data/lib/pione/model/block.rb +17 -0
  26. data/lib/pione/model/boolean.rb +54 -22
  27. data/lib/pione/model/constraints.rb +34 -0
  28. data/lib/pione/model/data-expr.rb +184 -297
  29. data/lib/pione/model/feature-expr.rb +13 -4
  30. data/lib/pione/model/float.rb +24 -41
  31. data/lib/pione/model/integer.rb +75 -41
  32. data/lib/pione/model/keyed-sequence.rb +143 -0
  33. data/lib/pione/model/list.rb +12 -8
  34. data/lib/pione/model/message.rb +8 -4
  35. data/lib/pione/model/ordinal-sequence.rb +75 -0
  36. data/lib/pione/model/package.rb +6 -2
  37. data/lib/pione/model/parameters.rb +61 -9
  38. data/lib/pione/model/pione-method.rb +146 -0
  39. data/lib/pione/model/rule-expr.rb +44 -38
  40. data/lib/pione/model/rule-io.rb +11 -3
  41. data/lib/pione/model/rule.rb +105 -155
  42. data/lib/pione/model/sequence.rb +273 -0
  43. data/lib/pione/model/string.rb +75 -29
  44. data/lib/pione/model/ticket-expr.rb +17 -29
  45. data/lib/pione/model/type.rb +242 -0
  46. data/lib/pione/model/variable-table.rb +52 -53
  47. data/lib/pione/model/variable.rb +8 -4
  48. data/lib/pione/model.rb +34 -0
  49. data/lib/pione/parser/block-parser.rb +44 -20
  50. data/lib/pione/parser/common-parser.rb +2 -1
  51. data/lib/pione/parser/document-parser.rb +6 -1
  52. data/lib/pione/parser/expr-parser.rb +57 -11
  53. data/lib/pione/parser/flow-element-parser.rb +2 -2
  54. data/lib/pione/parser/rule-definition-parser.rb +23 -1
  55. data/lib/pione/patch/rinda-patch.rb +1 -5
  56. data/lib/pione/rule-handler/action-handler.rb +5 -5
  57. data/lib/pione/rule-handler/basic-handler.rb +30 -7
  58. data/lib/pione/rule-handler/empty-handler.rb +14 -0
  59. data/lib/pione/rule-handler/flow-handler.rb +132 -115
  60. data/lib/pione/rule-handler/root-handler.rb +6 -2
  61. data/lib/pione/rule-handler/update-criteria.rb +152 -0
  62. data/lib/pione/rule-handler.rb +14 -0
  63. data/lib/pione/system/identifier.rb +9 -9
  64. data/lib/pione/transformer/block-transformer.rb +4 -0
  65. data/lib/pione/transformer/expr-transformer.rb +1 -1
  66. data/lib/pione/transformer/flow-element-transformer.rb +4 -2
  67. data/lib/pione/transformer/literal-transformer.rb +14 -3
  68. data/lib/pione/transformer/rule-definition-transformer.rb +17 -5
  69. data/lib/pione/tuple-space/data-finder.rb +15 -52
  70. data/lib/pione/version.rb +1 -1
  71. data/lib/pione.rb +12 -38
  72. data/test/agent/spec_task-worker.rb +13 -12
  73. data/test/model/spec_assignment.rb +2 -2
  74. data/test/model/spec_binary-operator.rb +10 -10
  75. data/test/model/spec_block.rb +8 -8
  76. data/test/model/spec_boolean.rb +1 -72
  77. data/test/model/spec_boolean.yml +134 -0
  78. data/test/model/spec_data-expr.rb +50 -237
  79. data/test/model/spec_data-expr.yml +16 -45
  80. data/test/model/spec_data-expr_match.yml +45 -0
  81. data/test/model/spec_feature-expr.rb +2 -43
  82. data/test/model/spec_feature-expr.yml +0 -28
  83. data/test/model/spec_feature-expr_decide.yml +28 -0
  84. data/test/model/spec_float.rb +1 -119
  85. data/test/model/spec_float.yml +17 -0
  86. data/test/model/spec_integer.rb +1 -119
  87. data/test/model/spec_integer.yml +57 -0
  88. data/test/model/spec_keyed-sequence.rb +5 -0
  89. data/test/model/spec_keyed-sequence.yml +22 -0
  90. data/test/model/spec_message.rb +7 -7
  91. data/test/model/spec_parameters.rb +50 -63
  92. data/test/model/spec_pione-method.rb +56 -0
  93. data/test/model/spec_rule-expr.rb +18 -8
  94. data/test/model/spec_rule.rb +12 -12
  95. data/test/model/spec_sequence.rb +5 -0
  96. data/test/model/spec_sequence.yml +60 -0
  97. data/test/model/spec_string.rb +3 -70
  98. data/test/model/spec_string.yml +83 -0
  99. data/test/model/spec_ticket-expr.rb +4 -54
  100. data/test/model/spec_ticket-expr.yml +11 -0
  101. data/test/model/spec_variable-table.rb +41 -42
  102. data/test/model/spec_variable.rb +20 -22
  103. data/test/parser/spec_block-parser.yml +9 -0
  104. data/test/parser/spec_expr-parser.yml +0 -17
  105. data/test/parser/spec_flow-element-parser.yml +1 -1
  106. data/test/parser/spec_rule-definition-parser.yml +0 -4
  107. data/test/rule-handler/spec_update-criteria.pione +39 -0
  108. data/test/rule-handler/spec_update-criteria.rb +53 -0
  109. data/test/rule-handler/spec_update-criteria.yml +158 -0
  110. data/test/test-util.rb +25 -0
  111. data/test/transformer/spec_block-transformer.rb +7 -0
  112. data/test/transformer/spec_expr-transformer.rb +64 -19
  113. data/test/transformer/spec_flow-element-transformer.rb +11 -11
  114. data/test/transformer/spec_literal-transformer.rb +29 -29
  115. data/test/transformer/spec_rule-definition-transformer.rb +39 -21
  116. metadata +57 -11
  117. data/lib/pione/model/undefined-value.rb +0 -24
  118. data/lib/pione/tuple-space/update-criteria.rb +0 -97
  119. data/test/model/spec_list.rb +0 -26
  120. data/test/model/spec_rule-io.rb +0 -32
  121. data/test/spec_update-criteria.rb +0 -83
data/History.txt CHANGED
@@ -1,6 +1,17 @@
1
1
  # History
2
2
 
3
- ## 0.1.3(2013/04/XX)
3
+ ## 0.1.4(2013/05/13)
4
+
5
+ * Sequence based expressions.
6
+ * Enable to distribute tasks based on parameters.
7
+ * Added many methods.
8
+ * Added annotations.
9
+ * Added remove and touch operation as data tuple operations.
10
+ * Modified update criteria.
11
+ * Added empty rule.
12
+ * Added new examples.
13
+
14
+ ## 0.1.3(2013/04/25)
4
15
 
5
16
  * Added new data expression literal "null" for accepting data nonexistence
6
17
  * Added new data expression property keyword "neglect" and "care" for the update criterion about data mtime
@@ -0,0 +1,40 @@
1
+ Rule Main
2
+ output 'message.txt'
3
+ param $NAME := "A"
4
+ Flow
5
+ case $NAME
6
+ when "A"
7
+ $RULE := A
8
+ when "B"
9
+ $RULE := B
10
+ when "C"
11
+ $RULE := C
12
+ end
13
+ rule Abstract {R: $RULE}
14
+ End
15
+
16
+ Rule Abstract
17
+ output 'message.txt'
18
+ param $R
19
+ Flow
20
+ rule $R
21
+ End
22
+
23
+ Rule A
24
+ output 'message.txt'
25
+ Action
26
+ echo "This is rule A." > {$O[1]}
27
+ End
28
+
29
+ Rule B
30
+ output 'message.txt'
31
+ Action
32
+ echo "This is rule B." > {$O[1]}
33
+ End
34
+
35
+ Rule C
36
+ output 'message.txt'
37
+ Action
38
+ echo "This is rule C." > {$O[1]}
39
+ End
40
+
@@ -1,25 +1,31 @@
1
- param $NUM := 3
1
+ @ author :: "Keita Yamaguchi"
2
+ @ "Fib.pione calculates the value of Fibonacci number."
3
+
4
+ param ($NUM := 3)
2
5
 
3
6
  Rule Main
4
7
  output 'result.txt'
5
8
  Flow
6
9
  rule Fib {N: $NUM}
7
- rule Result {N: $NUM}
10
+ rule Result
8
11
  End
9
12
 
10
13
  Rule Fib0
14
+ @ "the value of fib(0) is 0"
11
15
  output 'fib0.txt'
12
16
  Action
13
17
  echo -n '0' > fib0.txt
14
18
  End
15
19
 
16
20
  Rule Fib1
21
+ @ "the value of fib(1) is 1"
17
22
  output 'fib1.txt'
18
23
  Action
19
24
  echo -n '1' > fib1.txt
20
25
  End
21
26
 
22
27
  Rule Fib
28
+ @ "fib(n) is fib(0), fib(1), or fib(n-1) + fib(n-2)"
23
29
  output 'fib{$N}.txt'
24
30
  param $N
25
31
  Flow
@@ -38,6 +44,7 @@ Flow
38
44
  End
39
45
 
40
46
  Rule Calc
47
+ @ "calculate the value of fib(n-1) + fib(n-2)"
41
48
  input 'fib{$P1}.txt'
42
49
  input 'fib{$P2}.txt'
43
50
  output 'fib{$N}.txt'
@@ -49,9 +56,9 @@ Action
49
56
  End
50
57
 
51
58
  Rule Result
52
- input 'fib{$N}.txt'
59
+ @ "make the result"
60
+ input 'fib*.txt'
53
61
  output 'result.txt'
54
- param $N
55
62
  Action
56
- cat {$I[1]} > {$O[1]}
63
+ cp {$I[1]} {$O[1]}
57
64
  End
@@ -3,7 +3,7 @@ Rule Main
3
3
  param $NUM := 10
4
4
  Flow
5
5
  rule LucasNumber.params({NUM: $NUM})
6
- rule Result
6
+ rule Result {NUM: $NUM}
7
7
  End
8
8
 
9
9
  Rule LucasNumber
@@ -2,13 +2,28 @@ Rule Main
2
2
  input '*.i'.all
3
3
  output '*.pair'.all
4
4
  Flow
5
- rule MakePair
5
+ rule SuccessorPair
6
+ rule PermutationPair
7
+ rule CombinationPair
6
8
  End
7
9
 
8
- Rule MakePair
10
+ Rule SuccessorPair
9
11
  input '*.i'
10
- input '{$*.as_int + 1}.i'
11
- output '{$*}-{$*.as_int + 1}.pair'
12
- Action
13
- touch {$O[1]}
12
+ input '*.i'
13
+ output 'succ-{$I[1][1]}-{$I[2][1]}.pair'.touch
14
+ constraint ($I[1][1].i + 1) == $I[2][1].i
15
+ End
16
+
17
+ Rule PermutationPair
18
+ input '*.i'
19
+ input '*.i'
20
+ output 'perm-{$I[1][1]}-{$I[2][1]}.pair'.touch
21
+ constraint $I[1][1].i != $I[2][1].i
22
+ End
23
+
24
+ Rule CombinationPair
25
+ input '*.i'
26
+ input '*.i'
27
+ output 'comb-{$I[1][1]}-{$I[2][1]}.pair'.touch
28
+ constraint $I[1][1].i < $I[2][1].i
14
29
  End
@@ -0,0 +1,17 @@
1
+ Rule Main
2
+ input '*.i'.all
3
+ output '*.res'.all
4
+ Flow
5
+ rule OddFilter >>> MakeResult
6
+ End
7
+
8
+ Rule OddFilter
9
+ input '*.i'
10
+ output '*.i'.remove
11
+ constraint ($I[1][1].i % 2) == 0
12
+ End
13
+
14
+ Rule MakeResult
15
+ input '*.i'
16
+ output '{$*}.res'.touch
17
+ End
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ Rule Main
2
+ output '{$N}.i'.touch
3
+ param $N := 1.upto(10)
4
+ End
@@ -1,62 +1,50 @@
1
- param $MAX := 20
1
+ param $MAX := 10
2
2
 
3
3
  Rule Main
4
4
  output '*.prime'.all
5
5
  Flow
6
- rule Sieve
6
+ rule CreateUndeterminedNumbers >>> Sieve
7
+ End
8
+
9
+ Rule CreateUndeterminedNumbers
10
+ output '*.ud'.all
11
+ param $N := 2.upto($MAX)
12
+ Flow
13
+ rule CreateData {NAME: "{$N}.ud"}
7
14
  End
8
15
 
9
16
  Rule Sieve
10
- input '*-*.not_prime'.all or null
11
- output '*.current'.all or '*.prime'.all
12
- param $NUM := 2
17
+ input '*.ud'.all or null
18
+ input '*.prime'.all or null
19
+ output '*.prime'.all.neglect
20
+ output 'finished'
21
+ param $N := 2
13
22
  Flow
14
- $NEXT_NUM := $NUM + 1
15
- $NEXT_RULE := Sieve {NUM: $NEXT_NUM}
16
- rule Current {N: $NUM}
17
- if not :: $*.as_data_expr.match?($NUM.as_string)
18
- rule CreatePrime {N: $NUM}
19
- if ($NUM * $NUM) <= $MAX
20
- rule CreateNotPrimeAll {P: $NUM} >>> $NEXT_RULE
23
+ if $*.as_data_expr.match?($N.str)
24
+ if ($N * $N) <= $MAX
25
+ rule CreateData {NAME: "{$N}.prime"} >>> RemoveUndeterminedNumber >>> Sieve {N: $N+1}
21
26
  else
22
- rule $NEXT_RULE
27
+ rule UndeterminedNumber2Prime
28
+ rule CreateData {NAME: "finished"}
23
29
  end
24
30
  else
25
- if $NEXT_NUM <= $MAX
26
- rule $NEXT_RULE
27
- end
31
+ rule Sieve {N: $N+1}
28
32
  end
29
33
  End
30
34
 
31
- Rule CreateNotPrimeAll
32
- output '*-{$P}.not_prime'.all
33
- param $P
34
- param $INDEX := 2
35
- Flow
36
- if ($P * ($INDEX + 1)) <= $MAX
37
- rule CreateNotPrimeAll {P: $P, INDEX: $INDEX + 1}
38
- end
39
- rule CreateNotPrime {P: $P, N: $P * $INDEX}
35
+ Rule RemoveUndeterminedNumber
36
+ input '*.prime'
37
+ input '*.ud'
38
+ output '{$I[2][1]}.ud'.remove
39
+ constraint ($I[2][1].i % $I[1][1].i) == 0
40
40
  End
41
41
 
42
- Rule CreateNotPrime
43
- output '{$N}-{$P}.not_prime'
44
- param $P
45
- param $N
46
- Action
47
- touch {$N}-{$P}.not_prime
42
+ Rule UndeterminedNumber2Prime
43
+ input '*.ud'
44
+ output '{$*}.prime'.touch
48
45
  End
49
46
 
50
- Rule CreatePrime
51
- output '{$N}.prime'
52
- param $N
53
- Action
54
- touch {$N}.prime
47
+ Rule CreateData
48
+ param $NAME
49
+ output '{$NAME}'.touch
55
50
  End
56
-
57
- Rule Current
58
- output '{$N}.current'
59
- param $N
60
- Action
61
- touch {$N}.current
62
- End
@@ -102,7 +102,7 @@ Rule Create3dlst
102
102
  input '*.3dinfo'.all
103
103
  output '{$TARGET}.3dlst'
104
104
  Action
105
- cat {$I[1].join(" ")} | sort > {$TARGET}.3dlst
105
+ cat {$I[1].as_string.join(" ")} | sort > {$TARGET}.3dlst
106
106
  End
107
107
 
108
108
  # .3dlst.3d
@@ -0,0 +1,3 @@
1
+ Rule Main
2
+ output 'touched'.touch
3
+ End
@@ -40,9 +40,9 @@ module Pione
40
40
  when :readline
41
41
  action_readline_mode
42
42
  when :file
43
- print_result(Pathname.new(option[:document]).read)
43
+ print_result(DocumentParser.new, Pathname.new(option[:document]).read)
44
44
  when :expr
45
- print_result(option[:expr])
45
+ print_result(DocumentParser.new.expr, option[:expr])
46
46
  end
47
47
  end
48
48
 
@@ -109,10 +109,10 @@ module Pione
109
109
  # @param str [String]
110
110
  # PIONE expression
111
111
  # @return [void]
112
- def print_result(str)
112
+ def print_result(parser, str)
113
113
  begin
114
114
  puts Terminal.green("syntax:")
115
- stree = DocumentParser.new.parse(str)
115
+ stree = parser.parse(str)
116
116
  pp stree
117
117
  if option[:transform]
118
118
  puts Terminal.green("model:")
@@ -10,7 +10,7 @@ module Pione
10
10
  # # assigning a variable value
11
11
  # $X := $Y
12
12
  # # => Assignment.new(Variable.new('X'), Variable.new('Y'))
13
- class Assignment < BasicModel
13
+ class Assignment < Callable
14
14
  set_pione_model_type TypeAssignment
15
15
 
16
16
  # Return the variable part of assignment.
@@ -99,5 +99,10 @@ module Pione
99
99
  @variable.hash + @expr.hash
100
100
  end
101
101
  end
102
+
103
+ # class AssignmentSequence < Sequence
104
+ # set_pione_model_type TypeAssignment
105
+ # set_element_class Assignment
106
+ # end
102
107
  end
103
108
  end