tp_plus 0.0.73 → 0.0.74

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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +74 -65
  3. data/Rakefile +35 -21
  4. data/bin/tpp +73 -73
  5. data/lib/tp_plus/interpreter.rb +152 -129
  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/address_node.rb +22 -0
  9. data/lib/tp_plus/nodes/argument_node.rb +20 -19
  10. data/lib/tp_plus/nodes/assignment_node.rb +45 -45
  11. data/lib/tp_plus/nodes/call_node.rb +34 -34
  12. data/lib/tp_plus/nodes/case_condition_node.rb +26 -26
  13. data/lib/tp_plus/nodes/case_node.rb +33 -33
  14. data/lib/tp_plus/nodes/comment_node.rb +22 -22
  15. data/lib/tp_plus/nodes/conditional_node.rb +60 -54
  16. data/lib/tp_plus/nodes/definition_node.rb +22 -22
  17. data/lib/tp_plus/nodes/digit_node.rb +22 -21
  18. data/lib/tp_plus/nodes/empty_stmt_node.rb +9 -0
  19. data/lib/tp_plus/nodes/eval_node.rb +13 -13
  20. data/lib/tp_plus/nodes/expression_node.rb +68 -65
  21. data/lib/tp_plus/nodes/for_node.rb +20 -20
  22. data/lib/tp_plus/nodes/header_node.rb +27 -27
  23. data/lib/tp_plus/nodes/indirect_node.rb +51 -49
  24. data/lib/tp_plus/nodes/inline_conditional_node.rb +40 -40
  25. data/lib/tp_plus/nodes/io_method_node.rb +55 -55
  26. data/lib/tp_plus/nodes/io_node.rb +31 -30
  27. data/lib/tp_plus/nodes/jump_node.rb +23 -23
  28. data/lib/tp_plus/nodes/label_definition_node.rb +21 -21
  29. data/lib/tp_plus/nodes/motion_node.rb +62 -62
  30. data/lib/tp_plus/nodes/namespace_node.rb +16 -16
  31. data/lib/tp_plus/nodes/namespaced_var_node.rb +38 -38
  32. data/lib/tp_plus/nodes/numreg_node.rb +26 -25
  33. data/lib/tp_plus/nodes/offset_node.rb +27 -27
  34. data/lib/tp_plus/nodes/operator_node.rb +78 -72
  35. data/lib/tp_plus/nodes/paren_expression_node.rb +17 -0
  36. data/lib/tp_plus/nodes/pause_node.rb +9 -9
  37. data/lib/tp_plus/nodes/position_data_node.rb +64 -50
  38. data/lib/tp_plus/nodes/position_node.rb +26 -25
  39. data/lib/tp_plus/nodes/posreg_node.rb +64 -48
  40. data/lib/tp_plus/nodes/raise_node.rb +13 -13
  41. data/lib/tp_plus/nodes/real_node.rb +27 -27
  42. data/lib/tp_plus/nodes/set_skip_node.rb +14 -0
  43. data/lib/tp_plus/nodes/skip_node.rb +22 -22
  44. data/lib/tp_plus/nodes/speed_node.rb +29 -29
  45. data/lib/tp_plus/nodes/string_node.rb +13 -13
  46. data/lib/tp_plus/nodes/string_register_node.rb +26 -25
  47. data/lib/tp_plus/nodes/termination_node.rb +23 -18
  48. data/lib/tp_plus/nodes/terminator_node.rb +16 -16
  49. data/lib/tp_plus/nodes/time_node.rb +24 -24
  50. data/lib/tp_plus/nodes/timer_method_node.rb +37 -37
  51. data/lib/tp_plus/nodes/timer_node.rb +16 -21
  52. data/lib/tp_plus/nodes/units_node.rb +20 -20
  53. data/lib/tp_plus/nodes/use_node.rb +21 -21
  54. data/lib/tp_plus/nodes/user_alarm_node.rb +16 -15
  55. data/lib/tp_plus/nodes/var_method_node.rb +23 -23
  56. data/lib/tp_plus/nodes/var_node.rb +39 -39
  57. data/lib/tp_plus/nodes/vision_register_node.rb +22 -21
  58. data/lib/tp_plus/nodes/wait_for_node.rb +54 -54
  59. data/lib/tp_plus/nodes/wait_until_node.rb +65 -65
  60. data/lib/tp_plus/nodes/while_node.rb +42 -36
  61. data/lib/tp_plus/parser.rb +1682 -1592
  62. data/lib/tp_plus/scanner.rb +283 -383
  63. data/lib/tp_plus/token.rb +97 -0
  64. data/lib/tp_plus/version.rb +3 -3
  65. data/lib/tp_plus.rb +66 -62
  66. data/test/test_helper.rb +5 -5
  67. data/test/tp_plus/test_interpreter.rb +1309 -1168
  68. data/test/tp_plus/test_parser.rb +496 -489
  69. data/test/tp_plus/test_scanner.rb +577 -522
  70. data/tp_plus.gemspec +31 -28
  71. metadata +61 -14
  72. data/lib/tp_plus/nodes/set_node.rb +0 -22
