Class: BabelBridge::Node
- Inherits:
-
Object
- Object
- BabelBridge::Node
- Defined in:
- lib/nodes/node.rb
Overview
base class for all parse-tree nodes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#delimiter ⇒ Object
Returns the value of attribute delimiter.
-
#many_delimiter ⇒ Object
Returns the value of attribute many_delimiter.
-
#match_length ⇒ Object
Returns the value of attribute match_length.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#src ⇒ Object
Returns the value of attribute src.
Instance Method Summary collapse
- #column ⇒ Object
- #init_line_column ⇒ Object
-
#initialize(parent) ⇒ Node
constructor
A new instance of Node.
-
#inspect(options = {}) ⇒ Object
Returns a human-readable representation of the parse tree options :simple => output a simplified representation of the parse tree.
-
#length ⇒ Object
length returns the number of sub-nodes.
- #line ⇒ Object
- #match_range ⇒ Object
- #node_init(parent_or_parser) ⇒ Object
- #node_path ⇒ Object
-
#offset_after_match ⇒ Object
(also: #next)
the index of the first character after the match.
-
#on_matched ⇒ Object
called when a ruled is matched.
-
#onlychildren_list ⇒ Object
walk down the children chain as long as there is only one child at each level log and return the path.
- #parent_list ⇒ Object
- #path_string(node_list) ⇒ Object
- #relative_class_name ⇒ Object
- #remaining_src(sub_offset) ⇒ Object
-
#text ⇒ Object
the substring in src matched.
- #to_s ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(parent) ⇒ Node
Returns a new instance of Node.
73 74 75 |
# File 'lib/nodes/node.rb', line 73 def initialize(parent) node_init(parent) end |
Instance Attribute Details
#delimiter ⇒ Object
Returns the value of attribute delimiter.
10 11 12 |
# File 'lib/nodes/node.rb', line 10 def delimiter @delimiter end |
#many_delimiter ⇒ Object
Returns the value of attribute many_delimiter.
10 11 12 |
# File 'lib/nodes/node.rb', line 10 def many_delimiter @many_delimiter end |
#match_length ⇒ Object
Returns the value of attribute match_length.
10 11 12 |
# File 'lib/nodes/node.rb', line 10 def match_length @match_length end |
#offset ⇒ Object
Returns the value of attribute offset.
10 11 12 |
# File 'lib/nodes/node.rb', line 10 def offset @offset end |
#parent ⇒ Object
Returns the value of attribute parent.
10 11 12 |
# File 'lib/nodes/node.rb', line 10 def parent @parent end |
#parser ⇒ Object
Returns the value of attribute parser.
10 11 12 |
# File 'lib/nodes/node.rb', line 10 def parser @parser end |
#src ⇒ Object
Returns the value of attribute src.
10 11 12 |
# File 'lib/nodes/node.rb', line 10 def src @src end |
Instance Method Details
#column ⇒ Object
42 43 44 45 |
# File 'lib/nodes/node.rb', line 42 def column init_line_column unless @column @column end |
#init_line_column ⇒ Object
33 34 35 |
# File 'lib/nodes/node.rb', line 33 def init_line_column @line, @column = Tools.line_column(src, offset) end |
#inspect(options = {}) ⇒ Object
Returns a human-readable representation of the parse tree options
:simple => output a simplified representation of the parse tree
80 81 82 |
# File 'lib/nodes/node.rb', line 80 def inspect(={}) "(TODO: def #{self.class}#inspect(options={}))" end |
#length ⇒ Object
length returns the number of sub-nodes
91 92 93 |
# File 'lib/nodes/node.rb', line 91 def length 0 end |
#line ⇒ Object
37 38 39 40 |
# File 'lib/nodes/node.rb', line 37 def line init_line_column unless @line @line end |
#match_range ⇒ Object
25 26 27 |
# File 'lib/nodes/node.rb', line 25 def match_range offset..(offset+match_length-1) end |
#node_init(parent_or_parser) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/nodes/node.rb', line 55 def node_init(parent_or_parser) self.match_length=0 case parent_or_parser when Parser then self.parser=parent_or_parser self.offset=0 self.src=parser.src when Node then self.parent=parent_or_parser self.parser=parent.parser self.offset=parent.next self.src=parent.src raise "parent node does not have parser set" unless parser else raise "parent_or_parser(#{parent_or_parser.class}) must be a Node or a Parser" end end |
#node_path ⇒ Object
113 114 115 |
# File 'lib/nodes/node.rb', line 113 def node_path path_string parent_list end |
#offset_after_match ⇒ Object Also known as: next
the index of the first character after the match
17 18 19 |
# File 'lib/nodes/node.rb', line 17 def offset_after_match offset + match_length end |
#on_matched ⇒ Object
called when a ruled is matched
30 31 |
# File 'lib/nodes/node.rb', line 30 def on_matched end |
#onlychildren_list ⇒ Object
walk down the children chain as long as there is only one child at each level log and return the path
101 102 103 104 105 106 107 |
# File 'lib/nodes/node.rb', line 101 def onlychildren_list if matches.length == 1 [self] + matches[0].onlychildren_list else [self] end end |
#parent_list ⇒ Object
95 96 97 |
# File 'lib/nodes/node.rb', line 95 def parent_list return parent ? parent.parent_list+[parent] : [] end |
#path_string(node_list) ⇒ Object
109 110 111 |
# File 'lib/nodes/node.rb', line 109 def path_string(node_list) node_list.collect{|n|n.class}.join ' > ' end |
#relative_class_name ⇒ Object
12 13 14 |
# File 'lib/nodes/node.rb', line 12 def relative_class_name (self.class.to_s.split(parser.class.to_s+"::",2)[1]||self.class.to_s).strip end |
#remaining_src(sub_offset) ⇒ Object
21 22 23 |
# File 'lib/nodes/node.rb', line 21 def remaining_src(sub_offset) src[self.next+sub_offset..-1] end |
#text ⇒ Object
the substring in src matched
88 |
# File 'lib/nodes/node.rb', line 88 def text; src[match_range] end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/nodes/node.rb', line 47 def to_s text end |
#to_sym ⇒ Object
51 52 53 |
# File 'lib/nodes/node.rb', line 51 def to_sym to_s.to_sym end |