unparser 0.4.7 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +40 -9
  3. data/bin/unparser +2 -2
  4. data/lib/unparser/abstract_type.rb +121 -0
  5. data/lib/unparser/adamantium/method_builder.rb +111 -0
  6. data/lib/unparser/adamantium.rb +150 -0
  7. data/lib/unparser/anima/attribute.rb +59 -0
  8. data/lib/unparser/anima/error.rb +23 -0
  9. data/lib/unparser/anima.rb +184 -0
  10. data/lib/unparser/ast/local_variable_scope.rb +6 -76
  11. data/lib/unparser/ast.rb +1 -3
  12. data/lib/unparser/buffer.rb +14 -25
  13. data/lib/unparser/cli.rb +85 -77
  14. data/lib/unparser/{cli/color.rb → color.rb} +4 -14
  15. data/lib/unparser/comments.rb +0 -26
  16. data/lib/unparser/concord.rb +114 -0
  17. data/lib/unparser/constants.rb +4 -53
  18. data/lib/unparser/diff.rb +98 -0
  19. data/lib/unparser/dsl.rb +0 -32
  20. data/lib/unparser/either.rb +153 -0
  21. data/lib/unparser/emitter/alias.rb +2 -8
  22. data/lib/unparser/emitter/args.rb +45 -0
  23. data/lib/unparser/emitter/argument.rb +13 -169
  24. data/lib/unparser/emitter/array.rb +27 -0
  25. data/lib/unparser/emitter/array_pattern.rb +29 -0
  26. data/lib/unparser/emitter/assignment.rb +36 -127
  27. data/lib/unparser/emitter/begin.rb +9 -84
  28. data/lib/unparser/emitter/binary.rb +7 -20
  29. data/lib/unparser/emitter/block.rb +57 -41
  30. data/lib/unparser/emitter/case.rb +6 -48
  31. data/lib/unparser/emitter/case_guard.rb +27 -0
  32. data/lib/unparser/emitter/case_match.rb +40 -0
  33. data/lib/unparser/emitter/cbase.rb +1 -3
  34. data/lib/unparser/emitter/class.rb +6 -26
  35. data/lib/unparser/emitter/const_pattern.rb +24 -0
  36. data/lib/unparser/emitter/def.rb +7 -51
  37. data/lib/unparser/emitter/defined.rb +2 -12
  38. data/lib/unparser/emitter/dstr.rb +22 -0
  39. data/lib/unparser/emitter/dsym.rb +41 -0
  40. data/lib/unparser/emitter/find_pattern.rb +18 -0
  41. data/lib/unparser/emitter/flipflop.rb +11 -10
  42. data/lib/unparser/emitter/float.rb +29 -0
  43. data/lib/unparser/emitter/flow_modifier.rb +15 -53
  44. data/lib/unparser/emitter/for.rb +5 -19
  45. data/lib/unparser/emitter/hash.rb +36 -0
  46. data/lib/unparser/emitter/hash_pattern.rb +67 -0
  47. data/lib/unparser/emitter/hookexe.rb +5 -11
  48. data/lib/unparser/emitter/if.rb +15 -71
  49. data/lib/unparser/emitter/in_match.rb +21 -0
  50. data/lib/unparser/emitter/in_pattern.rb +36 -0
  51. data/lib/unparser/emitter/index.rb +22 -89
  52. data/lib/unparser/emitter/kwargs.rb +13 -0
  53. data/lib/unparser/emitter/kwbegin.rb +31 -0
  54. data/lib/unparser/emitter/lambda.rb +0 -8
  55. data/lib/unparser/emitter/masgn.rb +20 -0
  56. data/lib/unparser/emitter/match.rb +3 -17
  57. data/lib/unparser/emitter/match_alt.rb +23 -0
  58. data/lib/unparser/emitter/match_as.rb +21 -0
  59. data/lib/unparser/emitter/match_pattern.rb +30 -0
  60. data/lib/unparser/emitter/match_pattern_p.rb +20 -0
  61. data/lib/unparser/emitter/match_rest.rb +33 -0
  62. data/lib/unparser/emitter/match_var.rb +19 -0
  63. data/lib/unparser/emitter/mlhs.rb +40 -0
  64. data/lib/unparser/emitter/module.rb +3 -9
  65. data/lib/unparser/emitter/op_assign.rb +14 -29
  66. data/lib/unparser/emitter/pair.rb +33 -0
  67. data/lib/unparser/emitter/pin.rb +19 -0
  68. data/lib/unparser/emitter/primitive.rb +93 -0
  69. data/lib/unparser/emitter/range.rb +35 -0
  70. data/lib/unparser/emitter/regexp.rb +35 -0
  71. data/lib/unparser/emitter/repetition.rb +17 -57
  72. data/lib/unparser/emitter/rescue.rb +1 -97
  73. data/lib/unparser/emitter/root.rb +17 -1
  74. data/lib/unparser/emitter/send.rb +10 -219
  75. data/lib/unparser/emitter/simple.rb +33 -0
  76. data/lib/unparser/emitter/splat.rb +13 -19
  77. data/lib/unparser/emitter/super.rb +1 -29
  78. data/lib/unparser/emitter/undef.rb +1 -9
  79. data/lib/unparser/emitter/variable.rb +1 -31
  80. data/lib/unparser/emitter/xstr.rb +72 -0
  81. data/lib/unparser/emitter/yield.rb +1 -9
  82. data/lib/unparser/emitter.rb +24 -425
  83. data/lib/unparser/equalizer.rb +98 -0
  84. data/lib/unparser/generation.rb +252 -0
  85. data/lib/unparser/node_details/send.rb +65 -0
  86. data/lib/unparser/node_details.rb +21 -0
  87. data/lib/unparser/node_helpers.rb +48 -6
  88. data/lib/unparser/validation.rb +172 -0
  89. data/lib/unparser/writer/binary.rb +99 -0
  90. data/lib/unparser/writer/dynamic_string.rb +211 -0
  91. data/lib/unparser/writer/resbody.rb +40 -0
  92. data/lib/unparser/writer/rescue.rb +43 -0
  93. data/lib/unparser/{emitter → writer}/send/attribute_assignment.rb +11 -26
  94. data/lib/unparser/writer/send/binary.rb +27 -0
  95. data/lib/unparser/writer/send/conditional.rb +25 -0
  96. data/lib/unparser/writer/send/regular.rb +33 -0
  97. data/lib/unparser/{emitter → writer}/send/unary.rb +10 -17
  98. data/lib/unparser/writer/send.rb +115 -0
  99. data/lib/unparser/writer.rb +15 -0
  100. data/lib/unparser.rb +161 -77
  101. metadata +100 -157
  102. data/.circleci/config.yml +0 -49
  103. data/.gitignore +0 -37
  104. data/.rspec +0 -4
  105. data/.rubocop.yml +0 -9
  106. data/Changelog.md +0 -156
  107. data/Gemfile +0 -9
  108. data/Gemfile.lock +0 -181
  109. data/LICENSE +0 -20
  110. data/Rakefile +0 -22
  111. data/config/devtools.yml +0 -2
  112. data/config/flay.yml +0 -3
  113. data/config/flog.yml +0 -2
  114. data/config/mutant.yml +0 -6
  115. data/config/reek.yml +0 -98
  116. data/config/rubocop.yml +0 -122
  117. data/config/yardstick.yml +0 -2
  118. data/lib/unparser/cli/differ.rb +0 -152
  119. data/lib/unparser/cli/source.rb +0 -267
  120. data/lib/unparser/emitter/empty.rb +0 -23
  121. data/lib/unparser/emitter/ensure.rb +0 -37
  122. data/lib/unparser/emitter/literal/array.rb +0 -29
  123. data/lib/unparser/emitter/literal/dynamic.rb +0 -53
  124. data/lib/unparser/emitter/literal/dynamic_body.rb +0 -132
  125. data/lib/unparser/emitter/literal/execute_string.rb +0 -38
  126. data/lib/unparser/emitter/literal/hash.rb +0 -156
  127. data/lib/unparser/emitter/literal/primitive.rb +0 -145
  128. data/lib/unparser/emitter/literal/range.rb +0 -36
  129. data/lib/unparser/emitter/literal/regexp.rb +0 -114
  130. data/lib/unparser/emitter/literal/singleton.rb +0 -26
  131. data/lib/unparser/emitter/literal.rb +0 -10
  132. data/lib/unparser/emitter/meta.rb +0 -16
  133. data/lib/unparser/emitter/redo.rb +0 -25
  134. data/lib/unparser/emitter/resbody.rb +0 -76
  135. data/lib/unparser/emitter/retry.rb +0 -25
  136. data/lib/unparser/emitter/send/binary.rb +0 -57
  137. data/lib/unparser/emitter/send/conditional.rb +0 -40
  138. data/lib/unparser/emitter/send/regular.rb +0 -40
  139. data/lib/unparser/preprocessor.rb +0 -159
  140. data/spec/integration/unparser/corpus_spec.rb +0 -111
  141. data/spec/integrations.yml +0 -92
  142. data/spec/spec_helper.rb +0 -20
  143. data/spec/unit/unparser/buffer/append_spec.rb +0 -24
  144. data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +0 -23
  145. data/spec/unit/unparser/buffer/capture_content_spec.rb +0 -17
  146. data/spec/unit/unparser/buffer/content_spec.rb +0 -38
  147. data/spec/unit/unparser/buffer/fresh_line_spec.rb +0 -20
  148. data/spec/unit/unparser/buffer/indent_spec.rb +0 -20
  149. data/spec/unit/unparser/buffer/nl_spec.rb +0 -16
  150. data/spec/unit/unparser/buffer/unindent_spec.rb +0 -20
  151. data/spec/unit/unparser/comments/consume_spec.rb +0 -22
  152. data/spec/unit/unparser/comments/take_all_spec.rb +0 -19
  153. data/spec/unit/unparser/comments/take_before_spec.rb +0 -46
  154. data/spec/unit/unparser/comments/take_eol_comments_spec.rb +0 -32
  155. data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +0 -17
  156. data/spec/unit/unparser_spec.rb +0 -1849
  157. data/unparser.gemspec +0 -32
