Sha256: 465b1277ae86f87826b1ac573bb6b7ca6a1b2ffaf61f11db7495fea60ca2e611

Contents?: true

Size: 782 Bytes

Versions: 9

Compression:

Stored size: 782 Bytes

Contents

module Lrama
  class Grammar
    class Binding
      attr_reader :actual_args, :count

      def initialize(parameterizing_rule, actual_args)
        @parameters = parameterizing_rule.parameters
        @actual_args = actual_args
        @parameter_to_arg = @parameters.zip(actual_args).map do |param, arg|
          [param.s_value, arg]
        end.to_h
      end

      def resolve_symbol(symbol)
        if symbol.is_a?(Lexer::Token::InstantiateRule)
          resolved_args = symbol.args.map { |arg| resolve_symbol(arg) }
          Lrama::Lexer::Token::InstantiateRule.new(s_value: symbol.s_value, location: symbol.location, args: resolved_args, lhs_tag: symbol.lhs_tag)
        else
          @parameter_to_arg[symbol.s_value] || symbol
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lrama-0.6.9 lib/lrama/grammar/binding.rb
lrama-0.6.8 lib/lrama/grammar/binding.rb
lrama-0.6.7 lib/lrama/grammar/binding.rb
lrama-0.6.6 lib/lrama/grammar/binding.rb
lrama-0.6.5 lib/lrama/grammar/binding.rb
lrama-0.6.4 lib/lrama/grammar/binding.rb
lrama-0.6.3 lib/lrama/grammar/binding.rb
lrama-0.6.2 lib/lrama/grammar/binding.rb
lrama-0.6.1 lib/lrama/grammar/binding.rb