Module: Rley::Base::GrmItemsBuilder

Included in:
BaseParser
Defined in:
lib/rley/base/grm_items_builder.rb

Overview

Mix-in module. Builds the dotted items for a given grammar

Instance Method Summary collapse

Instance Method Details

#build_dotted_items(aGrammar) ⇒ Array<DottedItem>

Build an array of dotted items from the productions of passed grammar.

Parameters:

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rley/base/grm_items_builder.rb', line 12

def build_dotted_items(aGrammar)
  items = []
  aGrammar.rules.each do |prod|
    rhs_size = prod.rhs.size
    if rhs_size.zero?
      items << DottedItem.new(prod, 0)
    else
      items += (0..rhs_size).map { |i| DottedItem.new(prod, i) }
    end
  end

  return items
end