@@ -4,77 +4,39 @@ module Unparser
4
4
  class Emitter
5
5
  # Emitter control flow modifiers
6
6
  class FlowModifier < self
7
-
8
7
  MAP = {
9
- return: K_RETURN,
10
- next: K_NEXT,
11
- break: K_BREAK
8
+ return: 'return',
9
+ next: 'next',
10
+ break: 'break'
12
11
  }.freeze
13
12
 
13
+ private_constant(*constants(false))
14
+
14
15
  handle(*MAP.keys)
15
16
 
16
- def terminated?
17
- children.empty?
17
+ def emit_heredoc_reminders
18
+ children.each do |node|
19
+ emitter(node).emit_heredoc_reminders
20
+ end
18
21
  end
19
22
 
20
23
  private
21
24
 
22
- # Perform dispatch
23
- #
24
- # @return [undefined]
25
- #
26
- # @api private
27
- #
28
25
  def dispatch
29
26
  write(MAP.fetch(node.type))
30
- case children.length
31
- when 0 # rubocop:disable Lint/EmptyWhen
32
- when 1
33
- emit_single_argument
27
+
28
+ if children.one? && n_if?(children.first)
29
+ ws
30
+ emitter(children.first).emit_ternary
34
31
  else
35
- emit_arguments
32
+ emit_arguments unless children.empty?
36
33
  end