@@ -1,24 +1,24 @@
1
- module TPPlus
2
- module Nodes
3
- class TimeNode
4
- def initialize(type, time, action)
5
- @type = type
6
- @time = time
7
- @action = action
8
- end
9
-
10
- def type
11
- case @type.downcase
12
- when "time_before"
13
- "TB"
14
- when "time_after"
15
- "TA"
16
- end
17
- end
18
-
19
- def eval(context)
20
- "#{type} #{@time.eval(context,as_string: true)}sec,#{@action.eval(context)}"
21
- end
22
- end
23
- end
24
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class TimeNode
4
+ def initialize(type, time, action)
5
+ @type = type
6
+ @time = time
7
+ @action = action
8
+ end
9
+
10
+ def type
11
+ case @type.downcase
12
+ when "time_before"
13
+ "TB"
14
+ when "time_after"
15
+ "TA"
16
+ end
17
+ end
18
+
19
+ def eval(context)
20
+ "#{type} #{@time.eval(context,as_string: true)}sec,#{@action.eval(context)}"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,37 +1,37 @@
1
- module TPPlus
2
- module Nodes
3
- class TimerMethodNode
4
- def initialize(method, target)
5
- @method = method
6
- @target = target
7
- end
8
-
9
- def requires_mixed_logic?(context)
10
- true
11
- end
12
-
13
- def can_be_inlined?
14
- false
15
- end
16
-
17
- def timer(context)
18
- @timer ||= @target.eval(context)
19
- end
20
-
21
- def eval(context,options={})
22
- case @method
23
- when :start
24
- "#{timer(context)}=START"
25
- when :stop
26
- "#{timer(context)}=STOP"
27
- when :reset
28
- "#{timer(context)}=RESET"
29
- when :restart
30
- "#{timer(context)}=STOP ;\n#{timer(context)}=RESET ;\n#{timer(context)}=START"
31
- else
32
- raise "Invalid timer method (#{@method})"
33
- end
34
- end
35
- end
36
- end
37
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class TimerMethodNode
4
+ def initialize(method, target)
5
+ @method = method
6
+ @target = target
7
+ end
8
+
9
+ def requires_mixed_logic?(context)
10
+ true
11
+ end
12
+
13
+ def can_be_inlined?
14
+ false
15
+ end
16
+
17
+ def timer(context)
18
+ @timer ||= @target.eval(context)
19
+ end
20
+
21
+ def eval(context,options={})
22
+ case @method
23
+ when "start"
24
+ "#{timer(context)}=START"
25
+ when "stop"
26
+ "#{timer(context)}=STOP"
27
+ when "reset"
28
+ "#{timer(context)}=RESET"
29
+ when "restart"
30
+ "#{timer(context)}=STOP ;\n#{timer(context)}=RESET ;\n#{timer(context)}=START"
31
+ else
32
+ raise "Invalid timer method (#{@method})"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,21 +1,16 @@
1
- module TPPlus
2
- module Nodes
3
- class TimerNode
4
- attr_accessor :comment
5
- def initialize(id)
6
- @id = id
7
- @comment = ""
8
- end
9
-
10
- def comment_string
11
- return "" if @comment == ""
12
-
13
- ":#{comment}"
14
- end
15
-
16
- def eval(context, options={})
17
- "TIMER[#{@id}#{comment_string}]"
18
- end
19
- end
20
- end
21
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class TimerNode
4
+ attr_accessor :comment
5
+ attr_reader :id
6
+ def initialize(id)
7
+ @id = id
8
+ @comment = ""
9
+ end
10
+
11
+ def eval(context, options={})
12
+ "TIMER[#{@id}]" # FANUC does not like timer comments
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,20 +1,20 @@
1
- module TPPlus
2
- module Nodes
3
- class UnitsNode
4
- def initialize(s)
5
- @s = s
6
- end
7
-
8
- def eval(context)
9
- case @s
10
- when "mm/s"
11
- "mm/sec"
12
- when "%"
13
- "%"
14
- else
15
- raise "Unknown unit: #{@s}"
16
- end
17
- end
18
- end
19
- end
20
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class UnitsNode
4
+ def initialize(s)
5
+ @s = s
6
+ end
7
+
8
+ def eval(context)
9
+ case @s
10
+ when "mm/s"
11
+ "mm/sec"
12
+ when "%"
13
+ "%"
14
+ else
15
+ raise "Unknown unit: #{@s}"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,21 +1,21 @@
1
- module TPPlus
2
- module Nodes
3
- class UseNode
4
- def initialize(type, value)
5
- @type = type
6
- @value = value
7
- end
8
-
9
- def eval(context)
10
- case @type
11
- when "use_uframe"
12
- "UFRAME_NUM=#{@value.eval(context)}"
13
- when "use_utool"
14
- "UTOOL_NUM=#{@value.eval(context)}"
15
- when "use_payload"
16
- "PAYLOAD[#{@value.eval(context)}]"
17
- end
18
- end
19
- end
20
- end
21
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class UseNode
4
+ def initialize(type, value)
5
+ @type = type
6
+ @value = value
7
+ end
8
+
9
+ def eval(context)
10
+ case @type
11
+ when "use_uframe"
12
+ "UFRAME_NUM=#{@value.eval(context)}"
13
+ when "use_utool"
14
+ "UTOOL_NUM=#{@value.eval(context)}"
15
+ when "use_payload"
16
+ "PAYLOAD[#{@value.eval(context)}]"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,15 +1,16 @@
1
- module TPPlus
2
- module Nodes
3
- class UserAlarmNode
4
- attr_accessor :comment
5
- def initialize(id)
6
- @id = id
7
- @comment = ""
8
- end
9
-
10
- def eval(context, options={})
11
- "UALM[#{@id}]"
12
- end
13
- end
14
- end
15
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class UserAlarmNode
4
+ attr_accessor :comment
5
+ attr_reader :id
6
+ def initialize(id)
7
+ @id = id
8
+ @comment = ""
9
+ end
10
+
11
+ def eval(context, options={})
12
+ "UALM[#{@id}]"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,23 +1,23 @@
1
- module TPPlus
2
- module Nodes
3
- class VarMethodNode
4
- attr_reader :identifier
5
- def initialize(identifier, method)
6
- @identifier = identifier
7
- @method = method
8
- end
9
-
10
- def requires_mixed_logic?(context)
11
- node(context).requires_mixed_logic?(context)
12
- end
13
-
14
- def node(context)
15
- context.get_var(@identifier)
16
- end
17
-
18
- def eval(context,options={})
19
- node(context).eval(context,options.merge(method:@method))
20
- end
21
- end
22
- end
23
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class VarMethodNode
4
+ attr_reader :identifier
5
+ def initialize(identifier, method)
6
+ @identifier = identifier
7
+ @method = method || {}
8
+ end
9
+
10
+ def requires_mixed_logic?(context)
11
+ node(context).requires_mixed_logic?(context)
12
+ end
13
+
14
+ def node(context)
15
+ context.get_var(@identifier)
16
+ end
17
+
18
+ def eval(context,options={})
19
+ node(context).eval(context,options.merge(@method))
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,39 +1,39 @@
1
- module TPPlus
2
- module Nodes
3
- class VarNode
4
- attr_reader :identifier
5
- def initialize(identifier)
6
- @identifier = identifier
7
- end
8
-
9
- def target_node(context)
10
- constant? ? context.get_constant(@identifier) : context.get_var(@identifier)
11
- end
12
-
13
- def constant?
14
- @identifier.upcase == @identifier
15
- end
16
-
17
- def requires_mixed_logic?(context)
18
- target_node(context).requires_mixed_logic?(context)
19
- end
20
-
21
- def with_parens(s, options)
22
- return s unless options[:as_condition]
23
-
24
- "(#{s})"
25
- end
26
-
27
- def eval(context,options={})
28
- return target_node(context).eval(context) if constant?
29
-
30
- s = ""
31
- if options[:opposite]
32
- s += "!"
33
- end
34
-
35
- with_parens(s + target_node(context).eval(context, options), options)
36
- end
37
- end
38
- end
39
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class VarNode
4
+ attr_reader :identifier
5
+ def initialize(identifier)
6
+ @identifier = identifier
7
+ end
8
+
9
+ def target_node(context)
10
+ constant? ? context.get_constant(@identifier) : context.get_var(@identifier)
11
+ end
12
+
13
+ def constant?
14
+ @identifier.upcase == @identifier
15
+ end
16
+
17
+ def requires_mixed_logic?(context)
18
+ target_node(context).requires_mixed_logic?(context)
19
+ end
20
+
21
+ def with_parens(s, options)
22
+ return s unless options[:as_condition]
23
+
24
+ "(#{s})"
25
+ end
26
+
27
+ def eval(context,options={})
28
+ return target_node(context).eval(context) if constant?
29
+
30
+ s = ""
31
+ if options[:opposite]
32
+ s += "!"
33
+ end
34
+
35
+ with_parens(s + target_node(context).eval(context, options), options)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,21 +1,22 @@
1
- module TPPlus
2
- module Nodes
3
- class VisionRegisterNode
4
- attr_accessor :comment
5
- def initialize(id)
6
- @id = id
7
- @comment = ""
8
- end
9
-
10
- def comment_string
11
- return "" if @comment == ""
12
-
13
- ":#{@comment}"
14
- end
15
-
16
- def eval(context,options={})
17
- "VR[#{@id}#{comment_string}]"
18
- end
19
- end
20
- end
21
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class VisionRegisterNode
4
+ attr_accessor :comment
5
+ attr_reader :id
6
+ def initialize(id)
7
+ @id = id
8
+ @comment = ""
9
+ end
10
+
11
+ def comment_string
12
+ return "" if @comment == ""
13
+
14
+ ":#{@comment}"
15
+ end
16
+
17
+ def eval(context,options={})
18
+ "VR[#{@id}#{comment_string}]"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,54 +1,54 @@
1
- module TPPlus
2
- module Nodes
3
- class WaitForNode
4
- def initialize(time, units)
5
- @time = time
6
- @units = units
7
- end
8
-
9
- def units_valid?
10
- ["s","ms"].include?(@units)
11
- end
12
-
13
- # 2 decimal places and remove leading 0s
14
- def time(context)
15
- if @time.eval(context).is_a?(String)
16
- case @units
17
- when "s"
18
- @time.eval(context)
19
- else
20
- raise "Invalid units"
21
- end
22
- else
23
- ("%.2f" % case @units
24
- when "s"
25
- @time.eval(context)
26
- when "ms"
27
- @time.eval(context).to_f / 1000
28
- end).sub(/^0+/, "") + "(sec)"
29
- end
30
- end
31
-
32
- def can_be_inlined?
33
- false
34
- end
35
-
36
- def expression
37
- case @units
38
- when "s"
39
- @time
40
- when "ms"
41
- e = ExpressionNode.new(@time,"/",DigitNode.new(1000))
42
- e.grouped = true
43
- e
44
- end
45
- end
46
-
47
- def eval(context)
48
- raise "Invalid units" unless units_valid?
49
-
50
- "WAIT #{time(context)}"
51
- end
52
- end
53
- end
54
- end
1
+ module TPPlus
2
+ module Nodes
3
+ class WaitForNode
4
+ def initialize(time, units)
5
+ @time = time
6
+ @units = units
7
+ end
8
+
9
+ def units_valid?
10
+ ["s","ms"].include?(@units)
11
+ end
12
+
13
+ # 2 decimal places and remove leading 0s
14
+ def time(context)
15
+ if @time.eval(context).is_a?(String)
16
+ case @units
17
+ when "s"
18
+ @time.eval(context)
19
+ else
20
+ raise "Invalid units"
21
+ end
22
+ else
23
+ ("%.2f" % case @units
24
+ when "s"
25
+ @time.eval(context)
26
+ when "ms"
27
+ @time.eval(context).to_f / 1000
28
+ end).sub(/^0+/, "") + "(sec)"
29
+ end
30
+ end
31
+
32
+ def can_be_inlined?
33
+ false
34
+ end
35
+
36
+ def expression
37
+ case @units
38
+ when "s"
39
+ @time
40
+ when "ms"
41
+ e = ExpressionNode.new(@time,"/",DigitNode.new(1000))
42
+ e.grouped = true
43
+ e
44
+ end
45
+ end
46
+
47
+ def eval(context)
48
+ raise "Invalid units" unless units_valid?
49
+
50
+ "WAIT #{time(context)}"
51
+ end
52
+ end
53
+ end
54
+ end