Class: Musa::GenerativeGrammar::Implementation::BlockNode 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 with dynamic content generated by block.

Executes block at generation time to produce content. Block receives parent elements and attributes.

Instance Method Summary collapse

Constructor Details

#initialize(attributes) {|parent, attributes| ... } ⇒ void

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.

Parameters:

  • attributes (Hash)

    node attributes

Yields:

  • (parent, attributes)

    block to generate content



529
530
531
532
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 529

def initialize(attributes, &block)
  @attributes = attributes
  @block = block
end

Instance Method Details

#_options(parent: 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.



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 535

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

  element = @block.call(parent, @attributes)
  element = OptionElement.new(element, @attributes) unless element.is_a?(OptionElement)

  if block_given?
    if yield(parent + [element], @attributes)
      [[element]]
    else
      []
    end
  else
    [[element]]
  end
end