Sha256: 37944bc8281aee3603ce9d79846b4aa32b8cf78d3b8f53706f2ce3457cf7127c

Contents?: true

Size: 820 Bytes

Versions: 1

Compression:

Stored size: 820 Bytes

Contents

# frozen_string_literal: true

module Lrama
  class State
    class Reduce
      # https://www.gnu.org/software/bison/manual/html_node/Default-Reductions.html
      attr_reader :item, :look_ahead, :not_selected_symbols
      attr_accessor :default_reduction

      def initialize(item)
        @item = item
        @look_ahead = nil
        @not_selected_symbols = []
      end

      def rule
        @item.rule
      end

      def look_ahead=(look_ahead)
        @look_ahead = look_ahead.freeze
      end

      def add_not_selected_symbol(sym)
        @not_selected_symbols << sym
      end

      def selected_look_ahead
        if @look_ahead
          # @type ivar @look_ahead: Array<Grammar::Symbol>
          @look_ahead - @not_selected_symbols
        else
          []
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lrama-0.6.10 lib/lrama/state/reduce.rb