Sha256: d0b81601df4f7eb9dbea2bfcae1a90f4a0fd09eaf3b7d9134a6a7f96aef91863

Contents?: true

Size: 1.34 KB

Versions: 8

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Unparser
  class Emitter
    # Emitter for send to index references
    class Index < self

    private

      def dispatch
        emit_receiver
        emit_operation
      end

      def emit_receiver
        visit(first_child)
      end

      class Reference < self
        define_group(:indices, 1..-1)

        handle :index

      private

        def emit_operation
          parentheses('[', ']') do
            delimited(indices)
          end
        end
      end # Reference

      # Emitter for assign to index nodes
      class Assign < self

        handle :indexasgn

        VALUE_RANGE     = (1..-2).freeze
        NO_VALUE_PARENT = IceNine.deep_freeze(%i[and_asgn op_asgn or_asgn].to_set)

        private_constant(*constants(false))

        def emit_heredoc_reminders
          emitter(children.last).emit_heredoc_reminders
        end

        def dispatch
          emit_receiver
          emit_operation(children[VALUE_RANGE])
          write(' = ')
          visit(children.last)
        end

        def emit_mlhs
          emit_receiver
          emit_operation(children.drop(1))
        end

      private

        def emit_operation(indices)
          parentheses('[', ']') do
            delimited(indices)
          end
        end
      end # Assign
    end # Index
  end # Emitter
end # Unparser

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
unparser-0.5.7 lib/unparser/emitter/index.rb
unparser-0.5.6 lib/unparser/emitter/index.rb
unparser-0.5.5 lib/unparser/emitter/index.rb
unparser-0.5.4 lib/unparser/emitter/index.rb
unparser-0.5.3 lib/unparser/emitter/index.rb
unparser-0.5.2 lib/unparser/emitter/index.rb
unparser-0.5.1 lib/unparser/emitter/index.rb
unparser-0.5.0 lib/unparser/emitter/index.rb