Sha256: ea1e5bb00d5222c558583204a5d20272c93ef35287ee4ab6c5767ed4e4f5f755

Contents?: true

Size: 1 KB

Versions: 10

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require_relative 'dotted_item'

module Rley # This module is used as a namespace
  module Base # This module is used as a namespace
    # Mix-in module. Builds the dotted items for a given grammar
    module GrmItemsBuilder
      # Build an array of dotted items from the productions of passed grammar.
      # @param aGrammar [Syntax::Grammar]
      # @return [Array<DottedItem>]
      def build_dotted_items(aGrammar)
        items = []
        aGrammar.rules.each do |prod|
          index_prev = items.size
          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

          prod.constraints.each do |cs|
            # Attach constraint to dotted item n + 1
            items[index_prev + cs.idx_symbol + 1].constraint = cs
          end
        end

        return items
      end
    end # module
  end # module
end # module
# End of file

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rley-0.8.11 lib/rley/base/grm_items_builder.rb
rley-0.8.10 lib/rley/base/grm_items_builder.rb
rley-0.8.09 lib/rley/base/grm_items_builder.rb
rley-0.8.08 lib/rley/base/grm_items_builder.rb
rley-0.8.06 lib/rley/base/grm_items_builder.rb
rley-0.8.05 lib/rley/base/grm_items_builder.rb
rley-0.8.03 lib/rley/base/grm_items_builder.rb
rley-0.8.02 lib/rley/base/grm_items_builder.rb
rley-0.8.01 lib/rley/base/grm_items_builder.rb
rley-0.8.00 lib/rley/base/grm_items_builder.rb