Class: Coypond::Parser
- Inherits:
-
Object
- Object
- Coypond::Parser
- Defined in:
- lib/coypond/parser.rb
Instance Attribute Summary collapse
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#modules ⇒ Object
readonly
Returns the value of attribute modules.
Instance Method Summary collapse
- #extract_ref(type, *tail) ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse(parse_tree, prefix = nil) ⇒ Object
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
6 7 8 9 10 |
# File 'lib/coypond/parser.rb', line 6 def initialize @classes = {} @modules = {} @methods = {} end |
Instance Attribute Details
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
4 5 6 |
# File 'lib/coypond/parser.rb', line 4 def classes @classes end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
4 5 6 |
# File 'lib/coypond/parser.rb', line 4 def methods @methods end |
#modules ⇒ Object (readonly)
Returns the value of attribute modules.
4 5 6 |
# File 'lib/coypond/parser.rb', line 4 def modules @modules end |
Instance Method Details
#extract_ref(type, *tail) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# 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) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 |