Class: Dhaka::ParseTreeCompositeNode
- Inherits:
-
Object
- Object
- Dhaka::ParseTreeCompositeNode
- 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.
Instance Attribute Summary collapse
-
#child_nodes ⇒ Object
readonly
Returns the value of attribute child_nodes.
-
#production ⇒ Object
readonly
Returns the value of attribute production.
Instance Method Summary collapse
-
#dot_name ⇒ Object
:nodoc:.
-
#head_node? ⇒ Boolean
:nodoc:.
-
#initialize(production) ⇒ ParseTreeCompositeNode
constructor
:nodoc:.
-
#linearize ⇒ Object
:nodoc:.
-
#to_dot ⇒ Object
Returns the dot representation of the syntax tree.
-
#to_s ⇒ Object
:nodoc:.
- #tokens ⇒ Object
Constructor Details
#initialize(production) ⇒ ParseTreeCompositeNode
:nodoc:
5 6 7 8 |
# File 'lib/parser/parse_tree.rb', line 5 def initialize(production) #:nodoc: @production = production @child_nodes = [] end |
Instance Attribute Details
#child_nodes ⇒ Object (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 |
#production ⇒ Object (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_name ⇒ Object
:nodoc:
36 37 38 |
# File 'lib/parser/parse_tree.rb', line 36 def dot_name #:nodoc: "Node#{object_id}" end |
#head_node? ⇒ Boolean
:nodoc:
32 33 34 |
# File 'lib/parser/parse_tree.rb', line 32 def head_node? #:nodoc: production.symbol.name == START_SYMBOL_NAME end |
#linearize ⇒ Object
:nodoc:
9 10 11 |
# File 'lib/parser/parse_tree.rb', line 9 def linearize #:nodoc: child_nodes.collect {|child_node| child_node.linearize}.flatten + [self] end |
#to_dot ⇒ Object
Returns the dot representation of the syntax tree.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/parser/parse_tree.rb', line 19 def to_dot result = [] result << ["digraph x {", "node [fontsize=\"10\" shape=box size=\"5\"]"] if head_node? label = self.production result << "#{dot_name} [label=\"#{label}\"]" child_nodes.each do |child| result << "#{dot_name} -> #{child.dot_name}" result << "#{child.to_dot}" end result << ['}'] if head_node? result.join("\n") end |
#to_s ⇒ Object
:nodoc:
15 16 17 |
# File 'lib/parser/parse_tree.rb', line 15 def to_s #:nodoc: "CompositeNode: #{production.symbol} --> [#{child_nodes.join(", ")}]" end |
#tokens ⇒ Object
12 13 14 |
# File 'lib/parser/parse_tree.rb', line 12 def tokens child_nodes.collect{|child_node| child_node.tokens}.flatten end |