37
34
  end
38
35
 
39
- # Emit break or return arguments
40
- #
41
- # @return [undefined]
42
- #
43
- # @api private
44
- #
45
36
  def emit_arguments
46
37
  ws
47
- head, *tail = children
48
- emit_argument(head)
49
- tail.each do |node|
50
- write(DEFAULT_DELIMITER)
51
- emit_argument(node)
52
- end
38
+ delimited(children)
53
39
  end
54
-
55
- PARENS = %i[if case begin].to_set.freeze
56
-
57
- # Emit argument
58
- #
59
- # @param [Parser::AST::Node] node
60
- #
61
- # @api private
62
- #
63
- def emit_argument(node)
64
- visit_plain(node)
65
- end
66
-
67
- # Emit single argument
68
- #
69
- # @api private
70
- #
71
- def emit_single_argument
72
- ws
73
- conditional_parentheses(PARENS.include?(first_child.type)) do
74
- visit_plain(first_child)
75
- end
76
- end
77
-
78
40
  end # Return
79
41
  end # Emitter
80
42
  end # Unparser
@@ -4,38 +4,24 @@ module Unparser
4
4
  class Emitter
5
5
  # Emitter for for nodes
6
6
  class For < self
7
- include Terminated
8
-
9
7
  handle :for
10
8
 
