Skip to content

Commit 2243f29

Browse files
committed
add distance before motion modifier
``` point1 := P[1] pin1 := DO[1] point1.joints -> [0,0,0,0,0,0] linear_move.to(point1).at(100, 'mm/s').term(0).distance_before(100, foo()) linear_move.to(point1).at(100, 'mm/s').term(0).distance_before(100, turn_on(pin1)) ```
1 parent d41bd9f commit 2243f29

File tree

7 files changed

+2478
-2347
lines changed

7 files changed

+2478
-2347
lines changed

generators/parser.y

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class TPPlus::Parser
22
token ASSIGN AT_SYM COMMENT MESSAGE WARNING JUMP IO_METHOD INPUT OUTPUT
3-
token NUMREG POSREG VREG SREG TIME_SEGMENT ARG UALM TOOLREG FRAMEREG
3+
token NUMREG POSREG VREG SREG TIME_SEGMENT DISTANCE_SEGMENT ARG UALM TOOLREG FRAMEREG
44
token MOVE DOT TO DOWNTO MID AT ACC TERM OFFSET SKIP GROUP COORD
55
token MROT PTH WJNT INC BREAK RTCP FPLIN
66
token AP_LD RT_LD CD CR INDEV EV PSPD CTV
@@ -429,8 +429,10 @@ rule
429429
{ result = TerminationNode.new(val[2],val[4],nil) }
430430
| DOT swallow_newlines OFFSET LPAREN var_or_indirect RPAREN
431431
{ result = OffsetNode.new(val[2],val[4]) }
432-
| DOT swallow_newlines TIME_SEGMENT LPAREN time COMMA time_seg_actions RPAREN
432+
| DOT swallow_newlines TIME_SEGMENT LPAREN time COMMA seg_actions RPAREN
433433
{ result = TimeNode.new(val[2],val[4],val[6]) }
434+
| DOT swallow_newlines DISTANCE_SEGMENT LPAREN distance COMMA seg_actions RPAREN
435+
{ result = DistanceNode.new(val[2],val[4],val[6]) }
434436
| DOT swallow_newlines SKIP LPAREN label optional_lpos_arg RPAREN
435437
{ result = SkipNode.new(val[4],val[5]) }
436438
| DOT swallow_newlines valid_motion_statements
@@ -486,7 +488,7 @@ rule
486488
| { result = nil }
487489
;
488490

489-
time_seg_actions
491+
seg_actions
490492
: program_call
491493
| io_method
492494
;
@@ -495,6 +497,10 @@ rule
495497
: var
496498
| number
497499
;
500+
501+
distance
502+
: number
503+
;
498504

499505
speed
500506
: indirectable COMMA STRING { result = { speed: val[0], units: val[2] } }

lib/tp_plus.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module TPPlus
3030
require_relative 'tp_plus/nodes/conditional_block_node'
3131
require_relative 'tp_plus/nodes/definition_node'
3232
require_relative 'tp_plus/nodes/digit_node'
33+
require_relative 'tp_plus/nodes/distance_node'
3334
require_relative 'tp_plus/nodes/empty_stmt_node'
3435
require_relative 'tp_plus/nodes/eval_node'
3536
require_relative 'tp_plus/nodes/expression_node'

lib/tp_plus/nodes/distance_node.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module TPPlus
2+
module Nodes
3+
class DistanceNode < BaseNode
4+
def initialize(type, distance, action)
5+
@type = type
6+
@distance = distance
7+
@action = action
8+
end
9+
10+
def type
11+
case @type.downcase
12+
when "distance_before"
13+
"DB"
14+
end
15+
end
16+
17+
def eval(context)
18+
"#{type} #{@distance.eval(context,as_string: true)}mm,#{@action.eval(context)}"
19+
end
20+
end
21+
end
22+
end

0 commit comments

Comments
 (0)