Class: Dhaka::ParseTreeCompositeNode
- Inherits:
-
Object
- Object
- Dhaka::ParseTreeCompositeNode
- Defined in:
- lib/dhaka/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
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
-
#head_node? ⇒ Boolean
:nodoc:.
-
#initialize(production) ⇒ ParseTreeCompositeNode
constructor
:nodoc:.
-
#linearize ⇒ Object
:nodoc:.
-
#to_dot(graph) ⇒ Object
Returns the dot representation of this node.
-
#to_s ⇒ Object
:nodoc:.
- #tokens ⇒ Object
Constructor Details
#initialize(production) ⇒ ParseTreeCompositeNode
:nodoc:
6 7 8 9 |
# File 'lib/dhaka/parser/parse_tree.rb', line 6 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/dhaka/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/dhaka/parser/parse_tree.rb', line 4 def production @production end |
Instance Method Details
#head_node? ⇒ Boolean
:nodoc:
31 32 33 |
# File 'lib/dhaka/parser/parse_tree.rb', line 31 def head_node? #:nodoc: production.symbol.name == START_SYMBOL_NAME end |
#linearize ⇒ Object
:nodoc:
10 11 12 |
# File 'lib/dhaka/parser/parse_tree.rb', line 10 def linearize #:nodoc: child_nodes.collect {|child_node| child_node.linearize}.flatten + [self] end |
#to_dot(graph) ⇒ Object
Returns the dot representation of this node.
23 24 25 26 27 28 29 |
# File 'lib/dhaka/parser/parse_tree.rb', line 23 def to_dot graph graph.node(self, :label => production) child_nodes.each do |child| graph.edge(self, child) child.to_dot(graph) end end |
#to_s ⇒ Object
:nodoc:
18 19 20 |
# File 'lib/dhaka/parser/parse_tree.rb', line 18 def to_s #:nodoc: "CompositeNode: #{production.symbol} --> [#{child_nodes.join(", ")}]" end |
#tokens ⇒ Object
14 15 16 |
# File 'lib/dhaka/parser/parse_tree.rb', line 14 def tokens child_nodes.collect{|child_node| child_node.tokens}.flatten end |