tp_plus 0.0.77 → 0.0.87

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +87 -84
  3. data/Rakefile +35 -35
  4. data/bin/tpp +92 -92
  5. data/lib/tp_plus/interpreter.rb +152 -152
  6. data/lib/tp_plus/namespace.rb +66 -66
  7. data/lib/tp_plus/nodes/abort_node.rb +9 -9
  8. data/lib/tp_plus/nodes/acc_node.rb +19 -19
  9. data/lib/tp_plus/nodes/address_node.rb +22 -22
  10. data/lib/tp_plus/nodes/argument_node.rb +20 -20
  11. data/lib/tp_plus/nodes/assignment_node.rb +52 -45
  12. data/lib/tp_plus/nodes/base_node.rb +9 -0
  13. data/lib/tp_plus/nodes/call_node.rb +34 -34
  14. data/lib/tp_plus/nodes/case_condition_node.rb +26 -26
  15. data/lib/tp_plus/nodes/case_node.rb +33 -33
  16. data/lib/tp_plus/nodes/comment_node.rb +18 -22
  17. data/lib/tp_plus/nodes/conditional_node.rb +60 -60
  18. data/lib/tp_plus/nodes/definition_node.rb +22 -22
  19. data/lib/tp_plus/nodes/digit_node.rb +22 -22
  20. data/lib/tp_plus/nodes/empty_stmt_node.rb +9 -9
  21. data/lib/tp_plus/nodes/eval_node.rb +13 -13
  22. data/lib/tp_plus/nodes/expression_node.rb +68 -68
  23. data/lib/tp_plus/nodes/for_node.rb +20 -20
  24. data/lib/tp_plus/nodes/header_node.rb +27 -27
  25. data/lib/tp_plus/nodes/indirect_node.rb +27 -51
  26. data/lib/tp_plus/nodes/inline_conditional_node.rb +36 -40
  27. data/lib/tp_plus/nodes/io_method_node.rb +55 -55
  28. data/lib/tp_plus/nodes/io_node.rb +31 -31
  29. data/lib/tp_plus/nodes/jpos_node.rb +13 -0
  30. data/lib/tp_plus/nodes/jump_node.rb +23 -23
  31. data/lib/tp_plus/nodes/label_definition_node.rb +21 -21
  32. data/lib/tp_plus/nodes/lpos_node.rb +13 -0
  33. data/lib/tp_plus/nodes/motion_node.rb +62 -62
  34. data/lib/tp_plus/nodes/namespace_node.rb +16 -16
  35. data/lib/tp_plus/nodes/namespaced_var_node.rb +38 -38
  36. data/lib/tp_plus/nodes/numreg_node.rb +26 -26
  37. data/lib/tp_plus/nodes/offset_node.rb +27 -27
  38. data/lib/tp_plus/nodes/operator_node.rb +80 -78
  39. data/lib/tp_plus/nodes/paren_expression_node.rb +17 -17
  40. data/lib/tp_plus/nodes/pause_node.rb +9 -9
  41. data/lib/tp_plus/nodes/position_data_node.rb +66 -66
  42. data/lib/tp_plus/nodes/position_node.rb +26 -26
  43. data/lib/tp_plus/nodes/posreg_node.rb +64 -64
  44. data/lib/tp_plus/nodes/raise_node.rb +13 -13
  45. data/lib/tp_plus/nodes/real_node.rb +27 -27
  46. data/lib/tp_plus/nodes/return_node.rb +9 -0
  47. data/lib/tp_plus/nodes/set_skip_node.rb +14 -14
  48. data/lib/tp_plus/nodes/skip_node.rb +22 -22
  49. data/lib/tp_plus/nodes/speed_node.rb +29 -29
  50. data/lib/tp_plus/nodes/string_node.rb +13 -13
  51. data/lib/tp_plus/nodes/string_register_node.rb +26 -26
  52. data/lib/tp_plus/nodes/termination_node.rb +23 -23
  53. data/lib/tp_plus/nodes/terminator_node.rb +16 -16
  54. data/lib/tp_plus/nodes/time_node.rb +24 -24
  55. data/lib/tp_plus/nodes/timer_method_node.rb +33 -37
  56. data/lib/tp_plus/nodes/timer_node.rb +16 -16
  57. data/lib/tp_plus/nodes/unary_expression_node.rb +39 -0
  58. data/lib/tp_plus/nodes/units_node.rb +20 -20
  59. data/lib/tp_plus/nodes/use_node.rb +21 -21
  60. data/lib/tp_plus/nodes/user_alarm_node.rb +16 -16
  61. data/lib/tp_plus/nodes/var_method_node.rb +23 -23
  62. data/lib/tp_plus/nodes/var_node.rb +39 -39
  63. data/lib/tp_plus/nodes/vision_register_node.rb +22 -22
  64. data/lib/tp_plus/nodes/wait_for_node.rb +50 -54
  65. data/lib/tp_plus/nodes/wait_until_node.rb +61 -65
  66. data/lib/tp_plus/nodes/while_node.rb +40 -42
  67. data/lib/tp_plus/parser.rb +1749 -1697
  68. data/lib/tp_plus/scanner.rb +295 -295
  69. data/lib/tp_plus/token.rb +101 -98
  70. data/lib/tp_plus/version.rb +3 -3
  71. data/lib/tp_plus.rb +72 -67
  72. data/test/test_helper.rb +5 -5
  73. data/test/tp_plus/test_interpreter.rb +1372 -1329
  74. data/test/tp_plus/test_parser.rb +502 -502
  75. data/test/tp_plus/test_scanner.rb +591 -577
  76. data/tp_plus.gemspec +31 -31
  77. metadata +8 -3
