Class: Dendroid::Parsing::CompositeParseNode

Inherits:
ParseNode
  • Object
show all
Defined in:
lib/dendroid/parsing/composite_parse_node.rb

Overview

Composite Pattern. A specialization of parse nodes that have themselves children nodes.

Direct Known Subclasses

AndNode, OrNode

Instance Attribute Summary collapse

Attributes inherited from ParseNode

#range

Instance Method Summary collapse

Constructor Details

#initialize(lowerBound, upperBound, child_count) ⇒ CompositeParseNode

Returns a new instance of CompositeParseNode.

Parameters:

  • lowerBound (Integer)

    Rank of first input token that is matched by this node

  • upperBound (Integer)

    Rank of last input token that is matched by this node

  • child_count (Integer)

    The expected number of child nodes



15
16
17
18
# File 'lib/dendroid/parsing/composite_parse_node.rb', line 15

def initialize(lowerBound, upperBound, child_count)
  super(lowerBound, upperBound)
  @children = Array.new(child_count, nil)
end

Instance Attribute Details

#childrenArray<Dendroid::Parsing::ParseNode|NilClass> (readonly)

Returns Sub-nodes. Nil values represent available slots.

Returns:



10
11
12
# File 'lib/dendroid/parsing/composite_parse_node.rb', line 10

def children
  @children
end

Instance Method Details

#add_child(child_node, index) ⇒ Object



20
21
22
# File 'lib/dendroid/parsing/composite_parse_node.rb', line 20

def add_child(child_node, index)
  children[index] = child_node
end