11
9
  children :condition, :assignment, :body
12
10
 
13
11
  private
14
12
 
15
- # Perform dispatch
16
- #
17
- # @return [undefined]
18
- #
19
- # @api private
20
- #
21
13
  def dispatch
22
- write(K_FOR, WS)
14
+ write('for ')
23
15
  emit_condition
24
- emit_body
16
+ emit_optional_body(body)
25
17
  k_end
26
18
  end
27
19
 
28
- # Emit assignment
29
- #
30
- # @return [undefined]
31
- #
32
- # @api private
33
- #
34
20
  def emit_condition
35
- visit_plain(condition)
36
- write(WS, K_IN, WS)
21
+ visit(condition)
22
+ write(' in ')
37
23
  visit(assignment)
38
- write(WS, K_DO)
24
+ write(' do')
39
25
  end
40
26
 
41
27
  end # For
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unparser
4
+ class Emitter
5
+ # Emitter for Hash literals
6
+ class Hash < self
7
+ handle :hash
8
+
9
+ def emit_heredoc_reminders
10
+ children.each(&method(:emit_heredoc_reminder_member))
11
+ end
12
+
13
+ private
14
+
15
+ def dispatch
16
+ if children.empty?
17
+ write('{}')
18
+ else
19
+ parentheses('{', '}') do
20
+ write(' ')
21
+ emit_hash_body
22
+ write(' ')
23
+ end
24
+ end
25
+ end
26
+
27
+ def emit_heredoc_reminder_member(node)
28
+ emitter(node.children.last).emit_heredoc_reminders
29
+ end
30
+
31
+ def emit_hash_body
32
+ delimited(children)
33
+ end
34
+ end # Hash
35
+ end # Emitter
36
+ end # Unparser
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unparser
4
+ class Emitter
5
+ # Emitter for hash patterns
6
+ class HashPattern < self
7
+
8
+ handle :hash_pattern
9
+
10
+ def emit_const_pattern
11
+ parentheses do
12
+ emit_hash_body
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def dispatch
19
+ parentheses('{', '}') do
20
+ emit_hash_body
21
+ end
22
+ end
23
+
24
+ def emit_hash_body
25
+ delimited(children, &method(:emit_member))
26
+ end
27
+
28
+ def emit_member(node)
29
+ case node.type
30
+ when :pair
31
+ emit_pair(node)
32
+ when :match_var
33
+ emit_match_var(node)
34
+ when :match_rest
35
+ writer_with(MatchRest, node).emit_hash_pattern
36
+ else
37
+ visit(node)
38
+ end
39
+ end
40
+
41
+ def emit_match_var(node)
42
+ write_symbol_body(node.children.first)
43
+ write(':')
44
+ end
45
+
46
+ def emit_pair(node)
47
+ key, value = node.children
48
+
49
+ if n_sym?(key)
50
+ write_symbol_body(key.children.first)
51
+ else
52
+ visit(s(:dstr, *key))
53
+ end
54
+
55
+ write(':')
56
+
57
+ ws
58
+
59
+ visit(value)
60
+ end
61
+
62
+ def write_symbol_body(symbol)
63
+ write(symbol.inspect[1..])
64
+ end
65
+ end # Pin
66
+ end # Emitter
67
+ end # Unparser
@@ -6,8 +6,8 @@ module Unparser
6
6
  class Hookexe < self
