class Flor::Pro::On
Constants
- CATCHES
Public Instance Methods
rewrite_tree()
click to toggle source
# File lib/flor/pcore/on.rb, line 125 def rewrite_tree if att = find_catch # 22 rewrite_as_catch_tree(att) else rewrite_as_signal_trap_tree end end
Protected Instance Methods
find_catch()
click to toggle source
# File lib/flor/pcore/on.rb, line 138 def find_catch att_children .each_with_index { |t, i| tt = t[1].is_a?(Array) && t[1].length == 1 && t[1].first return [ tt[0], i ] if tt && tt[1] == [] && CATCHES.include?(tt[0]) } nil end
rewrite_as_catch_tree(att)
click to toggle source
# File lib/flor/pcore/on.rb, line 148 def rewrite_as_catch_tree(att) flavour, index = att atts = att_children atts.delete_at(index) l = tree[2] th = [ "on_#{flavour}", [], l, *tree[3] ] atts.each { |ac| th[1] << Flor.dup(ac) } td = [ 'def', [], l ] td[1] << [ '_att', [ [ 'msg', [], l ] ], l ] td[1] << [ '_att', [ [ 'err', [], l ] ], l ] if flavour == 'error' non_att_children.each { |nac| td[1] << Flor.dup(nac) } th[1] << td th end
rewrite_as_signal_trap_tree()
click to toggle source
# File lib/flor/pcore/on.rb, line 170 def rewrite_as_signal_trap_tree atts = att_children signame_i = atts.index { |at| at[1].size == 1 } fail Flor::FlorError.new("signal name not found in #{tree.inspect}", self) \ unless signame_i tname = atts[signame_i] tname = Flor.dup(tname[1][0]) atts.delete_at(signame_i) l = tree[2] th = [ 'trap', [], l, *tree[3] ] th[1] << [ '_att', [ [ 'point', [], l ], [ '_sqs', 'signal', l ] ], l ] th[1] << [ '_att', [ [ 'name', [], l ], tname ], l ] att_names = [] atts.each { |at| att_names << at[1][0][0] th[1] << Flor.dup(at) } th[1] << [ '_att', [ [ 'payload', [], l ], [ '_sqs', 'event', l ] ], l ] \ unless att_names.include?('payload') if (nac = non_att_children).any? td = [ 'def', [], l ] td[1] << [ '_att', [ [ 'msg', [], l ] ], l ] non_att_children.each { |nac| td[1] << Flor.dup(nac) } th[1] << td end th end