syntax_tree 2.2.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +20 -1
- data/.rubocop.yml +80 -0
- data/CHANGELOG.md +47 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +26 -1
- data/README.md +113 -0
- data/Rakefile +27 -5
- data/config/rubocop.yml +64 -0
- data/lib/syntax_tree/cli.rb +63 -27
- data/lib/syntax_tree/formatter.rb +14 -6
- data/lib/syntax_tree/language_server/inlay_hints.rb +87 -38
- data/lib/syntax_tree/language_server.rb +50 -14
- data/lib/syntax_tree/node.rb +1042 -326
- data/lib/syntax_tree/parser.rb +444 -111
- data/lib/syntax_tree/prettyprint.rb +53 -38
- data/lib/syntax_tree/version.rb +1 -1
- data/lib/syntax_tree/visitor/field_visitor.rb +1115 -0
- data/lib/syntax_tree/visitor/json_visitor.rb +25 -1305
- data/lib/syntax_tree/visitor/match_visitor.rb +122 -0
- data/lib/syntax_tree/visitor/pretty_print_visitor.rb +35 -1163
- data/lib/syntax_tree/visitor.rb +6 -1
- data/lib/syntax_tree.rb +19 -1
- data/syntax_tree.gemspec +21 -19
- metadata +8 -4
@@ -0,0 +1,1115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SyntaxTree
|
4
|
+
class Visitor
|
5
|
+
# This is the parent class of a lot of built-in visitors for Syntax Tree. It
|
6
|
+
# reflects visiting each of the fields on every node in turn. It itself does
|
7
|
+
# not do anything with these fields, it leaves that behavior up to the
|
8
|
+
# subclass to implement.
|
9
|
+
#
|
10
|
+
# In order to properly use this class, you will need to subclass it and
|
11
|
+
# implement #comments, #field, #list, #node, #pairs, and #text. Those are
|
12
|
+
# documented here.
|
13
|
+
#
|
14
|
+
# == comments(node)
|
15
|
+
#
|
16
|
+
# This accepts the node that is being visited and does something depending
|
17
|
+
# on the comments attached to the node.
|
18
|
+
#
|
19
|
+
# == field(name, value)
|
20
|
+
#
|
21
|
+
# This accepts the name of the field being visited as a string (like
|
22
|
+
# "value") and the actual value of that field. The value can be a subclass
|
23
|
+
# of Node or any other type that can be held within the tree.
|
24
|
+
#
|
25
|
+
# == list(name, values)
|
26
|
+
#
|
27
|
+
# This accepts the name of the field being visited as well as a list of
|
28
|
+
# values. This is used, for example, when visiting something like the body
|
29
|
+
# of a Statements node.
|
30
|
+
#
|
31
|
+
# == node(name, node)
|
32
|
+
#
|
33
|
+
# This is the parent serialization method for each node. It is called with
|
34
|
+
# the node itself, as well as the type of the node as a string. The type
|
35
|
+
# is an internally used value that usually resembles the name of the
|
36
|
+
# ripper event that generated the node. The method should yield to the
|
37
|
+
# given block which then calls through to visit each of the fields on the
|
38
|
+
# node.
|
39
|
+
#
|
40
|
+
# == text(name, value)
|
41
|
+
#
|
42
|
+
# This accepts the name of the field being visited as well as a string
|
43
|
+
# value representing the value of the field.
|
44
|
+
#
|
45
|
+
# == pairs(name, values)
|
46
|
+
#
|
47
|
+
# This accepts the name of the field being visited as well as a list of
|
48
|
+
# pairs that represent the value of the field. It is used only in a couple
|
49
|
+
# of circumstances, like when visiting the list of optional parameters
|
50
|
+
# defined on a method.
|
51
|
+
#
|
52
|
+
class FieldVisitor < Visitor
|
53
|
+
attr_reader :q
|
54
|
+
|
55
|
+
def visit_aref(node)
|
56
|
+
node(node, "aref") do
|
57
|
+
field("collection", node.collection)
|
58
|
+
field("index", node.index)
|
59
|
+
comments(node)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def visit_aref_field(node)
|
64
|
+
node(node, "aref_field") do
|
65
|
+
field("collection", node.collection)
|
66
|
+
field("index", node.index)
|
67
|
+
comments(node)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def visit_alias(node)
|
72
|
+
node(node, "alias") do
|
73
|
+
field("left", node.left)
|
74
|
+
field("right", node.right)
|
75
|
+
comments(node)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def visit_arg_block(node)
|
80
|
+
node(node, "arg_block") do
|
81
|
+
field("value", node.value) if node.value
|
82
|
+
comments(node)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def visit_arg_paren(node)
|
87
|
+
node(node, "arg_paren") do
|
88
|
+
field("arguments", node.arguments)
|
89
|
+
comments(node)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def visit_arg_star(node)
|
94
|
+
node(node, "arg_star") do
|
95
|
+
field("value", node.value)
|
96
|
+
comments(node)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def visit_args(node)
|
101
|
+
node(node, "args") do
|
102
|
+
list("parts", node.parts)
|
103
|
+
comments(node)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def visit_args_forward(node)
|
108
|
+
visit_token(node, "args_forward")
|
109
|
+
end
|
110
|
+
|
111
|
+
def visit_array(node)
|
112
|
+
node(node, "array") do
|
113
|
+
field("contents", node.contents)
|
114
|
+
comments(node)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def visit_aryptn(node)
|
119
|
+
node(node, "aryptn") do
|
120
|
+
field("constant", node.constant) if node.constant
|
121
|
+
list("requireds", node.requireds) if node.requireds.any?
|
122
|
+
field("rest", node.rest) if node.rest
|
123
|
+
list("posts", node.posts) if node.posts.any?
|
124
|
+
comments(node)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def visit_assign(node)
|
129
|
+
node(node, "assign") do
|
130
|
+
field("target", node.target)
|
131
|
+
field("value", node.value)
|
132
|
+
comments(node)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def visit_assoc(node)
|
137
|
+
node(node, "assoc") do
|
138
|
+
field("key", node.key)
|
139
|
+
field("value", node.value) if node.value
|
140
|
+
comments(node)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def visit_assoc_splat(node)
|
145
|
+
node(node, "assoc_splat") do
|
146
|
+
field("value", node.value)
|
147
|
+
comments(node)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def visit_backref(node)
|
152
|
+
visit_token(node, "backref")
|
153
|
+
end
|
154
|
+
|
155
|
+
def visit_backtick(node)
|
156
|
+
visit_token(node, "backtick")
|
157
|
+
end
|
158
|
+
|
159
|
+
def visit_bare_assoc_hash(node)
|
160
|
+
node(node, "bare_assoc_hash") do
|
161
|
+
list("assocs", node.assocs)
|
162
|
+
comments(node)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def visit_BEGIN(node)
|
167
|
+
node(node, "BEGIN") do
|
168
|
+
field("statements", node.statements)
|
169
|
+
comments(node)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def visit_begin(node)
|
174
|
+
node(node, "begin") do
|
175
|
+
field("bodystmt", node.bodystmt)
|
176
|
+
comments(node)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def visit_binary(node)
|
181
|
+
node(node, "binary") do
|
182
|
+
field("left", node.left)
|
183
|
+
text("operator", node.operator)
|
184
|
+
field("right", node.right)
|
185
|
+
comments(node)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def visit_blockarg(node)
|
190
|
+
node(node, "blockarg") do
|
191
|
+
field("name", node.name) if node.name
|
192
|
+
comments(node)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def visit_block_var(node)
|
197
|
+
node(node, "block_var") do
|
198
|
+
field("params", node.params)
|
199
|
+
list("locals", node.locals) if node.locals.any?
|
200
|
+
comments(node)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def visit_bodystmt(node)
|
205
|
+
node(node, "bodystmt") do
|
206
|
+
field("statements", node.statements)
|
207
|
+
field("rescue_clause", node.rescue_clause) if node.rescue_clause
|
208
|
+
field("else_clause", node.else_clause) if node.else_clause
|
209
|
+
field("ensure_clause", node.ensure_clause) if node.ensure_clause
|
210
|
+
comments(node)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def visit_brace_block(node)
|
215
|
+
node(node, "brace_block") do
|
216
|
+
field("block_var", node.block_var) if node.block_var
|
217
|
+
field("statements", node.statements)
|
218
|
+
comments(node)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def visit_break(node)
|
223
|
+
node(node, "break") do
|
224
|
+
field("arguments", node.arguments)
|
225
|
+
comments(node)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def visit_call(node)
|
230
|
+
node(node, "call") do
|
231
|
+
field("receiver", node.receiver)
|
232
|
+
field("operator", node.operator)
|
233
|
+
field("message", node.message)
|
234
|
+
field("arguments", node.arguments) if node.arguments
|
235
|
+
comments(node)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def visit_case(node)
|
240
|
+
node(node, "case") do
|
241
|
+
field("keyword", node.keyword)
|
242
|
+
field("value", node.value) if node.value
|
243
|
+
field("consequent", node.consequent)
|
244
|
+
comments(node)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def visit_CHAR(node)
|
249
|
+
visit_token(node, "CHAR")
|
250
|
+
end
|
251
|
+
|
252
|
+
def visit_class(node)
|
253
|
+
node(node, "class") do
|
254
|
+
field("constant", node.constant)
|
255
|
+
field("superclass", node.superclass) if node.superclass
|
256
|
+
field("bodystmt", node.bodystmt)
|
257
|
+
comments(node)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def visit_comma(node)
|
262
|
+
node(node, "comma") { field("value", node.value) }
|
263
|
+
end
|
264
|
+
|
265
|
+
def visit_command(node)
|
266
|
+
node(node, "command") do
|
267
|
+
field("message", node.message)
|
268
|
+
field("arguments", node.arguments)
|
269
|
+
comments(node)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
def visit_command_call(node)
|
274
|
+
node(node, "command_call") do
|
275
|
+
field("receiver", node.receiver)
|
276
|
+
field("operator", node.operator)
|
277
|
+
field("message", node.message)
|
278
|
+
field("arguments", node.arguments) if node.arguments
|
279
|
+
comments(node)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def visit_comment(node)
|
284
|
+
node(node, "comment") { field("value", node.value) }
|
285
|
+
end
|
286
|
+
|
287
|
+
def visit_const(node)
|
288
|
+
visit_token(node, "const")
|
289
|
+
end
|
290
|
+
|
291
|
+
def visit_const_path_field(node)
|
292
|
+
node(node, "const_path_field") do
|
293
|
+
field("parent", node.parent)
|
294
|
+
field("constant", node.constant)
|
295
|
+
comments(node)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def visit_const_path_ref(node)
|
300
|
+
node(node, "const_path_ref") do
|
301
|
+
field("parent", node.parent)
|
302
|
+
field("constant", node.constant)
|
303
|
+
comments(node)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
def visit_const_ref(node)
|
308
|
+
node(node, "const_ref") do
|
309
|
+
field("constant", node.constant)
|
310
|
+
comments(node)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
def visit_cvar(node)
|
315
|
+
visit_token(node, "cvar")
|
316
|
+
end
|
317
|
+
|
318
|
+
def visit_def(node)
|
319
|
+
node(node, "def") do
|
320
|
+
field("name", node.name)
|
321
|
+
field("params", node.params)
|
322
|
+
field("bodystmt", node.bodystmt)
|
323
|
+
comments(node)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
def visit_def_endless(node)
|
328
|
+
node(node, "def_endless") do
|
329
|
+
if node.target
|
330
|
+
field("target", node.target)
|
331
|
+
field("operator", node.operator)
|
332
|
+
end
|
333
|
+
|
334
|
+
field("name", node.name)
|
335
|
+
field("paren", node.paren) if node.paren
|
336
|
+
field("statement", node.statement)
|
337
|
+
comments(node)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
def visit_defined(node)
|
342
|
+
node(node, "defined") do
|
343
|
+
field("value", node.value)
|
344
|
+
comments(node)
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
def visit_defs(node)
|
349
|
+
node(node, "defs") do
|
350
|
+
field("target", node.target)
|
351
|
+
field("operator", node.operator)
|
352
|
+
field("name", node.name)
|
353
|
+
field("params", node.params)
|
354
|
+
field("bodystmt", node.bodystmt)
|
355
|
+
comments(node)
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
def visit_do_block(node)
|
360
|
+
node(node, "do_block") do
|
361
|
+
field("block_var", node.block_var) if node.block_var
|
362
|
+
field("bodystmt", node.bodystmt)
|
363
|
+
comments(node)
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
def visit_dot2(node)
|
368
|
+
node(node, "dot2") do
|
369
|
+
field("left", node.left) if node.left
|
370
|
+
field("right", node.right) if node.right
|
371
|
+
comments(node)
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
def visit_dot3(node)
|
376
|
+
node(node, "dot3") do
|
377
|
+
field("left", node.left) if node.left
|
378
|
+
field("right", node.right) if node.right
|
379
|
+
comments(node)
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
def visit_dyna_symbol(node)
|
384
|
+
node(node, "dyna_symbol") do
|
385
|
+
list("parts", node.parts)
|
386
|
+
comments(node)
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
def visit_END(node)
|
391
|
+
node(node, "END") do
|
392
|
+
field("statements", node.statements)
|
393
|
+
comments(node)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
def visit_else(node)
|
398
|
+
node(node, "else") do
|
399
|
+
field("statements", node.statements)
|
400
|
+
comments(node)
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
def visit_elsif(node)
|
405
|
+
node(node, "elsif") do
|
406
|
+
field("predicate", node.predicate)
|
407
|
+
field("statements", node.statements)
|
408
|
+
field("consequent", node.consequent) if node.consequent
|
409
|
+
comments(node)
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
def visit_embdoc(node)
|
414
|
+
node(node, "embdoc") { field("value", node.value) }
|
415
|
+
end
|
416
|
+
|
417
|
+
def visit_embexpr_beg(node)
|
418
|
+
node(node, "embexpr_beg") { field("value", node.value) }
|
419
|
+
end
|
420
|
+
|
421
|
+
def visit_embexpr_end(node)
|
422
|
+
node(node, "embexpr_end") { field("value", node.value) }
|
423
|
+
end
|
424
|
+
|
425
|
+
def visit_embvar(node)
|
426
|
+
node(node, "embvar") { field("value", node.value) }
|
427
|
+
end
|
428
|
+
|
429
|
+
def visit_ensure(node)
|
430
|
+
node(node, "ensure") do
|
431
|
+
field("statements", node.statements)
|
432
|
+
comments(node)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
def visit_excessed_comma(node)
|
437
|
+
visit_token(node, "excessed_comma")
|
438
|
+
end
|
439
|
+
|
440
|
+
def visit_fcall(node)
|
441
|
+
node(node, "fcall") do
|
442
|
+
field("value", node.value)
|
443
|
+
field("arguments", node.arguments) if node.arguments
|
444
|
+
comments(node)
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
def visit_field(node)
|
449
|
+
node(node, "field") do
|
450
|
+
field("parent", node.parent)
|
451
|
+
field("operator", node.operator)
|
452
|
+
field("name", node.name)
|
453
|
+
comments(node)
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
def visit_float(node)
|
458
|
+
visit_token(node, "float")
|
459
|
+
end
|
460
|
+
|
461
|
+
def visit_fndptn(node)
|
462
|
+
node(node, "fndptn") do
|
463
|
+
field("constant", node.constant) if node.constant
|
464
|
+
field("left", node.left)
|
465
|
+
list("values", node.values)
|
466
|
+
field("right", node.right)
|
467
|
+
comments(node)
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
def visit_for(node)
|
472
|
+
node(node, "for") do
|
473
|
+
field("index", node.index)
|
474
|
+
field("collection", node.collection)
|
475
|
+
field("statements", node.statements)
|
476
|
+
comments(node)
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
480
|
+
def visit_gvar(node)
|
481
|
+
visit_token(node, "gvar")
|
482
|
+
end
|
483
|
+
|
484
|
+
def visit_hash(node)
|
485
|
+
node(node, "hash") do
|
486
|
+
list("assocs", node.assocs) if node.assocs.any?
|
487
|
+
comments(node)
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
def visit_heredoc(node)
|
492
|
+
node(node, "heredoc") do
|
493
|
+
list("parts", node.parts)
|
494
|
+
comments(node)
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
def visit_heredoc_beg(node)
|
499
|
+
visit_token(node, "heredoc_beg")
|
500
|
+
end
|
501
|
+
|
502
|
+
def visit_hshptn(node)
|
503
|
+
node(node, "hshptn") do
|
504
|
+
field("constant", node.constant) if node.constant
|
505
|
+
pairs("keywords", node.keywords) if node.keywords.any?
|
506
|
+
field("keyword_rest", node.keyword_rest) if node.keyword_rest
|
507
|
+
comments(node)
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
511
|
+
def visit_ident(node)
|
512
|
+
visit_token(node, "ident")
|
513
|
+
end
|
514
|
+
|
515
|
+
def visit_if(node)
|
516
|
+
node(node, "if") do
|
517
|
+
field("predicate", node.predicate)
|
518
|
+
field("statements", node.statements)
|
519
|
+
field("consequent", node.consequent) if node.consequent
|
520
|
+
comments(node)
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
def visit_if_mod(node)
|
525
|
+
node(node, "if_mod") do
|
526
|
+
field("statement", node.statement)
|
527
|
+
field("predicate", node.predicate)
|
528
|
+
comments(node)
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
def visit_if_op(node)
|
533
|
+
node(node, "if_op") do
|
534
|
+
field("predicate", node.predicate)
|
535
|
+
field("truthy", node.truthy)
|
536
|
+
field("falsy", node.falsy)
|
537
|
+
comments(node)
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
def visit_imaginary(node)
|
542
|
+
visit_token(node, "imaginary")
|
543
|
+
end
|
544
|
+
|
545
|
+
def visit_in(node)
|
546
|
+
node(node, "in") do
|
547
|
+
field("pattern", node.pattern)
|
548
|
+
field("statements", node.statements)
|
549
|
+
field("consequent", node.consequent) if node.consequent
|
550
|
+
comments(node)
|
551
|
+
end
|
552
|
+
end
|
553
|
+
|
554
|
+
def visit_int(node)
|
555
|
+
visit_token(node, "int")
|
556
|
+
end
|
557
|
+
|
558
|
+
def visit_ivar(node)
|
559
|
+
visit_token(node, "ivar")
|
560
|
+
end
|
561
|
+
|
562
|
+
def visit_kw(node)
|
563
|
+
visit_token(node, "kw")
|
564
|
+
end
|
565
|
+
|
566
|
+
def visit_kwrest_param(node)
|
567
|
+
node(node, "kwrest_param") do
|
568
|
+
field("name", node.name)
|
569
|
+
comments(node)
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
573
|
+
def visit_label(node)
|
574
|
+
visit_token(node, "label")
|
575
|
+
end
|
576
|
+
|
577
|
+
def visit_label_end(node)
|
578
|
+
node(node, "label_end") { field("value", node.value) }
|
579
|
+
end
|
580
|
+
|
581
|
+
def visit_lambda(node)
|
582
|
+
node(node, "lambda") do
|
583
|
+
field("params", node.params)
|
584
|
+
field("statements", node.statements)
|
585
|
+
comments(node)
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
589
|
+
def visit_lbrace(node)
|
590
|
+
visit_token(node, "lbrace")
|
591
|
+
end
|
592
|
+
|
593
|
+
def visit_lbracket(node)
|
594
|
+
visit_token(node, "lbracket")
|
595
|
+
end
|
596
|
+
|
597
|
+
def visit_lparen(node)
|
598
|
+
visit_token(node, "lparen")
|
599
|
+
end
|
600
|
+
|
601
|
+
def visit_massign(node)
|
602
|
+
node(node, "massign") do
|
603
|
+
field("target", node.target)
|
604
|
+
field("value", node.value)
|
605
|
+
comments(node)
|
606
|
+
end
|
607
|
+
end
|
608
|
+
|
609
|
+
def visit_method_add_block(node)
|
610
|
+
node(node, "method_add_block") do
|
611
|
+
field("call", node.call)
|
612
|
+
field("block", node.block)
|
613
|
+
comments(node)
|
614
|
+
end
|
615
|
+
end
|
616
|
+
|
617
|
+
def visit_mlhs(node)
|
618
|
+
node(node, "mlhs") do
|
619
|
+
list("parts", node.parts)
|
620
|
+
comments(node)
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
def visit_mlhs_paren(node)
|
625
|
+
node(node, "mlhs_paren") do
|
626
|
+
field("contents", node.contents)
|
627
|
+
comments(node)
|
628
|
+
end
|
629
|
+
end
|
630
|
+
|
631
|
+
def visit_module(node)
|
632
|
+
node(node, "module") do
|
633
|
+
field("constant", node.constant)
|
634
|
+
field("bodystmt", node.bodystmt)
|
635
|
+
comments(node)
|
636
|
+
end
|
637
|
+
end
|
638
|
+
|
639
|
+
def visit_mrhs(node)
|
640
|
+
node(node, "mrhs") do
|
641
|
+
list("parts", node.parts)
|
642
|
+
comments(node)
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
def visit_next(node)
|
647
|
+
node(node, "next") do
|
648
|
+
field("arguments", node.arguments)
|
649
|
+
comments(node)
|
650
|
+
end
|
651
|
+
end
|
652
|
+
|
653
|
+
def visit_not(node)
|
654
|
+
node(node, "not") do
|
655
|
+
field("statement", node.statement)
|
656
|
+
comments(node)
|
657
|
+
end
|
658
|
+
end
|
659
|
+
|
660
|
+
def visit_op(node)
|
661
|
+
visit_token(node, "op")
|
662
|
+
end
|
663
|
+
|
664
|
+
def visit_opassign(node)
|
665
|
+
node(node, "opassign") do
|
666
|
+
field("target", node.target)
|
667
|
+
field("operator", node.operator)
|
668
|
+
field("value", node.value)
|
669
|
+
comments(node)
|
670
|
+
end
|
671
|
+
end
|
672
|
+
|
673
|
+
def visit_params(node)
|
674
|
+
node(node, "params") do
|
675
|
+
list("requireds", node.requireds) if node.requireds.any?
|
676
|
+
pairs("optionals", node.optionals) if node.optionals.any?
|
677
|
+
field("rest", node.rest) if node.rest
|
678
|
+
list("posts", node.posts) if node.posts.any?
|
679
|
+
pairs("keywords", node.keywords) if node.keywords.any?
|
680
|
+
field("keyword_rest", node.keyword_rest) if node.keyword_rest
|
681
|
+
field("block", node.block) if node.block
|
682
|
+
comments(node)
|
683
|
+
end
|
684
|
+
end
|
685
|
+
|
686
|
+
def visit_paren(node)
|
687
|
+
node(node, "paren") do
|
688
|
+
field("contents", node.contents)
|
689
|
+
comments(node)
|
690
|
+
end
|
691
|
+
end
|
692
|
+
|
693
|
+
def visit_period(node)
|
694
|
+
visit_token(node, "period")
|
695
|
+
end
|
696
|
+
|
697
|
+
def visit_pinned_begin(node)
|
698
|
+
node(node, "pinned_begin") do
|
699
|
+
field("statement", node.statement)
|
700
|
+
comments(node)
|
701
|
+
end
|
702
|
+
end
|
703
|
+
|
704
|
+
def visit_pinned_var_ref(node)
|
705
|
+
node(node, "pinned_var_ref") do
|
706
|
+
field("value", node.value)
|
707
|
+
comments(node)
|
708
|
+
end
|
709
|
+
end
|
710
|
+
|
711
|
+
def visit_program(node)
|
712
|
+
node(node, "program") do
|
713
|
+
field("statements", node.statements)
|
714
|
+
comments(node)
|
715
|
+
end
|
716
|
+
end
|
717
|
+
|
718
|
+
def visit_qsymbols(node)
|
719
|
+
node(node, "qsymbols") do
|
720
|
+
list("elements", node.elements)
|
721
|
+
comments(node)
|
722
|
+
end
|
723
|
+
end
|
724
|
+
|
725
|
+
def visit_qsymbols_beg(node)
|
726
|
+
node(node, "qsymbols_beg") { field("value", node.value) }
|
727
|
+
end
|
728
|
+
|
729
|
+
def visit_qwords(node)
|
730
|
+
node(node, "qwords") do
|
731
|
+
list("elements", node.elements)
|
732
|
+
comments(node)
|
733
|
+
end
|
734
|
+
end
|
735
|
+
|
736
|
+
def visit_qwords_beg(node)
|
737
|
+
node(node, "qwords_beg") { field("value", node.value) }
|
738
|
+
end
|
739
|
+
|
740
|
+
def visit_rassign(node)
|
741
|
+
node(node, "rassign") do
|
742
|
+
field("value", node.value)
|
743
|
+
field("operator", node.operator)
|
744
|
+
field("pattern", node.pattern)
|
745
|
+
comments(node)
|
746
|
+
end
|
747
|
+
end
|
748
|
+
|
749
|
+
def visit_rational(node)
|
750
|
+
visit_token(node, "rational")
|
751
|
+
end
|
752
|
+
|
753
|
+
def visit_rbrace(node)
|
754
|
+
node(node, "rbrace") { field("value", node.value) }
|
755
|
+
end
|
756
|
+
|
757
|
+
def visit_rbracket(node)
|
758
|
+
node(node, "rbracket") { field("value", node.value) }
|
759
|
+
end
|
760
|
+
|
761
|
+
def visit_redo(node)
|
762
|
+
visit_token(node, "redo")
|
763
|
+
end
|
764
|
+
|
765
|
+
def visit_regexp_beg(node)
|
766
|
+
node(node, "regexp_beg") { field("value", node.value) }
|
767
|
+
end
|
768
|
+
|
769
|
+
def visit_regexp_content(node)
|
770
|
+
node(node, "regexp_content") { list("parts", node.parts) }
|
771
|
+
end
|
772
|
+
|
773
|
+
def visit_regexp_end(node)
|
774
|
+
node(node, "regexp_end") { field("value", node.value) }
|
775
|
+
end
|
776
|
+
|
777
|
+
def visit_regexp_literal(node)
|
778
|
+
node(node, "regexp_literal") do
|
779
|
+
list("parts", node.parts)
|
780
|
+
field("options", node.options)
|
781
|
+
comments(node)
|
782
|
+
end
|
783
|
+
end
|
784
|
+
|
785
|
+
def visit_rescue(node)
|
786
|
+
node(node, "rescue") do
|
787
|
+
field("exception", node.exception) if node.exception
|
788
|
+
field("statements", node.statements)
|
789
|
+
field("consequent", node.consequent) if node.consequent
|
790
|
+
comments(node)
|
791
|
+
end
|
792
|
+
end
|
793
|
+
|
794
|
+
def visit_rescue_ex(node)
|
795
|
+
node(node, "rescue_ex") do
|
796
|
+
field("exceptions", node.exceptions)
|
797
|
+
field("variable", node.variable)
|
798
|
+
comments(node)
|
799
|
+
end
|
800
|
+
end
|
801
|
+
|
802
|
+
def visit_rescue_mod(node)
|
803
|
+
node(node, "rescue_mod") do
|
804
|
+
field("statement", node.statement)
|
805
|
+
field("value", node.value)
|
806
|
+
comments(node)
|
807
|
+
end
|
808
|
+
end
|
809
|
+
|
810
|
+
def visit_rest_param(node)
|
811
|
+
node(node, "rest_param") do
|
812
|
+
field("name", node.name)
|
813
|
+
comments(node)
|
814
|
+
end
|
815
|
+
end
|
816
|
+
|
817
|
+
def visit_retry(node)
|
818
|
+
visit_token(node, "retry")
|
819
|
+
end
|
820
|
+
|
821
|
+
def visit_return(node)
|
822
|
+
node(node, "return") do
|
823
|
+
field("arguments", node.arguments)
|
824
|
+
comments(node)
|
825
|
+
end
|
826
|
+
end
|
827
|
+
|
828
|
+
def visit_return0(node)
|
829
|
+
visit_token(node, "return0")
|
830
|
+
end
|
831
|
+
|
832
|
+
def visit_rparen(node)
|
833
|
+
node(node, "rparen") { field("value", node.value) }
|
834
|
+
end
|
835
|
+
|
836
|
+
def visit_sclass(node)
|
837
|
+
node(node, "sclass") do
|
838
|
+
field("target", node.target)
|
839
|
+
field("bodystmt", node.bodystmt)
|
840
|
+
comments(node)
|
841
|
+
end
|
842
|
+
end
|
843
|
+
|
844
|
+
def visit_statements(node)
|
845
|
+
node(node, "statements") do
|
846
|
+
list("body", node.body)
|
847
|
+
comments(node)
|
848
|
+
end
|
849
|
+
end
|
850
|
+
|
851
|
+
def visit_string_concat(node)
|
852
|
+
node(node, "string_concat") do
|
853
|
+
field("left", node.left)
|
854
|
+
field("right", node.right)
|
855
|
+
comments(node)
|
856
|
+
end
|
857
|
+
end
|
858
|
+
|
859
|
+
def visit_string_content(node)
|
860
|
+
node(node, "string_content") { list("parts", node.parts) }
|
861
|
+
end
|
862
|
+
|
863
|
+
def visit_string_dvar(node)
|
864
|
+
node(node, "string_dvar") do
|
865
|
+
field("variable", node.variable)
|
866
|
+
comments(node)
|
867
|
+
end
|
868
|
+
end
|
869
|
+
|
870
|
+
def visit_string_embexpr(node)
|
871
|
+
node(node, "string_embexpr") do
|
872
|
+
field("statements", node.statements)
|
873
|
+
comments(node)
|
874
|
+
end
|
875
|
+
end
|
876
|
+
|
877
|
+
def visit_string_literal(node)
|
878
|
+
node(node, "string_literal") do
|
879
|
+
list("parts", node.parts)
|
880
|
+
comments(node)
|
881
|
+
end
|
882
|
+
end
|
883
|
+
|
884
|
+
def visit_super(node)
|
885
|
+
node(node, "super") do
|
886
|
+
field("arguments", node.arguments)
|
887
|
+
comments(node)
|
888
|
+
end
|
889
|
+
end
|
890
|
+
|
891
|
+
def visit_symbeg(node)
|
892
|
+
node(node, "symbeg") { field("value", node.value) }
|
893
|
+
end
|
894
|
+
|
895
|
+
def visit_symbol_content(node)
|
896
|
+
node(node, "symbol_content") { field("value", node.value) }
|
897
|
+
end
|
898
|
+
|
899
|
+
def visit_symbol_literal(node)
|
900
|
+
node(node, "symbol_literal") do
|
901
|
+
field("value", node.value)
|
902
|
+
comments(node)
|
903
|
+
end
|
904
|
+
end
|
905
|
+
|
906
|
+
def visit_symbols(node)
|
907
|
+
node(node, "symbols") do
|
908
|
+
list("elements", node.elements)
|
909
|
+
comments(node)
|
910
|
+
end
|
911
|
+
end
|
912
|
+
|
913
|
+
def visit_symbols_beg(node)
|
914
|
+
node(node, "symbols_beg") { field("value", node.value) }
|
915
|
+
end
|
916
|
+
|
917
|
+
def visit_tlambda(node)
|
918
|
+
node(node, "tlambda") { field("value", node.value) }
|
919
|
+
end
|
920
|
+
|
921
|
+
def visit_tlambeg(node)
|
922
|
+
node(node, "tlambeg") { field("value", node.value) }
|
923
|
+
end
|
924
|
+
|
925
|
+
def visit_top_const_field(node)
|
926
|
+
node(node, "top_const_field") do
|
927
|
+
field("constant", node.constant)
|
928
|
+
comments(node)
|
929
|
+
end
|
930
|
+
end
|
931
|
+
|
932
|
+
def visit_top_const_ref(node)
|
933
|
+
node(node, "top_const_ref") do
|
934
|
+
field("constant", node.constant)
|
935
|
+
comments(node)
|
936
|
+
end
|
937
|
+
end
|
938
|
+
|
939
|
+
def visit_tstring_beg(node)
|
940
|
+
node(node, "tstring_beg") { field("value", node.value) }
|
941
|
+
end
|
942
|
+
|
943
|
+
def visit_tstring_content(node)
|
944
|
+
visit_token(node, "tstring_content")
|
945
|
+
end
|
946
|
+
|
947
|
+
def visit_tstring_end(node)
|
948
|
+
node(node, "tstring_end") { field("value", node.value) }
|
949
|
+
end
|
950
|
+
|
951
|
+
def visit_unary(node)
|
952
|
+
node(node, "unary") do
|
953
|
+
field("operator", node.operator)
|
954
|
+
field("statement", node.statement)
|
955
|
+
comments(node)
|
956
|
+
end
|
957
|
+
end
|
958
|
+
|
959
|
+
def visit_undef(node)
|
960
|
+
node(node, "undef") do
|
961
|
+
list("symbols", node.symbols)
|
962
|
+
comments(node)
|
963
|
+
end
|
964
|
+
end
|
965
|
+
|
966
|
+
def visit_unless(node)
|
967
|
+
node(node, "unless") do
|
968
|
+
field("predicate", node.predicate)
|
969
|
+
field("statements", node.statements)
|
970
|
+
field("consequent", node.consequent) if node.consequent
|
971
|
+
comments(node)
|
972
|
+
end
|
973
|
+
end
|
974
|
+
|
975
|
+
def visit_unless_mod(node)
|
976
|
+
node(node, "unless_mod") do
|
977
|
+
field("statement", node.statement)
|
978
|
+
field("predicate", node.predicate)
|
979
|
+
comments(node)
|
980
|
+
end
|
981
|
+
end
|
982
|
+
|
983
|
+
def visit_until(node)
|
984
|
+
node(node, "until") do
|
985
|
+
field("predicate", node.predicate)
|
986
|
+
field("statements", node.statements)
|
987
|
+
comments(node)
|
988
|
+
end
|
989
|
+
end
|
990
|
+
|
991
|
+
def visit_until_mod(node)
|
992
|
+
node(node, "until_mod") do
|
993
|
+
field("statement", node.statement)
|
994
|
+
field("predicate", node.predicate)
|
995
|
+
comments(node)
|
996
|
+
end
|
997
|
+
end
|
998
|
+
|
999
|
+
def visit_var_alias(node)
|
1000
|
+
node(node, "var_alias") do
|
1001
|
+
field("left", node.left)
|
1002
|
+
field("right", node.right)
|
1003
|
+
comments(node)
|
1004
|
+
end
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
def visit_var_field(node)
|
1008
|
+
node(node, "var_field") do
|
1009
|
+
field("value", node.value)
|
1010
|
+
comments(node)
|
1011
|
+
end
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
def visit_var_ref(node)
|
1015
|
+
node(node, "var_ref") do
|
1016
|
+
field("value", node.value)
|
1017
|
+
comments(node)
|
1018
|
+
end
|
1019
|
+
end
|
1020
|
+
|
1021
|
+
def visit_vcall(node)
|
1022
|
+
node(node, "vcall") do
|
1023
|
+
field("value", node.value)
|
1024
|
+
comments(node)
|
1025
|
+
end
|
1026
|
+
end
|
1027
|
+
|
1028
|
+
def visit_void_stmt(node)
|
1029
|
+
node(node, "void_stmt") { comments(node) }
|
1030
|
+
end
|
1031
|
+
|
1032
|
+
def visit_when(node)
|
1033
|
+
node(node, "when") do
|
1034
|
+
field("arguments", node.arguments)
|
1035
|
+
field("statements", node.statements)
|
1036
|
+
field("consequent", node.consequent) if node.consequent
|
1037
|
+
comments(node)
|
1038
|
+
end
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
def visit_while(node)
|
1042
|
+
node(node, "while") do
|
1043
|
+
field("predicate", node.predicate)
|
1044
|
+
field("statements", node.statements)
|
1045
|
+
comments(node)
|
1046
|
+
end
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
def visit_while_mod(node)
|
1050
|
+
node(node, "while_mod") do
|
1051
|
+
field("statement", node.statement)
|
1052
|
+
field("predicate", node.predicate)
|
1053
|
+
comments(node)
|
1054
|
+
end
|
1055
|
+
end
|
1056
|
+
|
1057
|
+
def visit_word(node)
|
1058
|
+
node(node, "word") do
|
1059
|
+
list("parts", node.parts)
|
1060
|
+
comments(node)
|
1061
|
+
end
|
1062
|
+
end
|
1063
|
+
|
1064
|
+
def visit_words(node)
|
1065
|
+
node(node, "words") do
|
1066
|
+
list("elements", node.elements)
|
1067
|
+
comments(node)
|
1068
|
+
end
|
1069
|
+
end
|
1070
|
+
|
1071
|
+
def visit_words_beg(node)
|
1072
|
+
node(node, "words_beg") { field("value", node.value) }
|
1073
|
+
end
|
1074
|
+
|
1075
|
+
def visit_xstring(node)
|
1076
|
+
node(node, "xstring") { list("parts", node.parts) }
|
1077
|
+
end
|
1078
|
+
|
1079
|
+
def visit_xstring_literal(node)
|
1080
|
+
node(node, "xstring_literal") do
|
1081
|
+
list("parts", node.parts)
|
1082
|
+
comments(node)
|
1083
|
+
end
|
1084
|
+
end
|
1085
|
+
|
1086
|
+
def visit_yield(node)
|
1087
|
+
node(node, "yield") do
|
1088
|
+
field("arguments", node.arguments)
|
1089
|
+
comments(node)
|
1090
|
+
end
|
1091
|
+
end
|
1092
|
+
|
1093
|
+
def visit_yield0(node)
|
1094
|
+
visit_token(node, "yield0")
|
1095
|
+
end
|
1096
|
+
|
1097
|
+
def visit_zsuper(node)
|
1098
|
+
visit_token(node, "zsuper")
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
def visit___end__(node)
|
1102
|
+
visit_token(node, "__end__")
|
1103
|
+
end
|
1104
|
+
|
1105
|
+
private
|
1106
|
+
|
1107
|
+
def visit_token(node, type)
|
1108
|
+
node(node, type) do
|
1109
|
+
field("value", node.value)
|
1110
|
+
comments(node)
|
1111
|
+
end
|
1112
|
+
end
|
1113
|
+
end
|
1114
|
+
end
|
1115
|
+
end
|