@@ -1,16 +1,16 @@
1
- module TPPlus
2
- module Nodes
3
- class NamespaceNode
4
- attr_reader :block
5
- def initialize(name, block)
6
- @name = name
7
- @block = block
8
- end
9
-
10
- def eval(context)
11
- context.add_namespace(@name, @block)
12
- nil
13
- end
14
- end
15
- end
16
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class NamespaceNode < BaseNode
4
+ attr_reader :block
5
+ def initialize(name, block)
6
+ @name = name
7
+ @block = block
8
+ end
9
+
10
+ def eval(context)
11
+ context.add_namespace(@name, @block)
12
+ nil
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,38 +1,38 @@
1
- module TPPlus
2
- module Nodes
3
- class NamespacedVarNode
4
- attr_reader :namespaces
5
- def initialize(namespaces, var_node)
6
- @namespaces = namespaces
7
- @var_node = var_node
8
- end
9
-
10
- def namespace(context)
11
- @context = context
12
- @namespaces.each do |ns|
13
- if @context.get_namespace(ns)
14
- @context = @context.get_namespace(ns)
15
- end
16
- end
17
-
18
- @context
19
- end
20
-
21
- def identifier
22
- @var_node.identifier
23
- end
24
-
25
- def target_node(context)
26
- @var_node.target_node(namespace(context))
27
- end
28
-
29
- def requires_mixed_logic?(context)
30
- @var_node.requires_mixed_logic?(namespace(context))
31
- end
32
-
33
- def eval(context,options={})
34
- @var_node.eval(namespace(context), options)
35
- end
36
- end
37
- end
38
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class NamespacedVarNode < BaseNode
4
+ attr_reader :namespaces
5
+ def initialize(namespaces, var_node)
6
+ @namespaces = namespaces
7
+ @var_node = var_node
8
+ end
9
+
10
+ def namespace(context)
11
+ @context = context
12
+ @namespaces.each do |ns|
13
+ if @context.get_namespace(ns)
14
+ @context = @context.get_namespace(ns)
15
+ end
16
+ end
17
+
18
+ @context
19
+ end
20
+
21
+ def identifier
22
+ @var_node.identifier
23
+ end
24
+
25
+ def target_node(context)
26
+ @var_node.target_node(namespace(context))
27
+ end
28
+
29
+ def requires_mixed_logic?(context)
30
+ @var_node.requires_mixed_logic?(namespace(context))
31
+ end
32
+
33
+ def eval(context,options={})
34
+ @var_node.eval(namespace(context), options)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,26 +1,26 @@
1
- module TPPlus
2
- module Nodes
3
- class NumregNode
4
- attr_accessor :comment
5
- attr_reader :id
6
- def initialize(id)
7
- @id = id
8
- @comment = ""
9
- end
10
-
11
- def requires_mixed_logic?(context)
12
- false
13
- end
14
-
15
- def comment_string
16
- return "" if @comment == ""
17
-
18
- ":#{@comment}"
19
- end
20
-
21
- def eval(context,options={})
22
- "R[#{@id}#{comment_string}]"
23
- end
24
- end
25
- end
26
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class NumregNode < BaseNode
4
+ attr_accessor :comment
5
+ attr_reader :id
6
+ def initialize(id)
7
+ @id = id
8
+ @comment = ""
9
+ end
10
+
11
+ def requires_mixed_logic?(context)
12
+ false
13
+ end
14
+
15
+ def comment_string
16
+ return "" if @comment == ""
17
+
18
+ ":#{@comment}"
19
+ end
20
+
21
+ def eval(context,options={})
22
+ "R[#{@id}#{comment_string}]"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,27 +1,27 @@
1
- module TPPlus
2
- module Nodes
3
- class OffsetNode
4
- def initialize(type, var)
5
- @type = type
6
- @var = var
7
- end
8
-
9
- def name
10
- case @type.downcase
11
- when "offset"
12
- "Offset"
13
- when "tool_offset"
14
- "Tool_Offset"
15
- when "vision_offset"
16
- "VOFFSET"
17
- else
18
- raise "Invalid type"
19
- end
20
- end
21
-
22
- def eval(context)
23
- "#{name},#{@var.eval(context)}"
24
- end
25
- end
26
- end
27
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class OffsetNode < BaseNode
4
+ def initialize(type, var)
5
+ @type = type
6
+ @var = var
7
+ end
8
+
9
+ def name
10
+ case @type.downcase
11
+ when "offset"
12
+ "Offset"
13
+ when "tool_offset"
14
+ "Tool_Offset"
15
+ when "vision_offset"
16
+ "VOFFSET"
17
+ else
18
+ raise "Invalid type"
19
+ end
20
+ end
21
+
22
+ def eval(context)
23
+ "#{name},#{@var.eval(context)}"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,78 +1,80 @@
1
- module TPPlus
2
- module Nodes
3
- class OperatorNode
4
- attr_reader :string
5
- def initialize(string)
6
- @string = string
7
- end
8
-
9
- def bang?
10
- @string == "!"
11
- end
12
-
13
- def requires_mixed_logic?(context)
14
- case @string
15
- when "&&", "||", "!"
16
- true
17
- else
18
- false
19
- end
20
- end
21
-
22
- def boolean?
23
- case @string
24
- when "&&", "||", "!"#, "==", "<>", ">", ">=", "<", "<="
25
- true
26
- else
27
- false
28
- end
29
- end
30
-
31
- def eval(context,options={})
32
- if options[:opposite]
33
- case @string
34
- when "=="
35
- "<>"
36
- when "!=", "<>"
37
- "="
38
- when ">"
39
- "<="
40
- when "<"
41
- ">="
42
- when ">="
43
- "<"
44
- when "<="
45
- ">"
46
- when "!"
47
- ""
48
- when "||"
49
- " AND "
50
- when "&&"
51
- " OR "
52
- when "DIV"
53
- " MOD "
54
- else
55
- "#{@string}"
56
- end
57
- else
58
- case @string
59
- when "=="
60
- "="
61
- when "!="
62
- "<>"
63
- when "&&"
64
- " AND "
65
- when "||"
66
- " OR "
67
- when "%"
68
- " MOD "
69
- when "DIV"
70
- " DIV "
71
- else
72
- "#{@string}"
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class OperatorNode < BaseNode
4
+ attr_reader :string
5
+ def initialize(string)
6
+ @string = string
7
+ end
8
+
9
+ def bang?
10
+ @string == "!"
11
+ end
12
+
13
+ def requires_mixed_logic?(context)
14
+ case @string
15
+ when "&&", "||", "!"
16
+ true
17
+ else
18
+ false
19
+ end
20
+ end
21
+
22
+ def boolean?
23
+ case @string
24
+ when "&&", "||", "!"#, "==", "<>", ">", ">=", "<", "<="
25
+ true
26
+ else
27
+ false
28
+ end
29
+ end
30
+
31
+ def eval(context,options={})
32
+ if options[:opposite]
33
+ case @string
34
+ when "=="
35
+ "<>"
36
+ when "!=", "<>"
37
+ "="
38
+ when ">"
39
+ "<="
40
+ when "<"
41
+ ">="
42
+ when ">="
43
+ "<"
44
+ when "<="
45
+ ">"
46
+ when "!"
47
+ ""
48
+ when "||"
49
+ " AND "
50
+ when "&&"
51
+ " OR "
52
+ when "DIV"
53
+ " MOD "
54
+ when "!"
55
+ ""
56
+ else
57
+ "#{@string}"
58
+ end
59
+ else
60
+ case @string
61
+ when "=="
62
+ "="
63
+ when "!="
64
+ "<>"
65
+ when "&&"
66
+ " AND "
67
+ when "||"
68
+ " OR "
69
+ when "%"
70
+ " MOD "
71
+ when "DIV"
72
+ " DIV "
73
+ else
74
+ "#{@string}"
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,17 +1,17 @@
1
- module TPPlus
2
- module Nodes
3
- class ParenExpressionNode
4
- def initialize(x)
5
- @x = x
6
- end
7
-
8
- def requires_mixed_logic?(context)
9
- @x.requires_mixed_logic?(context)
10
- end
11
-
12
- def eval(context, options={})
13
- "(#{@x.eval(context, options)})"
14
- end
15
- end
16
- end
17
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class ParenExpressionNode < BaseNode
4
+ def initialize(x)
5
+ @x = x
6
+ end
7
+
8
+ def requires_mixed_logic?(context)
9
+ @x.requires_mixed_logic?(context)
10
+ end
11
+
12
+ def eval(context, options={})
13
+ "(#{@x.eval(context, options)})"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,9 +1,9 @@
1
- module TPPlus
2
- module Nodes
3
- class PauseNode
4
- def eval(context)
5
- "PAUSE"
6
- end
7
- end
8
- end
9
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class PauseNode < BaseNode
4
+ def eval(context)
5
+ "PAUSE"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,66 +1,66 @@
1
- module TPPlus
2
- module Nodes
3
- class PositionDataNode
4
- attr_reader :hash
5
- def initialize(hash)
6
- @hash = hash
7
- @ids = []
8
- end
9
-
10
- def valid?
11
- return false unless @hash[:positions].is_a?(Array)
12
- return false if @hash[:positions].map {|p| position_valid?(p) == false }.any?
13
-
14
- true
15
- end
16
-
17
- def position_valid?(position_hash)
18
- return false if @ids.include?(position_hash[:id])
19
- @ids.push(position_hash[:id])
20
-
21
- return false unless position_hash[:mask].is_a? Array
22
-
23
- position_hash[:mask].select {|q|
24
- !mask_valid?(q)
25
- }.empty?
26
- end
27
-
28
- def mask_valid?(position_hash)
29
- return false unless position_hash[:group].is_a?(Fixnum)
30
- return false unless position_hash[:uframe].is_a?(Fixnum)
31
- return false unless position_hash[:utool].is_a?(Fixnum)
32
-
33
- if position_hash[:config].is_a?(Hash)
34
- return false unless boolean?(position_hash[:config][:flip])
35
- return false unless boolean?(position_hash[:config][:up])
36
- return false unless boolean?(position_hash[:config][:top])
37
- return false unless position_hash[:config][:turn_counts].is_a?(Array)
38
- return false unless position_hash[:config][:turn_counts].length == 3
39
- return false if position_hash[:config][:turn_counts].map {|tc| tc.is_a?(Fixnum) == false }.any?
40
- return false unless position_hash[:components].is_a?(Hash)
41
- [:x,:y,:z,:w,:p,:r].each do |component|
42
- return false unless position_hash[:components][component].is_a?(Float)
43
- end
44
- else
45
- # must be joint representation
46
- return false unless position_hash[:components].is_a?(Hash)
47
- position_hash[:components].each do |component|
48
- return false unless component[1].is_a?(Float)
49
- end
50
- end
51
-
52
- true
53
- end
54
-
55
- def boolean?(thing)
56
- thing.is_a?(TrueClass) || thing.is_a?(FalseClass)
57
- end
58
-
59
- def eval(context, options={})
60
- raise "Invalid position data" unless valid?
61
- context.position_data = @hash
62
- nil
63
- end
64
- end
65
- end
66
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class PositionDataNode < BaseNode
4
+ attr_reader :hash
5
+ def initialize(hash)
6
+ @hash = hash
7
+ @ids = []
8
+ end
9
+
10
+ def valid?
11
+ return false unless @hash[:positions].is_a?(Array)
12
+ return false if @hash[:positions].map {|p| position_valid?(p) == false }.any?
13
+
14
+ true
15
+ end
16
+
17
+ def position_valid?(position_hash)
18
+ return false if @ids.include?(position_hash[:id])
19
+ @ids.push(position_hash[:id])
20
+
21
+ return false unless position_hash[:mask].is_a? Array
22
+
23
+ position_hash[:mask].select {|q|
24
+ !mask_valid?(q)
25
+ }.empty?
26
+ end
27
+
28
+ def mask_valid?(position_hash)
29
+ return false unless position_hash[:group].is_a?(Fixnum)
30
+ return false unless position_hash[:uframe].is_a?(Fixnum)
31
+ return false unless position_hash[:utool].is_a?(Fixnum)
32
+
33
+ if position_hash[:config].is_a?(Hash)
34
+ return false unless boolean?(position_hash[:config][:flip])
35
+ return false unless boolean?(position_hash[:config][:up])
36
+ return false unless boolean?(position_hash[:config][:top])
37
+ return false unless position_hash[:config][:turn_counts].is_a?(Array)
38
+ return false unless position_hash[:config][:turn_counts].length == 3
39
+ return false if position_hash[:config][:turn_counts].map {|tc| tc.is_a?(Fixnum) == false }.any?
40
+ return false unless position_hash[:components].is_a?(Hash)
41
+ [:x,:y,:z,:w,:p,:r].each do |component|
42
+ return false unless position_hash[:components][component].is_a?(Float)
43
+ end
44
+ else
45
+ # must be joint representation
46
+ return false unless position_hash[:components].is_a?(Hash)
47
+ position_hash[:components].each do |component|
48
+ return false unless component[1].is_a?(Float)
49
+ end
50
+ end
51
+
52
+ true
53
+ end
54
+
55
+ def boolean?(thing)
56
+ thing.is_a?(TrueClass) || thing.is_a?(FalseClass)
57
+ end
58
+
59
+ def eval(context, options={})
60
+ raise "Invalid position data" unless valid?
61
+ context.position_data = @hash
62
+ nil
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,26 +1,26 @@
1
- module TPPlus
2
- module Nodes
3
- class PositionNode
4
- attr_accessor :comment
5
- attr_reader :id
6
- def initialize(id)
7
- @id = id
8
- @comment = ""
9
- end
10
-
11
- def requires_mixed_logic?(context)
12
- false
13
- end
14
-
15
- def comment_string
16
- return "" if @comment == ""
17
-
18
- ":#{@comment}"
19
- end
20
-
21
- def eval(context,options={})
22
- "P[#{@id}#{comment_string}]"
23
- end
24
- end
25
- end
26
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class PositionNode < BaseNode
4
+ attr_accessor :comment
5
+ attr_reader :id
6
+ def initialize(id)
7
+ @id = id
8
+ @comment = ""
9
+ end
10
+
11
+ def requires_mixed_logic?(context)
12
+ false
13
+ end
14
+
15
+ def comment_string
16
+ return "" if @comment == ""
17
+
18
+ ":#{@comment}"
19
+ end
20
+
21
+ def eval(context,options={})
22
+ "P[#{@id}#{comment_string}]"
23
+ end
24
+ end
25
+ end
26
+ end