7
7
 
8
8
  MAP = {
9
- preexe: K_PREEXE,
10
- postexe: K_POSTEXE
9
+ preexe: 'BEGIN',
10
+ postexe: 'END'
11
11
  }.freeze
12
12
 
13
13
  handle(*MAP.keys)
@@ -16,16 +16,10 @@ module Unparser
16
16
 
17
17
  private
18
18
 
19
- # Perfrom dispatch
20
- #
21
- # @return [undefined]
22
- #
23
- # @api private
24
- #
25
19
  def dispatch
26
- write(MAP.fetch(node.type), WS)
27
- parentheses(*BRACKETS_CURLY) do
28
- emit_body
20
+ write(MAP.fetch(node.type), ' ')
21
+ parentheses('{', '}') do
22
+ emit_body(body)
29
23
  end
30
24
  end
31
25
 
@@ -3,25 +3,21 @@
3
3
  module Unparser
4
4
  class Emitter
5
5
  # Emitter if nodes
6
- #
7
- # ignore :reek:RepeatedConditional
8
6
  class If < self
9
7
  handle :if
10
8
 
11
9
  children :condition, :if_branch, :else_branch
12
10
 
13
- def terminated?
14
- !postcondition?
11
+ def emit_ternary
12
+ visit(condition)
13
+ write(' ? ')
14
+ visit(if_branch)
15
+ write(' : ')
16
+ visit(else_branch)
15
17
  end
16
18
 
17
19
  private
18
20
 
19
- # Perform dispatch
20
- #
21
- # @return [undefined]
22
- #
23
- # @api private
24
- #
25
21
  def dispatch
26
22
  if postcondition?
27
23
  emit_postcondition
@@ -30,105 +26,53 @@ module Unparser
30
26
  end
31
27
  end
32
28
 
33
- # Test for postcondition
34
- #
35
- # @return [Boolean]
36
- #
37
- # @api private
38
- #
39
29
  def postcondition?
40
30
  return false unless if_branch.nil? ^ else_branch.nil?
41
31
 
42
32
  body = if_branch || else_branch
43
33
 
44
- local_variable_scope.first_assignment_in_body_and_used_in_condition?(body, condition)
34
+ local_variable_scope.first_assignment_in?(body, condition)
45
35
  end
46
36
 
47
- # Emit in postcondition style
48
- #
49
- # @return [undefined]
50
- #
51
- # @api private
52
- #
53
37
  def emit_postcondition
54
- visit_plain(if_branch || else_branch)
55
- write(WS, keyword, WS)
38
+ visit(if_branch || else_branch)
39
+ write(' ', keyword, ' ')
56
40
  emit_condition
57
41
  end
58
42
 
59
- # Emit in normal style
60
- #
61
- # @return [undefined]
62
- #
63
- # @api private
64
- #
65
43
  def emit_normal
66
- write(keyword, WS)
44
+ write(keyword, ' ')
67
45
  emit_condition
68
46
  emit_if_branch
69
47
  emit_else_branch
70
48
  k_end
71
49
  end
72
50
 
73
- # Test if AST can be emitted as unless
74
- #
75
- # @return [Boolean]
76
- #
77
- # @api private
78
- #
79
51
  def unless?
80
52
  !if_branch && else_branch
81
53
  end
82
54
 
