unparser 0.4.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -3
- data/bin/unparser +1 -1
- data/lib/unparser.rb +117 -62
- data/lib/unparser/ast.rb +1 -2
- data/lib/unparser/ast/local_variable_scope.rb +9 -79
- data/lib/unparser/buffer.rb +19 -16
- data/lib/unparser/cli.rb +84 -77
- data/lib/unparser/{cli/color.rb → color.rb} +0 -13
- data/lib/unparser/comments.rb +0 -26
- data/lib/unparser/constants.rb +4 -53
- data/lib/unparser/diff.rb +98 -0
- data/lib/unparser/dsl.rb +0 -32
- data/lib/unparser/emitter.rb +25 -428
- data/lib/unparser/emitter/alias.rb +2 -8
- data/lib/unparser/emitter/args.rb +45 -0
- data/lib/unparser/emitter/argument.rb +17 -179
- data/lib/unparser/emitter/array.rb +27 -0
- data/lib/unparser/emitter/array_pattern.rb +29 -0
- data/lib/unparser/emitter/assignment.rb +36 -127
- data/lib/unparser/emitter/begin.rb +9 -84
- data/lib/unparser/emitter/binary.rb +7 -20
- data/lib/unparser/emitter/block.rb +57 -41
- data/lib/unparser/emitter/case.rb +6 -48
- data/lib/unparser/emitter/case_guard.rb +27 -0
- data/lib/unparser/emitter/case_match.rb +40 -0
- data/lib/unparser/emitter/cbase.rb +1 -3
- data/lib/unparser/emitter/class.rb +6 -26
- data/lib/unparser/emitter/const_pattern.rb +24 -0
- data/lib/unparser/emitter/def.rb +7 -51
- data/lib/unparser/emitter/defined.rb +2 -12
- data/lib/unparser/emitter/dstr.rb +22 -0
- data/lib/unparser/emitter/dsym.rb +41 -0
- data/lib/unparser/emitter/flipflop.rb +11 -10
- data/lib/unparser/emitter/float.rb +29 -0
- data/lib/unparser/emitter/flow_modifier.rb +8 -55
- data/lib/unparser/emitter/for.rb +5 -19
- data/lib/unparser/emitter/hash.rb +74 -0
- data/lib/unparser/emitter/hash_pattern.rb +67 -0
- data/lib/unparser/emitter/hookexe.rb +5 -11
- data/lib/unparser/emitter/if.rb +9 -73
- data/lib/unparser/emitter/in_match.rb +21 -0
- data/lib/unparser/emitter/in_pattern.rb +34 -0
- data/lib/unparser/emitter/index.rb +21 -88
- data/lib/unparser/emitter/kwbegin.rb +31 -0
- data/lib/unparser/emitter/lambda.rb +0 -8
- data/lib/unparser/emitter/masgn.rb +20 -0
- data/lib/unparser/emitter/match.rb +3 -17
- data/lib/unparser/emitter/match_alt.rb +23 -0
- data/lib/unparser/emitter/match_as.rb +21 -0
- data/lib/unparser/emitter/match_rest.rb +26 -0
- data/lib/unparser/emitter/match_var.rb +19 -0
- data/lib/unparser/emitter/mlhs.rb +40 -0
- data/lib/unparser/emitter/module.rb +3 -9
- data/lib/unparser/emitter/op_assign.rb +12 -27
- data/lib/unparser/emitter/pin.rb +19 -0
- data/lib/unparser/emitter/primitive.rb +93 -0
- data/lib/unparser/emitter/range.rb +35 -0
- data/lib/unparser/emitter/regexp.rb +35 -0
- data/lib/unparser/emitter/repetition.rb +17 -57
- data/lib/unparser/emitter/rescue.rb +1 -97
- data/lib/unparser/emitter/root.rb +17 -1
- data/lib/unparser/emitter/send.rb +10 -219
- data/lib/unparser/emitter/simple.rb +33 -0
- data/lib/unparser/emitter/splat.rb +2 -18
- data/lib/unparser/emitter/super.rb +1 -29
- data/lib/unparser/emitter/undef.rb +1 -9
- data/lib/unparser/emitter/variable.rb +1 -31
- data/lib/unparser/emitter/xstr.rb +72 -0
- data/lib/unparser/emitter/yield.rb +1 -9
- data/lib/unparser/generation.rb +250 -0
- data/lib/unparser/node_details.rb +21 -0
- data/lib/unparser/node_details/send.rb +62 -0
- data/lib/unparser/node_helpers.rb +49 -8
- data/lib/unparser/validation.rb +151 -0
- data/lib/unparser/writer.rb +15 -0
- data/lib/unparser/writer/binary.rb +99 -0
- data/lib/unparser/writer/dynamic_string.rb +229 -0
- data/lib/unparser/writer/resbody.rb +40 -0
- data/lib/unparser/writer/rescue.rb +39 -0
- data/lib/unparser/writer/send.rb +124 -0
- data/lib/unparser/{emitter → writer}/send/attribute_assignment.rb +11 -26
- data/lib/unparser/writer/send/binary.rb +27 -0
- data/lib/unparser/writer/send/conditional.rb +25 -0
- data/lib/unparser/writer/send/regular.rb +33 -0
- data/lib/unparser/{emitter → writer}/send/unary.rb +10 -17
- metadata +152 -101
- data/.circleci/config.yml +0 -41
- data/.gitignore +0 -37
- data/.rspec +0 -4
- data/.rubocop.yml +0 -9
- data/Changelog.md +0 -146
- data/Gemfile +0 -11
- data/Gemfile.lock +0 -180
- data/LICENSE +0 -20
- data/Rakefile +0 -22
- data/config/devtools.yml +0 -2
- data/config/flay.yml +0 -3
- data/config/flog.yml +0 -2
- data/config/mutant.yml +0 -6
- data/config/reek.yml +0 -98
- data/config/rubocop.yml +0 -122
- data/config/yardstick.yml +0 -2
- data/lib/unparser/cli/differ.rb +0 -152
- data/lib/unparser/cli/source.rb +0 -267
- data/lib/unparser/emitter/empty.rb +0 -23
- data/lib/unparser/emitter/ensure.rb +0 -37
- data/lib/unparser/emitter/literal.rb +0 -10
- data/lib/unparser/emitter/literal/array.rb +0 -29
- data/lib/unparser/emitter/literal/dynamic.rb +0 -53
- data/lib/unparser/emitter/literal/dynamic_body.rb +0 -132
- data/lib/unparser/emitter/literal/execute_string.rb +0 -38
- data/lib/unparser/emitter/literal/hash.rb +0 -156
- data/lib/unparser/emitter/literal/primitive.rb +0 -145
- data/lib/unparser/emitter/literal/range.rb +0 -36
- data/lib/unparser/emitter/literal/regexp.rb +0 -114
- data/lib/unparser/emitter/literal/singleton.rb +0 -26
- data/lib/unparser/emitter/meta.rb +0 -16
- data/lib/unparser/emitter/redo.rb +0 -25
- data/lib/unparser/emitter/resbody.rb +0 -76
- data/lib/unparser/emitter/retry.rb +0 -25
- data/lib/unparser/emitter/send/binary.rb +0 -57
- data/lib/unparser/emitter/send/conditional.rb +0 -40
- data/lib/unparser/emitter/send/regular.rb +0 -40
- data/lib/unparser/preprocessor.rb +0 -159
- data/spec/integration/unparser/corpus_spec.rb +0 -111
- data/spec/integrations.yml +0 -87
- data/spec/spec_helper.rb +0 -20
- data/spec/unit/unparser/buffer/append_spec.rb +0 -24
- data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +0 -23
- data/spec/unit/unparser/buffer/capture_content_spec.rb +0 -17
- data/spec/unit/unparser/buffer/content_spec.rb +0 -38
- data/spec/unit/unparser/buffer/fresh_line_spec.rb +0 -20
- data/spec/unit/unparser/buffer/indent_spec.rb +0 -20
- data/spec/unit/unparser/buffer/nl_spec.rb +0 -16
- data/spec/unit/unparser/buffer/unindent_spec.rb +0 -20
- data/spec/unit/unparser/comments/consume_spec.rb +0 -22
- data/spec/unit/unparser/comments/take_all_spec.rb +0 -19
- data/spec/unit/unparser/comments/take_before_spec.rb +0 -46
- data/spec/unit/unparser/comments/take_eol_comments_spec.rb +0 -32
- data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +0 -17
- data/spec/unit/unparser_spec.rb +0 -1841
- data/unparser.gemspec +0 -30
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unparser
|
4
|
+
class Emitter
|
5
|
+
# Arguments emitter
|
6
|
+
class Args < self
|
7
|
+
def emit_block_arguments
|
8
|
+
delimited(normal_arguments)
|
9
|
+
|
10
|
+
write(',') if normal_arguments.one? && n_arg?(normal_arguments.first)
|
11
|
+
|
12
|
+
emit_shadowargs
|
13
|
+
end
|
14
|
+
|
15
|
+
def emit_def_arguments
|
16
|
+
delimited(normal_arguments)
|
17
|
+
end
|
18
|
+
|
19
|
+
def emit_lambda_arguments
|
20
|
+
delimited(normal_arguments)
|
21
|
+
emit_shadowargs
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def emit_shadowargs
|
27
|
+
return if shadowargs.empty?
|
28
|
+
|
29
|
+
write('; ')
|
30
|
+
delimited(shadowargs)
|
31
|
+
end
|
32
|
+
|
33
|
+
def normal_arguments
|
34
|
+
children.reject(&method(:n_shadowarg?))
|
35
|
+
end
|
36
|
+
memoize :normal_arguments
|
37
|
+
|
38
|
+
def shadowargs
|
39
|
+
children.select(&method(:n_shadowarg?))
|
40
|
+
end
|
41
|
+
memoize :shadowargs
|
42
|
+
|
43
|
+
end # Arguments
|
44
|
+
end # Emitter
|
45
|
+
end # Unparser
|
@@ -2,121 +2,19 @@
|
|
2
2
|
|
3
3
|
module Unparser
|
4
4
|
class Emitter
|
5
|
-
|
6
|
-
# Arg expr (pattern args) emitter
|
7
|
-
class ArgExpr < self
|
8
|
-
|
9
|
-
handle :arg_expr
|
10
|
-
|
11
|
-
children :body
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
# Perform dispatch
|
16
|
-
#
|
17
|
-
# @return [undefined]
|
18
|
-
#
|
19
|
-
# @api private
|
20
|
-
#
|
21
|
-
def dispatch
|
22
|
-
visit_parentheses(body)
|
23
|
-
end
|
24
|
-
end # ArgExpr
|
25
|
-
|
26
|
-
# Arguments emitter
|
27
|
-
class Arguments < self
|
28
|
-
include Terminated
|
29
|
-
|
30
|
-
handle :args
|
31
|
-
|
32
|
-
SHADOWARGS = ->(node) { node.type.equal?(:shadowarg) }.freeze
|
33
|
-
ARG = ->(node) { node.type.equal?(:arg) }.freeze
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
# Perform dispatch
|
38
|
-
#
|
39
|
-
# @return [undefined]
|
40
|
-
#
|
41
|
-
# @api private
|
42
|
-
#
|
43
|
-
def dispatch
|
44
|
-
delimited(normal_arguments)
|
45
|
-
|
46
|
-
write(', ') if procarg_disambiguator?
|
47
|
-
|
48
|
-
return if shadowargs.empty?
|
49
|
-
|
50
|
-
write('; ')
|
51
|
-
delimited(shadowargs)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Test for procarg_disambiguator
|
55
|
-
#
|
56
|
-
# @return [Boolean]
|
57
|
-
#
|
58
|
-
# @api private
|
59
|
-
#
|
60
|
-
def procarg_disambiguator?
|
61
|
-
regular_block? && normal_arguments.all?(&ARG) && normal_arguments.one?
|
62
|
-
end
|
63
|
-
|
64
|
-
# Test for regular block
|
65
|
-
#
|
66
|
-
# @return [Boolean]
|
67
|
-
#
|
68
|
-
# @api private
|
69
|
-
#
|
70
|
-
def regular_block?
|
71
|
-
parent_type.equal?(:block) && !parent.node.children.first.type.equal?(:lambda)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Return normal arguments
|
75
|
-
#
|
76
|
-
# @return [Enumerable<Parser::AST::Node>]
|
77
|
-
#
|
78
|
-
# @api private
|
79
|
-
#
|
80
|
-
def normal_arguments
|
81
|
-
children.reject(&SHADOWARGS)
|
82
|
-
end
|
83
|
-
memoize :normal_arguments
|
84
|
-
|
85
|
-
# Return shadow args
|
86
|
-
#
|
87
|
-
# @return [Enumerable<Parser::AST::Node>]
|
88
|
-
#
|
89
|
-
# @api private
|
90
|
-
#
|
91
|
-
def shadowargs
|
92
|
-
children.select(&SHADOWARGS)
|
93
|
-
end
|
94
|
-
memoize :shadowargs
|
95
|
-
|
96
|
-
end # Arguments
|
97
|
-
|
98
5
|
# Emitter for block and kwrestarg arguments
|
99
6
|
class Morearg < self
|
100
|
-
include Terminated
|
101
|
-
|
102
7
|
MAP = {
|
103
|
-
blockarg:
|
104
|
-
kwrestarg:
|
8
|
+
blockarg: '&',
|
9
|
+
kwrestarg: '**'
|
105
10
|
}.freeze
|
106
11
|
|
107
|
-
handle
|
108
|
-
handle :kwrestarg
|
12
|
+
handle(*MAP.keys)
|
109
13
|
|
110
14
|
children :name
|
111
15
|
|
112
16
|
private
|
113
17
|
|
114
|
-
# Perform dispatch
|
115
|
-
#
|
116
|
-
# @return [undefined]
|
117
|
-
#
|
118
|
-
# @api private
|
119
|
-
#
|
120
18
|
def dispatch
|
121
19
|
write(MAP.fetch(node_type), name.to_s)
|
122
20
|
end
|
@@ -125,44 +23,28 @@ module Unparser
|
|
125
23
|
|
126
24
|
# Optional argument emitter
|
127
25
|
class Optarg < self
|
128
|
-
include Terminated
|
129
|
-
|
130
26
|
handle :optarg
|
131
27
|
|
132
28
|
children :name, :value
|
133
29
|
|
134
30
|
private
|
135
31
|
|
136
|
-
# Perform dispatch
|
137
|
-
#
|
138
|
-
# @return [undefined]
|
139
|
-
#
|
140
|
-
# @api private
|
141
|
-
#
|
142
32
|
def dispatch
|
143
|
-
write(name.to_s,
|
33
|
+
write(name.to_s, ' = ')
|
144
34
|
visit(value)
|
145
35
|
end
|
146
36
|
end
|
147
37
|
|
148
38
|
# Optional keyword argument emitter
|
149
39
|
class KeywordOptional < self
|
150
|
-
include Terminated
|
151
|
-
|
152
40
|
handle :kwoptarg
|
153
41
|
|
154
42
|
children :name, :value
|
155
43
|
|
156
44
|
private
|
157
45
|
|
158
|
-
# Perform dispatch
|
159
|
-
#
|
160
|
-
# @return [undefined]
|
161
|
-
#
|
162
|
-
# @api private
|
163
|
-
#
|
164
46
|
def dispatch
|
165
|
-
write(name.to_s,
|
47
|
+
write(name.to_s, ': ')
|
166
48
|
visit(value)
|
167
49
|
end
|
168
50
|
|
@@ -170,64 +52,40 @@ module Unparser
|
|
170
52
|
|
171
53
|
# Keyword argument emitter
|
172
54
|
class Kwarg < self
|
173
|
-
include Terminated
|
174
|
-
|
175
55
|
handle :kwarg
|
176
56
|
|
177
57
|
children :name
|
178
58
|
|
179
59
|
private
|
180
60
|
|
181
|
-
# Perform dispatch
|
182
|
-
#
|
183
|
-
# @return [undefined]
|
184
|
-
#
|
185
|
-
# @api private
|
186
|
-
#
|
187
61
|
def dispatch
|
188
|
-
write(name.to_s,
|
62
|
+
write(name.to_s, ':')
|
189
63
|
end
|
190
64
|
|
191
65
|
end # Restarg
|
192
66
|
|
193
67
|
# Rest argument emitter
|
194
68
|
class Restarg < self
|
195
|
-
include Terminated
|
196
|
-
|
197
69
|
handle :restarg
|
198
70
|
|
199
71
|
children :name
|
200
72
|
|
201
73
|
private
|
202
74
|
|
203
|
-
# Perform dispatch
|
204
|
-
#
|
205
|
-
# @return [undefined]
|
206
|
-
#
|
207
|
-
# @api private
|
208
|
-
#
|
209
75
|
def dispatch
|
210
|
-
write(
|
76
|
+
write('*', name.to_s)
|
211
77
|
end
|
212
78
|
|
213
79
|
end # Restarg
|
214
80
|
|
215
81
|
# Argument emitter
|
216
82
|
class Argument < self
|
217
|
-
include Terminated
|
218
|
-
|
219
83
|
handle :arg, :shadowarg
|
220
84
|
|
221
85
|
children :name
|
222
86
|
|
223
87
|
private
|
224
88
|
|
225
|
-
# Perform dispatch
|
226
|
-
#
|
227
|
-
# @return [undefined]
|
228
|
-
#
|
229
|
-
# @api private
|
230
|
-
#
|
231
89
|
def dispatch
|
232
90
|
write(name.to_s)
|
233
91
|
end
|
@@ -236,59 +94,39 @@ module Unparser
|
|
236
94
|
|
237
95
|
# Progarg emitter
|
238
96
|
class Procarg < self
|
239
|
-
include Terminated
|
240
|
-
|
241
97
|
handle :procarg0
|
242
98
|
|
243
|
-
|
99
|
+
PARENS = %i[restarg mlhs].freeze
|
244
100
|
|
245
101
|
private
|
246
102
|
|
247
|
-
# Perform dispatch
|
248
|
-
#
|
249
|
-
# @return [undefined]
|
250
|
-
#
|
251
|
-
# @api private
|
252
|
-
#
|
253
103
|
def dispatch
|
254
|
-
if
|
255
|
-
|
104
|
+
if needs_parens?
|
105
|
+
parentheses do
|
106
|
+
delimited(children)
|
107
|
+
end
|
256
108
|
else
|
257
|
-
|
109
|
+
delimited(children)
|
258
110
|
end
|
259
111
|
end
|
260
112
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
#
|
265
|
-
# @api private
|
266
|
-
#
|
267
|
-
def emit_multiple_children
|
268
|
-
parentheses do
|
269
|
-
delimited(children)
|
113
|
+
def needs_parens?
|
114
|
+
children.length > 1 || children.any? do |node|
|
115
|
+
PARENS.include?(node.type)
|
270
116
|
end
|
271
117
|
end
|
272
118
|
end
|
273
119
|
|
274
120
|
# Block pass node emitter
|
275
121
|
class BlockPass < self
|
276
|
-
include Terminated
|
277
|
-
|
278
122
|
handle :block_pass
|
279
123
|
|
280
124
|
children :name
|
281
125
|
|
282
126
|
private
|
283
127
|
|
284
|
-
# Perform dispatch
|
285
|
-
#
|
286
|
-
# @return [undefined]
|
287
|
-
#
|
288
|
-
# @api private
|
289
|
-
#
|
290
128
|
def dispatch
|
291
|
-
write(
|
129
|
+
write('&')
|
292
130
|
visit(name)
|
293
131
|
end
|
294
132
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unparser
|
4
|
+
class Emitter
|
5
|
+
# Array literal emitter
|
6
|
+
class Array < self
|
7
|
+
handle :array
|
8
|
+
|
9
|
+
def emit_heredoc_reminders
|
10
|
+
emitters.each(&:emit_heredoc_reminders)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def dispatch
|
16
|
+
parentheses('[', ']') do
|
17
|
+
delimited(emitters, &:write_to_buffer)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def emitters
|
22
|
+
children.map(&method(:emitter))
|
23
|
+
end
|
24
|
+
memoize :emitters
|
25
|
+
end # Array
|
26
|
+
end # Emitter
|
27
|
+
end # Unparser
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unparser
|
4
|
+
class Emitter
|
5
|
+
# Emitter for array patterns
|
6
|
+
class ArrayPattern < self
|
7
|
+
|
8
|
+
handle :array_pattern
|
9
|
+
handle :array_pattern_with_tail
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def dispatch
|
14
|
+
write('[')
|
15
|
+
delimited(children, &method(:emit_member))
|
16
|
+
write(', ') if node_type.equal?(:array_pattern_with_tail)
|
17
|
+
write(']')
|
18
|
+
end
|
19
|
+
|
20
|
+
def emit_member(node)
|
21
|
+
if n_match_rest?(node)
|
22
|
+
writer_with(MatchRest, node).emit_array_pattern
|
23
|
+
else
|
24
|
+
visit(node)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end # Pin
|
28
|
+
end # Emitter
|
29
|
+
end # Unparser
|
@@ -5,163 +5,72 @@ module Unparser
|
|
5
5
|
|
6
6
|
# Base class for assignment emitters
|
7
7
|
class Assignment < self
|
8
|
+
BINARY_OPERATOR = %i[and or].freeze
|
9
|
+
|
10
|
+
def symbol_name
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def emit_heredoc_reminders
|
15
|
+
return unless right
|
16
|
+
|
17
|
+
emitter(right).emit_heredoc_reminders
|
18
|
+
end
|
8
19
|
|
9
20
|
private
|
10
21
|
|
11
|
-
# Perform dispatch
|
12
|
-
#
|
13
|
-
# @return [undefined]
|
14
|
-
#
|
15
|
-
# @api private
|
16
|
-
#
|
17
22
|
def dispatch
|
18
23
|
emit_left
|
19
24
|
emit_right
|
20
25
|
end
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
# Test for terminated emit
|
26
|
-
#
|
27
|
-
# @return [Boolean]
|
28
|
-
#
|
29
|
-
# @api private
|
30
|
-
#
|
31
|
-
def terminated?
|
32
|
-
right.nil?
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
27
|
+
def emit_right
|
28
|
+
return unless right
|
36
29
|
|
37
|
-
|
38
|
-
#
|
39
|
-
# @return [undefined]
|
40
|
-
#
|
41
|
-
# @api private
|
42
|
-
#
|
43
|
-
def emit_right
|
44
|
-
return unless right
|
30
|
+
write(' = ')
|
45
31
|
|
46
|
-
|
32
|
+
if BINARY_OPERATOR.include?(right.type)
|
33
|
+
writer_with(Writer::Binary, right).emit_operator
|
34
|
+
else
|
47
35
|
visit(right)
|
48
36
|
end
|
37
|
+
end
|
49
38
|
|
50
|
-
|
51
|
-
|
52
|
-
# Variable assignment emitter
|
53
|
-
class Variable < self
|
54
|
-
|
55
|
-
handle :lvasgn, :ivasgn, :cvasgn, :gvasgn
|
56
|
-
|
57
|
-
children :name, :right
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
# Emit left
|
62
|
-
#
|
63
|
-
# @return [undefined]
|
64
|
-
#
|
65
|
-
# @api private
|
66
|
-
#
|
67
|
-
def emit_left
|
68
|
-
write(name.to_s)
|
69
|
-
end
|
70
|
-
|
71
|
-
end # Variable
|
72
|
-
|
73
|
-
# Constant assignment emitter
|
74
|
-
class Constant < self
|
75
|
-
|
76
|
-
handle :casgn
|
77
|
-
|
78
|
-
children :base, :name, :right
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
# Emit left
|
83
|
-
#
|
84
|
-
# @return [undefined]
|
85
|
-
#
|
86
|
-
# @api private
|
87
|
-
#
|
88
|
-
def emit_left
|
89
|
-
if base
|
90
|
-
visit(base)
|
91
|
-
write(T_DCL) if base.type != :cbase
|
92
|
-
end
|
93
|
-
write(name.to_s)
|
94
|
-
end
|
39
|
+
abstract_method :emit_left
|
95
40
|
|
96
|
-
|
97
|
-
|
41
|
+
# Variable assignment emitter
|
42
|
+
class Variable < self
|
98
43
|
|
99
|
-
|
100
|
-
class Multiple < self
|
101
|
-
include Unterminated
|
44
|
+
handle :lvasgn, :ivasgn, :cvasgn, :gvasgn
|
102
45
|
|
103
|
-
|
46
|
+
children :name, :right
|
104
47
|
|
105
48
|
private
|
106
49
|
|
107
|
-
# Emit left
|
108
|
-
#
|
109
|
-
# @return [undefined]
|
110
|
-
#
|
111
|
-
# @api private
|
112
|
-
#
|
113
50
|
def emit_left
|
114
|
-
|
51
|
+
write(name.to_s)
|
115
52
|
end
|
116
53
|
|
117
|
-
|
118
|
-
#
|
119
|
-
# @return [undefined]
|
120
|
-
#
|
121
|
-
# @api private
|
122
|
-
#
|
123
|
-
def emit_right
|
124
|
-
write(WS, T_ASN, WS)
|
125
|
-
visit(children.last)
|
126
|
-
end
|
54
|
+
end # Variable
|
127
55
|
|
128
|
-
|
56
|
+
# Constant assignment emitter
|
57
|
+
class Constant < self
|
129
58
|
|
130
|
-
|
131
|
-
class MLHS < Emitter
|
132
|
-
include Unterminated
|
59
|
+
handle :casgn
|
133
60
|
|
134
|
-
|
61
|
+
children :base, :name, :right
|
135
62
|
|
136
63
|
private
|
137
64
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
#
|
145
|
-
# @api private
|
146
|
-
#
|
147
|
-
def dispatch
|
148
|
-
delimited(children)
|
149
|
-
|
150
|
-
write(',') if children.one? && mlhs?
|
151
|
-
end
|
152
|
-
|
153
|
-
# Test for mlhs context
|
154
|
-
#
|
155
|
-
# @return [undefined]
|
156
|
-
#
|
157
|
-
# @api private
|
158
|
-
#
|
159
|
-
def mlhs?
|
160
|
-
!NO_COMMA.include?(first_child.type) && PARENT_MLHS.include?(parent_type)
|
65
|
+
def emit_left
|
66
|
+
if base
|
67
|
+
visit(base)
|
68
|
+
write('::') unless n_cbase?(base)
|
69
|
+
end
|
70
|
+
write(name.to_s)
|
161
71
|
end
|
162
72
|
|
163
|
-
end #
|
164
|
-
|
73
|
+
end # Constant
|
165
74
|
end # Assignment
|
166
75
|
end # Emitter
|
167
76
|
end # Unparser
|