Class: Musa::GenerativeGrammar::Implementation::BlockNode

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(attributes, &block) ⇒ BlockNode

Returns a new instance of BlockNode.



168
169
170
171
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 168

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

Instance Method Details

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



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 173

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