Sha256: 46930a15d1cc9dbd0b6a192311edcdcf7d373ccb47bdf3a713c293c043fd5c64

Contents?: true

Size: 996 Bytes

Versions: 2

Compression:

Stored size: 996 Bytes

Contents

# frozen_string_literal: true

module Lrama
  class Grammar
    class ParameterizingRule
      class Rhs
        attr_accessor :symbols, :user_code, :precedence_sym

        def initialize
          @symbols = []
          @user_code = nil
          @precedence_sym = nil
        end

        def resolve_user_code(bindings)
          return unless user_code

          resolved = Lexer::Token::UserCode.new(s_value: user_code.s_value, location: user_code.location)
          var_to_arg = {} #: Hash[String, String]
          symbols.each do |sym|
            resolved_sym = bindings.resolve_symbol(sym)
            if resolved_sym != sym
              var_to_arg[sym.s_value] = resolved_sym.s_value
            end
          end

          var_to_arg.each do |var, arg|
            resolved.references.each do |ref|
              if ref.name == var
                ref.name = arg
              end
            end
          end

          return resolved
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lrama-0.7.0 lib/lrama/grammar/parameterizing_rule/rhs.rb
lrama-0.6.11 lib/lrama/grammar/parameterizing_rule/rhs.rb