Class: Musa::GenerativeGrammar::Implementation::RepeatNode Private

Inherits:
Node
  • Object
show all
Defined in:
lib/musa-dsl/generative/generative-grammar.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Node representing repetition of a node.

Generates options with different repetition counts. Created by Node#repeat.

Instance Method Summary collapse

Constructor Details

#initialize(node, max = nil) ⇒ RepeatNode

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RepeatNode.

Parameters:

  • node (Node)

    node to repeat

  • max (Integer, nil) (defaults to: nil)

    maximum repetitions (nil = infinite)



613
614
615
616
617
618
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 613

def initialize(node, max = nil)
  @node = node
  @max = max

  super()
end

Instance Method Details

#_options(parent: nil, depth: nil, &condition) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 621

def _options(parent: nil, depth: nil, &condition)
  parent ||= []
  depth ||= 0

  r = []

  if @max.nil? || depth < @max
    node_options = @node._options(parent: parent, &condition)

    node_options.each do |node_option|
      r << node_option

      node_suboptions = _options(parent: parent + node_option, depth: depth + 1, &condition)

      node_suboptions.each do |node_suboption|
        r << node_option + node_suboption
      end
    end
  end

  r
end