class Coypond::Parser

Attributes

classes[R]
methods[R]
modules[R]

Public Class Methods

new() click to toggle source
# File lib/coypond/parser.rb, line 6
def initialize
  @classes = {}
  @modules = {}
  @methods = {}
end

Public Instance Methods

extract_ref(type, *tail) click to toggle source
# File lib/coypond/parser.rb, line 12
def extract_ref(type, *tail)
  case type
  when :const_path_ref
    var_ref = extract_ref(*(tail.first)).first
    name, location = extract_const_and_location(tail[1])
    return [[var_ref, name].join("::"), location]
  else
    return extract_const_and_location(tail.first)
  end
end
parse(parse_tree, prefix=nil) click to toggle source
# File lib/coypond/parser.rb, line 23
def parse(parse_tree, prefix=nil)
  return self unless parse_tree.is_a? Array
  case parse_tree.first
  when :module
    name, location = extract_ref(*(parse_tree[1]))
    prefix = [prefix, name].compact.join("::")
    @modules[prefix] = location
    parse_tree[2..-1].each do |pt|
      parse(pt, prefix)
    end
  when :class
    name, location = extract_ref(*(parse_tree[1]))
    prefix = [prefix, name].compact.join("::")
    @classes[prefix] = location
    parse_tree[2..-1].each do |pt|
      parse(pt, prefix)
    end
  when :def
    name, location = extract_const_and_location(parse_tree[1])
    prefix = [prefix, name].compact.join("#")
    @methods[prefix] = location
  else
    parse_tree[1..-1].each do |pt|
      parse(pt, prefix)
    end
  end
  return self
end

Private Instance Methods

extract_const_and_location(tuple) click to toggle source
# File lib/coypond/parser.rb, line 53
def extract_const_and_location(tuple)
  return tuple[1..2]
end