File: index.rb

package info (click to toggle)
ruby-unparser 0.6.13-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 936 kB
  • sloc: ruby: 7,691; sh: 6; makefile: 4
file content (69 lines) | stat: -rw-r--r-- 1,355 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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 = %i[and_asgn op_asgn or_asgn].to_set.freeze

        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