class Flor::Pro::Cursor

Public Instance Methods

cancel() click to toggle source
Calls superclass method Flor::Procedure#cancel
# File lib/flor/pcore/cursor.rb, line 151
def cancel

  if %w[ continue move ].include?(fla = @message['flavour'])

    cid =
      fla == 'move' ?
      move_target_child_id :
      first_non_att_child_id

    @node['subs'] <<
      counter_next('subs')

    @node['on_receive_last'] =
      execute_child(cid, @node['subs'].last, 'orl' => fla)

  else

    @node['on_receive_last'] = nil
  end

  super
end
cancel_when_closed() click to toggle source
# File lib/flor/pcore/cursor.rb, line 143
def cancel_when_closed

  return cancel if node_status_flavour == 'on-error'
  return [] if @message['flavour'] != 'break'

  cancel
end
pre_execute() click to toggle source
# File lib/flor/pcore/cursor.rb, line 93
def pre_execute

  @node['atts'] = []
  @node['subs'] = []
end
receive_att() click to toggle source
Calls superclass method Flor::Procedure#receive_att
# File lib/flor/pcore/cursor.rb, line 115
def receive_att

  receive_unkeyed_tag_att + super
end
receive_first() click to toggle source
Calls superclass method Flor::Procedure#receive_first
# File lib/flor/pcore/cursor.rb, line 99
def receive_first

  # break/continue/move are set as variables so that they can
  # be aliases, it's useful in nested loops

  @node['vars'] = {
    'break' =>
      [ '_proc', { 'proc' => 'break', 'nid' => nid }, tree[-1] ],
    'continue' =>
      [ '_proc', { 'proc' => 'continue', 'nid' => nid }, tree[-1] ],
    'move' =>
      [ '_proc', { 'proc' => 'move', 'nid' => nid }, tree[-1] ] }

  super
end
receive_last_att() click to toggle source
Calls superclass method Flor::Procedure#receive_last_att
# File lib/flor/pcore/cursor.rb, line 134
def receive_last_att

  start = att('start', 'initial')
  cid = start && find_child_id(start)
  @ncid = cid if cid

  super
end
receive_non_att() click to toggle source
# File lib/flor/pcore/cursor.rb, line 120
def receive_non_att

  if @ncid >= children.size
    if @message['orl'] == 'continue'
      @node['subs'] << counter_next('subs')
      execute_child(first_non_att_child_id, @node['subs'].last)
    else
      wrap_reply
    end
  else
    execute_child(@ncid, @node['subs'].last)
  end
end

Protected Instance Methods

find_att_target(to) click to toggle source
# File lib/flor/pcore/cursor.rb, line 240
def find_att_target(to)

  tree[1]
    .index { |c|
      c[0] == '_' &&
      c[1].is_a?(Array) &&
      c[1].find { |cc|
        cc[0] == '_att' &&
        cc[1].is_a?(Array) &&
        cc[1][0][0, 2] == [ 'here', [] ] } } # FIXME hardcoded...
end
find_child_id(to) click to toggle source
# File lib/flor/pcore/cursor.rb, line 187
def find_child_id(to)

  find_tag_target(to) ||
  find_string_arg_target(to) ||
  find_string_target(to) ||
  find_name_target(to) ||
  find_att_target(to) ||
  fail(Flor::FlorError.new("move target #{to.inspect} not found", self))
end
find_name_target(to) click to toggle source
# File lib/flor/pcore/cursor.rb, line 234
def find_name_target(to)

  tree[1]
    .index { |ct| ct[0] == to }
end
find_string_arg_target(to) click to toggle source
# File lib/flor/pcore/cursor.rb, line 220
def find_string_arg_target(to)

  tree[1]
    .index { |c|
      c[1].is_a?(Array) &&
      c[1].index { |cc| is_att_string_tree?(cc, to) } }
end
find_string_target(to) click to toggle source
# File lib/flor/pcore/cursor.rb, line 228
def find_string_target(to)

  tree[1]
    .index { |ct| Flor.is_string_tree?(ct, to) }
end
find_tag_target(to) click to toggle source
# File lib/flor/pcore/cursor.rb, line 212
def find_tag_target(to)

  tree[1]
    .index { |ct|
      ct[1].is_a?(Array) &&
      ct[1].index { |cc| is_tag_tree?(cc, to) } }
end
is_att_string_tree?(t, s) click to toggle source
# File lib/flor/pcore/cursor.rb, line 205
def is_att_string_tree?(t, s)

  Flor.is_att_tree?(t) &&
  t[1].size == 1 &&
  Flor.is_string_tree?(t[1].first, s)
end
is_tag_tree?(t, tagname) click to toggle source
# File lib/flor/pcore/cursor.rb, line 197
def is_tag_tree?(t, tagname)

  Flor.is_att_tree?(t) &&
  t[1].size == 2 &&
  t[1][0][0, 2] == [ 'tag', [] ] &&
  Flor.is_string_tree?(t[1][1], tagname)
end
move_target_child_id() click to toggle source
# File lib/flor/pcore/cursor.rb, line 176
def move_target_child_id

  to = @message['to']

  fail Flor::FlorError.new(
    "move target #{to.inspect} is not a string", self
  ) unless to.is_a?(String)

  find_child_id(to)
end