module TypedRb::TypeSignature::TypeProcessor

Public Instance Methods

block_arg?(function_tokens) click to toggle source
# File lib/typed/type_signature/parser.rb, line 84
def block_arg?(function_tokens)
  function_tokens[-2] == '&'
end
parse_binding() click to toggle source
# File lib/typed/type_signature/parser.rb, line 95
def parse_binding
  new_type = parse_new_type
  @current_function << new_type unless @current_type.empty?
  @current_type = []
end
parse_block_arg(function_tokens) click to toggle source
# File lib/typed/type_signature/parser.rb, line 88
def parse_block_arg(function_tokens)
  block = { :block => function_tokens.pop,
            :kind  => :block_arg }
  function_tokens.pop
  function_tokens << block
end
parse_end_of_binding() click to toggle source
# File lib/typed/type_signature/parser.rb, line 101
def parse_end_of_binding
  bound = parse_variable_binding
  # method variables
  if bound[:kind] == :type_var && method_info[bound[:type]]
    bound = method_info[bound[:type]].dup
    bound[:sub_kind] = :method_type_var
  end
  @binding = nil
  parent_function = @stack.pop
  parent_function << bound
  @current_function = parent_function
  @current_type = []
end
parse_end_of_function() click to toggle source
# File lib/typed/type_signature/parser.rb, line 73
def parse_end_of_function
  new_type = parse_new_type
  @current_function << new_type unless @current_type.empty?
  parent_function = @stack.pop
  next_function_elem = transform_function_tokens(@current_function)
  parent_function << next_function_elem
  parse_block_arg(parent_function) if block_arg?(parent_function)
  @current_function = parent_function
  @current_type = []
end
parse_new_type() click to toggle source
# File lib/typed/type_signature/parser.rb, line 145
def parse_new_type
  new_type = @current_type.join
  new_type = :unit if new_type == 'unit'
  if new_type.to_s.end_with?('...')
    new_type = new_type.split('...').first
    new_type = @current_function.pop if new_type.nil?
    new_type =  { :type       => 'Array',
                  :kind       => :rest,
                  :parameters => [new_type] }
  end
  new_type
end
parse_next_elem() click to toggle source
# File lib/typed/type_signature/parser.rb, line 136
def parse_next_elem
  return parse_binding if @in_binding

  new_type = parse_new_type
  @current_function << new_type unless @current_type.empty?
  @current_function << :<
  @current_type = []
end
parse_start_of_type() click to toggle source
# File lib/typed/type_signature/parser.rb, line 65
def parse_start_of_type
  new_type = parse_new_type
  @current_function << new_type unless @current_type.empty?
  @stack << @current_function
  @current_type = []
  @current_function = []
end
parse_variable_binding() click to toggle source
# File lib/typed/type_signature/parser.rb, line 115
def parse_variable_binding
  new_type = parse_new_type
  @current_function << new_type unless @current_type.empty?
  if @current_function.size == 1
    { :type => @current_function.first,
      :kind => :type_var }
  else
    if @binding.nil?
      # This is the case for nested generic types
      { :type       => @current_function.first,
        :parameters => @current_function.drop(1),
        :kind       => :generic_type }
    else
      { :type    => @current_function.first,
        :bound   => @current_function.last,
        :binding => @binding,
        :kind    => :type_var }
    end
  end
end