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:



15
16
17
18
# File 'lib/rley/sppf/composite_node.rb', line 15

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

Instance Attribute Details

#signaturesObject (readonly)

Returns the value of attribute signatures.



8
9
10
# File 'lib/rley/parse_forest_visitor.rb', line 8

def signatures
  @signatures
end

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

Returns Sub-nodes (children).

Returns:

  • (Array<SPFFNode>)

    Sub-nodes (children).



9
10
11
# File 'lib/rley/sppf/composite_node.rb', line 9

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).



12
13
14
# File 'lib/rley/parse_forest_visitor.rb', line 12

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:



22
23
24
# File 'lib/rley/sppf/composite_node.rb', line 22

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

#inspectString

Returns a text representation of the node.

Returns:

  • (String)

    a text representation of the node.



27
28
29
# File 'lib/rley/sppf/composite_node.rb', line 27

def inspect()
  key
end

#keyString

Returns:

  • (String)


32
33
34
# File 'lib/rley/sppf/composite_node.rb', line 32

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

#signature_exist?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rley/parse_forest_visitor.rb', line 16

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