Class: Rley::SPPF::CompositeNode

Inherits:
SPPFNode
  • Object
show all
Defined in:
lib/rley/sppf/composite_node.rb,
lib/rley/parse_forest_visitor.rb

Overview

Monkey-patching

Direct Known Subclasses

AlternativeNode, NonTerminalNode

Instance Attribute Summary collapse

Attributes inherited from SPPFNode

#range

Instance Method Summary collapse

Methods inherited from SPPFNode

#origin

Constructor Details

#initialize(aRange) ⇒ CompositeNode

Constructor

Parameters:



17
18
19
20
# File 'lib/rley/sppf/composite_node.rb', line 17

def initialize(aRange)
  super(aRange)
  @subnodes = []
end

Instance Attribute Details

#signaturesObject (readonly)

Returns the value of attribute signatures.



10
11
12
# File 'lib/rley/parse_forest_visitor.rb', line 10

def signatures
  @signatures
end

#subnodesArray<SPFFNode> (readonly) Also known as: children

Returns Sub-nodes (children).

Returns:

  • (Array<SPFFNode>)

    Sub-nodes (children).



11
12
13
# File 'lib/rley/sppf/composite_node.rb', line 11

def subnodes
  @subnodes
end

Instance Method Details

#add_edge_signatures(prime_enumerator) ⇒ Object

Associate for each edge between this node and each subnode an unique prime number (called a signature).



14
15
16
# File 'lib/rley/parse_forest_visitor.rb', line 14

def add_edge_signatures(prime_enumerator)
  @signatures = subnodes.map { |_| prime_enumerator.next }
end

#add_subnode(aSubnode) ⇒ Object

Add a sub-node (child) to this one.

Parameters:



24
25
26
# File 'lib/rley/sppf/composite_node.rb', line 24

def add_subnode(aSubnode)
  subnodes.unshift(aSubnode)
end

#inspectString

Returns a text representation of the node.

Returns:

  • (String)

    a text representation of the node.



29
30
31
# File 'lib/rley/sppf/composite_node.rb', line 29

def inspect()
  key
end

#keyString

Returns:

  • (String)


34
35
36
# File 'lib/rley/sppf/composite_node.rb', line 34

def key()
  @key ||= to_string(0)
end

#signature_exist?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/rley/parse_forest_visitor.rb', line 18

def signature_exist?()
  @signatures.nil? ? false : true
end