@@ -31,15 +31,15 @@ class Node
31
31
# @return [Parser::AST::Node] name node.
32
32
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
33
33
def name
34
- case self . type
34
+ case type
35
35
when :class , :module , :def , :arg , :blockarg , :restarg
36
- self . children [ 0 ]
36
+ children [ 0 ]
37
37
when :defs , :const
38
- self . children [ 1 ]
38
+ children [ 1 ]
39
39
when :mlhs
40
40
self
41
41
else
42
- raise Synvert ::Core ::MethodNotSupported . new "name is not handled for #{ self . debug_info } "
42
+ raise Synvert ::Core ::MethodNotSupported . new "name is not handled for #{ debug_info } "
43
43
end
44
44
end
45
45
@@ -48,10 +48,10 @@ def name
48
48
# @return [Parser::AST::Node] parent_class node.
49
49
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
50
50
def parent_class
51
- if :class == self . type
52
- self . children [ 1 ]
51
+ if :class == type
52
+ children [ 1 ]
53
53
else
54
- raise Synvert ::Core ::MethodNotSupported . new "parent_class is not handled for #{ self . debug_info } "
54
+ raise Synvert ::Core ::MethodNotSupported . new "parent_class is not handled for #{ debug_info } "
55
55
end
56
56
end
57
57
@@ -60,10 +60,10 @@ def parent_class
60
60
# @return [Parser::AST::Node] parent const node.
61
61
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
62
62
def parent_const
63
- if :const == self . type
64
- self . children [ 0 ]
63
+ if :const == type
64
+ children [ 0 ]
65
65
else
66
- raise Synvert ::Core ::MethodNotSupported . new "parent_const is not handled for #{ self . debug_info } "
66
+ raise Synvert ::Core ::MethodNotSupported . new "parent_const is not handled for #{ debug_info } "
67
67
end
68
68
end
69
69
@@ -72,10 +72,10 @@ def parent_const
72
72
# @return [Parser::AST::Node] receiver node.
73
73
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
74
74
def receiver
75
- if :send == self . type
76
- self . children [ 0 ]
75
+ if :send == type
76
+ children [ 0 ]
77
77
else
78
- raise Synvert ::Core ::MethodNotSupported . new "receiver is not handled for #{ self . debug_info } "
78
+ raise Synvert ::Core ::MethodNotSupported . new "receiver is not handled for #{ debug_info } "
79
79
end
80
80
end
81
81
@@ -84,13 +84,13 @@ def receiver
84
84
# @return [Parser::AST::Node] mesage node.
85
85
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
86
86
def message
87
- case self . type
87
+ case type
88
88
when :super , :zsuper
89
89
:super
90
90
when :send
91
- self . children [ 1 ]
91
+ children [ 1 ]
92
92
else
93
- raise Synvert ::Core ::MethodNotSupported . new "message is not handled for #{ self . debug_info } "
93
+ raise Synvert ::Core ::MethodNotSupported . new "message is not handled for #{ debug_info } "
94
94
end
95
95
end
96
96
@@ -99,17 +99,17 @@ def message
99
99
# @return [Array<Parser::AST::Node>] arguments node.
100
100
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
101
101
def arguments
102
- case self . type
102
+ case type
103
103
when :def , :block
104
- ArgumentsNode . new self . children [ 1 ]
104
+ ArgumentsNode . new children [ 1 ]
105
105
when :defs
106
- ArgumentsNode . new self . children [ 2 ]
106
+ ArgumentsNode . new children [ 2 ]
107
107
when :send
108
- self . children [ 2 ..-1 ]
108
+ children [ 2 ..-1 ]
109
109
when :defined?
110
- self . children
110
+ children
111
111
else
112
- raise Synvert ::Core ::MethodNotSupported . new "arguments is not handled for #{ self . debug_info } "
112
+ raise Synvert ::Core ::MethodNotSupported . new "arguments is not handled for #{ debug_info } "
113
113
end
114
114
end
115
115
@@ -118,10 +118,10 @@ def arguments
118
118
# @return [Parser::AST::Node] caller node.
119
119
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
120
120
def caller
121
- if :block == self . type
122
- self . children [ 0 ]
121
+ if :block == type
122
+ children [ 0 ]
123
123
else
124
- raise Synvert ::Core ::MethodNotSupported . new "caller is not handled for #{ self . debug_info } "
124
+ raise Synvert ::Core ::MethodNotSupported . new "caller is not handled for #{ debug_info } "
125
125
end
126
126
end
127
127
@@ -130,19 +130,19 @@ def caller
130
130
# @return [Array<Parser::AST::Node>] body node.
131
131
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
132
132
def body
133
- case self . type
133
+ case type
134
134
when :begin
135
- self . children
135
+ children
136
136
when :def , :block
137
- return [ ] if self . children [ 2 ] . nil?
137
+ return [ ] if children [ 2 ] . nil?
138
138
139
- :begin == self . children [ 2 ] . type ? self . children [ 2 ] . body : self . children [ 2 ..-1 ]
139
+ :begin == children [ 2 ] . type ? children [ 2 ] . body : children [ 2 ..-1 ]
140
140
when :defs
141
- return [ ] if self . children [ 3 ] . nil?
141
+ return [ ] if children [ 3 ] . nil?
142
142
143
- :begin == self . children [ 3 ] . type ? self . children [ 3 ] . body : self . children [ 3 ..-1 ]
143
+ :begin == children [ 3 ] . type ? children [ 3 ] . body : children [ 3 ..-1 ]
144
144
else
145
- raise Synvert ::Core ::MethodNotSupported . new "body is not handled for #{ self . debug_info } "
145
+ raise Synvert ::Core ::MethodNotSupported . new "body is not handled for #{ debug_info } "
146
146
end
147
147
end
148
148
@@ -151,10 +151,10 @@ def body
151
151
# @return [Parser::AST::Node] condition node.
152
152
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
153
153
def condition
154
- if :if == self . type
155
- self . children [ 0 ]
154
+ if :if == type
155
+ children [ 0 ]
156
156
else
157
- raise Synvert ::Core ::MethodNotSupported . new "condition is not handled for #{ self . debug_info } "
157
+ raise Synvert ::Core ::MethodNotSupported . new "condition is not handled for #{ debug_info } "
158
158
end
159
159
end
160
160
@@ -163,10 +163,10 @@ def condition
163
163
# @return [Array<Parser::AST::Node>] keys node.
164
164
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
165
165
def keys
166
- if :hash == self . type
167
- self . children . map { |child | child . children [ 0 ] }
166
+ if :hash == type
167
+ children . map { |child | child . children [ 0 ] }
168
168
else
169
- raise Synvert ::Core ::MethodNotSupported . new "keys is not handled for #{ self . debug_info } "
169
+ raise Synvert ::Core ::MethodNotSupported . new "keys is not handled for #{ debug_info } "
170
170
end
171
171
end
172
172
@@ -175,10 +175,10 @@ def keys
175
175
# @return [Array<Parser::AST::Node>] values node.
176
176
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
177
177
def values
178
- if :hash == self . type
179
- self . children . map { |child | child . children [ 1 ] }
178
+ if :hash == type
179
+ children . map { |child | child . children [ 1 ] }
180
180
else
181
- raise Synvert ::Core ::MethodNotSupported . new "keys is not handled for #{ self . debug_info } "
181
+ raise Synvert ::Core ::MethodNotSupported . new "keys is not handled for #{ debug_info } "
182
182
end
183
183
end
184
184
@@ -188,10 +188,10 @@ def values
188
188
# @return [Boolean] true if specified key exists.
189
189
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
190
190
def has_key? ( key )
191
- if :hash == self . type
192
- self . children . any? { |pair_node | pair_node . key . to_value == key }
191
+ if :hash == type
192
+ children . any? { |pair_node | pair_node . key . to_value == key }
193
193
else
194
- raise Synvert ::Core ::MethodNotSupported . new "has_key? is not handled for #{ self . debug_info } "
194
+ raise Synvert ::Core ::MethodNotSupported . new "has_key? is not handled for #{ debug_info } "
195
195
end
196
196
end
197
197
@@ -201,11 +201,11 @@ def has_key?(key)
201
201
# @return [Parser::AST::Node] value node.
202
202
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
203
203
def hash_value ( key )
204
- if :hash == self . type
205
- value_node = self . children . find { |pair_node | pair_node . key . to_value == key }
204
+ if :hash == type
205
+ value_node = children . find { |pair_node | pair_node . key . to_value == key }
206
206
value_node ? value_node . value : nil
207
207
else
208
- raise Synvert ::Core ::MethodNotSupported . new "has_key? is not handled for #{ self . debug_info } "
208
+ raise Synvert ::Core ::MethodNotSupported . new "has_key? is not handled for #{ debug_info } "
209
209
end
210
210
end
211
211
@@ -214,10 +214,10 @@ def hash_value(key)
214
214
# @return [Parser::AST::Node] key node.
215
215
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
216
216
def key
217
- if :pair == self . type
218
- self . children . first
217
+ if :pair == type
218
+ children . first
219
219
else
220
- raise Synvert ::Core ::MethodNotSupported . new "key is not handled for #{ self . debug_info } "
220
+ raise Synvert ::Core ::MethodNotSupported . new "key is not handled for #{ debug_info } "
221
221
end
222
222
end
223
223
@@ -226,10 +226,10 @@ def key
226
226
# @return [Parser::AST::Node] value node.
227
227
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
228
228
def value
229
- if :pair == self . type
230
- self . children . last
229
+ if :pair == type
230
+ children . last
231
231
else
232
- raise Synvert ::Core ::MethodNotSupported . new "value is not handled for #{ self . debug_info } "
232
+ raise Synvert ::Core ::MethodNotSupported . new "value is not handled for #{ debug_info } "
233
233
end
234
234
end
235
235
@@ -238,10 +238,10 @@ def value
238
238
# @return [Parser::AST::Node] variable nodes.
239
239
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
240
240
def left_value
241
- if %i[ masgn lvasgn ivasgn ] . include? self . type
242
- self . children [ 0 ]
241
+ if %i[ masgn lvasgn ivasgn ] . include? type
242
+ children [ 0 ]
243
243
else
244
- raise Synvert ::Core ::MethodNotSupported . new "left_value is not handled for #{ self . debug_info } "
244
+ raise Synvert ::Core ::MethodNotSupported . new "left_value is not handled for #{ debug_info } "
245
245
end
246
246
end
247
247
@@ -250,10 +250,10 @@ def left_value
250
250
# @return [Array<Parser::AST::Node>] variable nodes.
251
251
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
252
252
def right_value
253
- if %i[ masgn lvasgn ivasgn ] . include? self . type
254
- self . children [ 1 ]
253
+ if %i[ masgn lvasgn ivasgn ] . include? type
254
+ children [ 1 ]
255
255
else
256
- raise Synvert ::Core ::MethodNotSupported . new "right_value is not handled for #{ self . debug_info } "
256
+ raise Synvert ::Core ::MethodNotSupported . new "right_value is not handled for #{ debug_info } "
257
257
end
258
258
end
259
259
@@ -262,69 +262,69 @@ def right_value
262
262
# @return [Object] exact value.
263
263
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
264
264
def to_value
265
- case self . type
265
+ case type
266
266
when :int , :str , :sym
267
- self . children . last
267
+ children . last
268
268
when :true
269
269
true
270
270
when :false
271
271
false
272
272
when :array
273
- self . children . map ( &:to_value )
273
+ children . map ( &:to_value )
274
274
when :irange
275
- ( self . children . first . to_value .. self . children . last . to_value )
275
+ ( children . first . to_value ..children . last . to_value )
276
276
when :begin
277
- self . children . first . to_value
277
+ children . first . to_value
278
278
else
279
- raise Synvert ::Core ::MethodNotSupported . new "to_value is not handled for #{ self . debug_info } "
279
+ raise Synvert ::Core ::MethodNotSupported . new "to_value is not handled for #{ debug_info } "
280
280
end
281
281
end
282
282
283
283
def to_s
284
- if :mlhs == self . type
285
- "(#{ self . children . map ( &:name ) . join ( ', ' ) } )"
284
+ if :mlhs == type
285
+ "(#{ children . map ( &:name ) . join ( ', ' ) } )"
286
286
end
287
287
end
288
288
289
289
def debug_info
290
290
"\n " +
291
291
[
292
- "file: #{ self . loc . expression . source_buffer . name } " ,
293
- "line: #{ self . loc . expression . line } " ,
294
- "source: #{ self . to_source } " ,
295
- "node: #{ self . inspect } "
292
+ "file: #{ loc . expression . source_buffer . name } " ,
293
+ "line: #{ loc . expression . line } " ,
294
+ "source: #{ to_source } " ,
295
+ "node: #{ inspect } "
296
296
] . join ( "\n " )
297
297
end
298
298
299
299
# Get the source code of current node.
300
300
#
301
301
# @return [String] source code.
302
302
def to_source
303
- if self . loc . expression
304
- self . loc . expression . source
303
+ if loc . expression
304
+ loc . expression . source
305
305
end
306
306
end
307
307
308
308
# Get the indent of current node.
309
309
#
310
310
# @return [Integer] indent.
311
311
def indent
312
- self . loc . expression . column
312
+ loc . expression . column
313
313
end
314
314
315
315
# Get the line of current node.
316
316
#
317
317
# @return [Integer] line.
318
318
def line
319
- self . loc . expression . line
319
+ loc . expression . line
320
320
end
321
321
322
322
# Recursively iterate all child nodes of current node.
323
323
#
324
324
# @yield [child] Gives a child node.
325
325
# @yieldparam child [Parser::AST::Node] child node
326
326
def recursive_children
327
- self . children . each do |child |
327
+ children . each do |child |
328
328
if Parser ::AST ::Node === child
329
329
yield child
330
330
child . recursive_children { |c | yield c }
@@ -366,8 +366,8 @@ def match?(rules)
366
366
def rewritten_source ( code )
367
367
code . gsub ( /{{(.*?)}}/m ) do
368
368
old_code = $1
369
- if self . respond_to? old_code . split ( /\. |\[ / ) . first
370
- evaluated = self . instance_eval old_code
369
+ if respond_to? old_code . split ( /\. |\[ / ) . first
370
+ evaluated = instance_eval old_code
371
371
case evaluated
372
372
when Parser ::AST ::Node
373
373
evaluated . loc . expression . source
0 commit comments