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

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

Instance Method Summary collapse

Methods inherited from Node

#[], #limit, #next, #options, #or, #repeat, #size, #to_serie

Constructor Details

#initialize(node, max = nil) ⇒ RepeatNode

Returns a new instance of RepeatNode.



255
256
257
258
259
260
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 255

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

  super()
end

Instance Method Details

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



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 262

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