Class: Peggy::Node
- Inherits:
-
Object
- Object
- Peggy::Node
- Defined in:
- lib/ast.rb
Instance Attribute Summary collapse
-
#first ⇒ Object
Returns the value of attribute first.
-
#from ⇒ Object
Returns the value of attribute from.
-
#name ⇒ Object
Returns the value of attribute name.
-
#next ⇒ Object
Returns the value of attribute next.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #<<(child) ⇒ Object
- #each ⇒ Object
- #format(tabs) ⇒ Object
-
#initialize(name) ⇒ Node
constructor
A new instance of Node.
- #last ⇒ Object
- #to_s(source = nil) ⇒ Object
Constructor Details
#initialize(name) ⇒ Node
Returns a new instance of Node.
5 6 7 |
# File 'lib/ast.rb', line 5 def initialize name self.name = name end |
Instance Attribute Details
#first ⇒ Object
Returns the value of attribute first.
3 4 5 |
# File 'lib/ast.rb', line 3 def first @first end |
#from ⇒ Object
Returns the value of attribute from.
3 4 5 |
# File 'lib/ast.rb', line 3 def from @from end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/ast.rb', line 3 def name @name end |
#next ⇒ Object
Returns the value of attribute next.
3 4 5 |
# File 'lib/ast.rb', line 3 def next @next end |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/ast.rb', line 3 def parent @parent end |
#to ⇒ Object
Returns the value of attribute to.
3 4 5 |
# File 'lib/ast.rb', line 3 def to @to end |
Instance Method Details
#<<(child) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/ast.rb', line 9 def << child child.parent = self if first last.next = child else first = child end end |
#each ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/ast.rb', line 18 def each child = first while child yield child child = child.next end end |
#format(tabs) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/ast.rb', line 26 def format tabs result = "#{tabs}#{self}\n" tabs << ' ' node = first while node "#{tabs}#{node.format tabs}" end tabs = tabs[0..-3] end |
#last ⇒ Object
36 37 38 39 40 41 |
# File 'lib/ast.rb', line 36 def last node = first while (n2 = node.next) node = n2 end end |
#to_s(source = nil) ⇒ Object
43 44 45 |
# File 'lib/ast.rb', line 43 def to_s source=nil source ? source[from...to] : "#{name}[#{from}...#{to}]" end |