83
- # Return keyword
84
- #
85
- # @return [String]
86
- #
87
- # @api private
88
- #
89
55
  def keyword
90
- unless? ? K_UNLESS : K_IF
56
+ unless? ? 'unless' : 'if'
91
57
  end
92
58
 
93
- # Emit condition
94
- #
95
- # @return [undefined]
96
- #
97
- # @api private
98
- #
99
59
  def emit_condition
100
- if condition.type.equal?(:match_current_line)
101
- visit_plain(condition)
102
- else
103
- visit(condition)
104
- end
60
+ visit(condition)
105
61
  end
106
62
 
107
- # Emit if branch
108
- #
109
- # @return [undefined]
110
- #
111
- # @api private
112
- #
113
63
  def emit_if_branch
114
64
  if if_branch
115
- visit_indented(if_branch)
65
+ emit_body(if_branch)
116
66
  end
117
67
 
118
68
  nl if !if_branch && !else_branch
119
69
  end
120
70
 
121
- # Emit else branch
122
- #
123
- # @return [undefined]
124
- #
125
- # @api private
126
- #
127
71
  def emit_else_branch
128
72
  return unless else_branch
129
73
 
130
- write(K_ELSE) unless unless?
131
- visit_indented(else_branch)
74
+ write('else') unless unless?
75
+ emit_body(else_branch)
132
76
  end
133
77
 
134
78
  end # If
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unparser
4
+ class Emitter
5
+ # Emitter for in pattern nodes
6
+ class InMatch < self
7
+
8
+ handle :in_match
9
+
10
+ children :target, :pattern
11
+
12
+ private
13
+
14
+ def dispatch
15
+ visit(target)
16
+ write(' in ')
17
+ visit(pattern)
18
+ end
19
+ end # InMatch
20
+ end # Emitter
21
+ end # Unparser
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unparser
4
+ class Emitter
5
+ # Emitter for in pattern nodes
6
+ class InPattern < self
7
+
8
+ handle :in_pattern
9
+
10
+ children :target, :unless_guard, :branch, :else_branch
11
+
12
+ private
13
+
14
+ def dispatch
15
+ write('in')
16
+
17
+ ws
18
+
19
+ visit(target)
20
+
21
+ if unless_guard
22
+ ws
23
+ visit(unless_guard)
24
+ end
25
+
26
+ if branch
27
+ ws
28
+ write('then')
29
+ emit_body(branch)
30
+ else
31
+ nl
32
+ end
33
+ end
34
+ end # InPattern
35
+ end # Emitter
36
+ end # Unparser
@@ -3,61 +3,29 @@
3
3
  module Unparser
4
4
  class Emitter
5
5
  # Emitter for send to index references
6
- #
7
- # ignore :reek:RepeatedConditional
8
6
  class Index < self
9
7
 
10
- # Perform dispatch
11
- #
12
- # @return [undefined]
13
- #
14
- # @api private
15
- #
8
+ private
9
+
16
10
  def dispatch
17
11
  emit_receiver
18
12
  emit_operation
19
13
  end
20
14
 
21
- private
22
-
23
- # Emit receiver
24
- #
25
- # @return [undefined]
26
- #
27
- # @api private
28
- #
29
15
  def emit_receiver
30
16
  visit(first_child)
31
17
  end
32
18
 
33
- # Test for mlhs
34
- #
35
- # @return [Boolean]
36
- #
37
- # @api private
38
- #
39
- def mlhs?
40
- parent_type.equal?(:mlhs)
41
- end
42
-
43
19
  class Reference < self
44
- include Terminated
45
-
46
20
  define_group(:indices, 1..-1)
47
21
 
48
22
  handle :index
49
23
 
50
24
  private
51
25
 
52
- # Emit arguments
53
- #
54
- # @return [undefined]
55
- #
56
- # @api private
57
- #
58
26
  def emit_operation
59
- parentheses(*BRACKETS_SQUARE) do
60
- delimited_plain(indices)
27
+ parentheses('[', ']') do
28
+ delimited(indices)
61
29
  end
