Class: Dhaka::ParseTreeCompositeNode

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

Overview

These are composite nodes of the syntax tree returned by the successful parsing of a token stream.

Direct Known Subclasses

ParseSuccessResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(production) ⇒ ParseTreeCompositeNode

:nodoc:



6
7
8
9
# File 'lib/parser/parse_tree.rb', line 6

def initialize(production) #:nodoc:
  @production  = production
  @child_nodes = []
end

Instance Attribute Details

#child_nodesObject (readonly)

Returns the value of attribute child_nodes.



4
5
6
# File 'lib/parser/parse_tree.rb', line 4

def child_nodes
  @child_nodes
end

#productionObject (readonly)

Returns the value of attribute production.



4
5
6
# File 'lib/parser/parse_tree.rb', line 4

def production
  @production
end

Instance Method Details

#dot_nameObject

:nodoc:



38
39
40
# File 'lib/parser/parse_tree.rb', line 38

def dot_name #:nodoc:
  "Node#{object_id}"
end

#head_node?Boolean

:nodoc:

Returns:

  • (Boolean)


34
35
36
# File 'lib/parser/parse_tree.rb', line 34

def head_node? #:nodoc:
  production.symbol.name == START_SYMBOL_NAME
end

#linearizeObject

:nodoc:



10
11
12
# File 'lib/parser/parse_tree.rb', line 10

def linearize #:nodoc:
  child_nodes.collect {|child_node| child_node.linearize}.flatten + [self]
end

#to_dotObject

Returns the dot representation of this node.



23
24
25
26
27
28
29
30
31
32
# File 'lib/parser/parse_tree.rb', line 23

def to_dot
  result = []
  label  = production
  result << %(#{dot_name} [label="#{label}"])
  child_nodes.each do |child|
    result << "#{dot_name} -> #{child.dot_name}"
    result << "#{child.to_dot}"
  end
  result.join("\n")
end

#to_sObject

:nodoc:



18
19
20
# File 'lib/parser/parse_tree.rb', line 18

def to_s #:nodoc:
  "CompositeNode: #{production.symbol} --> [#{child_nodes.join(", ")}]"
end

#tokensObject



14
15
16
# File 'lib/parser/parse_tree.rb', line 14

def tokens
  child_nodes.collect{|child_node| child_node.tokens}.flatten
end