class Rookout::Processor::Paths::Canopy::Actions

Attributes

operations[R]

Public Class Methods

new(namespace) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 11
def initialize namespace
  @namespace = namespace
  @operations = []
end

Public Instance Methods

make_and_execute_namespace_operation(input, start, finish, elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 51
def make_and_execute_namespace_operation input, start, finish, elements
  # Element 1 will not be null
  # Element 2 is a list of another elements (can be empty)
  # element1.(element2.element3.element4)
  # For further explanation, check ArithmeticPath.peg
  @operations = []
  @operations.push elements[1]

  elements[2].elements.each { |e| @operations.push e }

  @operations.each do |op|
    return op if op.is_a? ToolExceptionMarker
  end

  result = elements[1].read @namespace, false
  elements[2].elements.each do |e|
    result = e.read result, false
  end

  NamespaceResult.new result, input[start...finish]
rescue StandardError => e
  ToolExceptionMarker.new e
end
make_apostrophe_string(_input, _start, _finish, elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 131
def make_apostrophe_string _input, _start, _finish, elements
  Text.new elements[2].text
end
make_attribute(input, start, finish, _elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 47
def make_attribute input, start, finish, _elements
  AttributeOperation.new input[start...finish]
end
make_attribute_operation(input, start, finish, _elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 43
def make_attribute_operation input, start, finish, _elements
  AttributeOperation.new input[start + 1...finish]
end
make_bool(input, start, finish, _elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 169
def make_bool input, start, finish, _elements
  Bool.new input[start...finish].delete " "
end
make_char(input, start, finish, _elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 165
def make_char input, start, finish, _elements
  Char.new input[start...finish].delete " "
end
make_comp_exp(_input, _start, _finish, elements) click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/rookout/processor/paths/canopy/actions.rb, line 82
def make_comp_exp _input, _start, _finish, elements
  # We can assume the following: atom ( opt_ atom )*
  # the first (which must be) will be simple atom
  # the second and so forth will always be pair <Opt, Atom>
  # Its important to remember that this execution will handle the inner brackets if exist
  # In order to handle priority (which i could not figure out if available with canopy library):
  # 1. lets make the tree flat
  # 2. handle priority ourselves - (atom opt1 atom) will be handled before (atom opt2 atom)
  #   and will return TreeNode with result
  # For further explanation, check ArithmeticPath.peg

  # handle case the size is 1
  return elements[0] if elements[1].elements.empty? || elements[0].is_a?(ToolExceptionMarker)

  flat_elements = [elements[0]]
  elements[1].elements.each do |it|
    return it.elements[1] if it.elements[1].is_a? ToolExceptionMarker

    flat_elements.push it.elements[0]
    flat_elements.push it.elements[1]
  end

  until flat_elements.length == 1
    restart_scan = false

    ALL_LEVELS.each_with_index do |_, level|
      flat_elements.each_with_index do |e, index|
        if e.is_a?(Opt) && e.level == level
          result = e.execute_operation flat_elements[index - 1], flat_elements[index + 1]
          flat_elements = flat_elements[0...index - 1] + [result] + flat_elements[index + 2..-1]
          restart_scan = true
          break
        end

        break if restart_scan
      end

      break if restart_scan
    end
  end

  flat_elements[0]
end
make_comp_exp_ex(_input, _start, _finish, elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 75
def make_comp_exp_ex _input, _start, _finish, elements
  # Element 2 is the actual expression
  # For further explanation, check ArithmeticPath.peg
  elements[2]
end
make_float(input, start, finish, _elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 157
def make_float input, start, finish, _elements
  FloatNumber.new input[start...finish].delete " "
end
make_function_operation(_input, _start, _finish, elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 22
def make_function_operation _input, _start, _finish, elements
  name = elements[0].text + elements[1].text
  return elements[3] if elements[3].is_a? Exceptions::ToolException

  args = elements[3].text
  FunctionOperation.new name, args
end
make_function_operation_access(_input, _start, _finish, elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 30
def make_function_operation_access _input, _start, _finish, elements
  # To build the function name, we will merge the unicode_set and all the unicode_set_with_numbers
  # To build the args we will simply read the atom at index 4
  #   which can be result of another operation; thus checking for exception
  # For further explanation, check ArithmeticPath.peg

  return elements[4] if elements[4].is_a? ToolExceptionMarker

  function_name = elements[1].text + elements[2].text
  args = elements[4].text
  FunctionOperation.new function_name, args
end
make_list(input, start, finish, elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 139
def make_list input, start, finish, elements
  list = []
  items_to_scan = [elements[3]]
  until items_to_scan.empty?
    item = items_to_scan.pop

    if item.is_a? Marker
      list.push item
    else
      item.elements.each do |e|
        items_to_scan.push e
      end
    end
  end

  List.new list, input[start...finish]
end
make_lookup_operation(input, start, finish, _elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 18
def make_lookup_operation input, start, finish, _elements
  LookupOperation.new input[start + 1...finish - 1]
end
make_null(_input, _start, _finish, _elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 173
def make_null _input, _start, _finish, _elements
  Nil.new
end
make_number(input, start, finish, _elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 161
def make_number input, start, finish, _elements
  Number.new input[start...finish].delete " "
end
make_opt(_input, _start, _finish, elements) click to toggle source

rubocop:enable Metrics/AbcSize

# File lib/rookout/processor/paths/canopy/actions.rb, line 127
def make_opt _input, _start, _finish, elements
  Opt.new elements[1].text
end
make_string(_input, _start, _finish, elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 135
def make_string _input, _start, _finish, elements
  Text.new elements[2].text
end
make_undefined(_input, _start, _finish, _elements) click to toggle source
# File lib/rookout/processor/paths/canopy/actions.rb, line 177
def make_undefined _input, _start, _finish, _elements
  Nil.new
end