62
30
  end
63
31
  end # Reference
@@ -68,67 +36,32 @@ module Unparser
68
36
  handle :indexasgn
69
37
 
70
38
  VALUE_RANGE = (1..-2).freeze
71
- NO_VALUE_PARENT = IceNine.deep_freeze(%i[and_asgn op_asgn or_asgn].to_set)
72
-
73
- # Test if assign will be emitted terminated
74
- #
75
- # @return [Boolean]
76
- #
77
- # @api private
78
- #
79
- def terminated?
80
- !emit_value?
81
- end
39
+ NO_VALUE_PARENT = %i[and_asgn op_asgn or_asgn].to_set.freeze
82
40
 
83
- private
41
+ private_constant(*constants(false))
84
42
 
85
- # Emit arguments
86
- #
87
- # @return [undefined]
88
- #
89
- # @api private
90
- #
91
- def emit_operation
92
- parentheses(*BRACKETS_SQUARE) do
93
- delimited_plain(indices)
94
- end
95
-
96
- if emit_value?
97
- write(WS, T_ASN, WS)
98
- visit(children.last)
99
- end
43
+ def emit_heredoc_reminders
44
+ emitter(children.last).emit_heredoc_reminders
100
45
  end
101
46
 
102
- # The indices
103
- #
104
- # @return [Array<Parser::AST::Node>]
105
- #
106
- def indices
107
- if emit_value?
108
- children[VALUE_RANGE]
109
- else
110
- children.drop(1)
111
- end
47
+ def dispatch
48
+ emit_receiver
49
+ emit_operation(children[VALUE_RANGE])
50
+ write(' = ')
51
+ visit(children.last)
112
52
  end
113
53
 
114
- # Test if value should be emitted
115
- #
116
- # @return [Boolean]
117
- #
118
- # @api private
119
- #
120
- def emit_value?
121
- !mlhs? && !no_value_parent?
54
+ def emit_mlhs
55
+ emit_receiver
56
+ emit_operation(children.drop(1))
122
57
  end
123
58
 
124
- # Test for no value parent
125
- #
126
- # @return [Boolean]
127
- #
128
- # @api private
129
- #
130
- def no_value_parent?
131
- NO_VALUE_PARENT.include?(parent_type)
59
+ private
60
+
61
+ def emit_operation(indices)
62
+ parentheses('[', ']') do
63
+ delimited(indices)
64
+ end
132
65
  end
133
66
  end # Assign
134
67
  end # Index
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unparser
4
+ class Emitter
5
+ class Kwargs < self
6
+ handle :kwargs
7
+
8
+ def dispatch
9
+ delimited(children)
10
+ end
11
+ end # Kwargs
12
+ end # Emitter
13
+ end # Unparser
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unparser
4
+ class Emitter
5
+ # Emitter for explicit begins
6
+ class KWBegin < self
7
+ handle :kwbegin
8
+
9
+ private
10
+
11
+ def dispatch
12
+ write('begin')
13
+
14
+ if children.one?
15
+ emit_body_ensure_rescue(children.first)
16
+ else
17
+ indented do
18
+ emit_multiple_body
19
+ end
20
+ end
21
+
22
+ k_end
23
+ end
24
+
25
+ def emit_multiple_body
26
+ emit_join(children, method(:emit_body_member), method(:nl))
27
+ end
28
+
29
+ end # KWBegin
30
+ end # Emitter
31
+ end # Unparser
@@ -4,18 +4,10 @@ module Unparser
4
4
  class Emitter
5
5
  # Emitter for lambda nodes
6
6
  class Lambda < self
7
- include Terminated
8
-
9
7
  handle :lambda
10
8
 
11
9
  private
12
10
 
13
- # Perform dispatch
14
- #
15
- # @return [undefined]
16
- #
17
- # @api private
18
- #
19
11
  def dispatch
20
12
  write('->')
21
13
  end