Class: Peggy::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#firstObject

Returns the value of attribute first.



3
4
5
# File 'lib/ast.rb', line 3

def first
  @first
end

#fromObject

Returns the value of attribute from.



3
4
5
# File 'lib/ast.rb', line 3

def from
  @from
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/ast.rb', line 3

def name
  @name
end

#nextObject

Returns the value of attribute next.



3
4
5
# File 'lib/ast.rb', line 3

def next
  @next
end

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/ast.rb', line 3

def parent
  @parent
end

#toObject

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

#eachObject



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

#lastObject



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