Class: SyntaxTree::Visitor::FieldVisitor

Inherits:
BasicVisitor show all
Defined in:
lib/syntax_tree/visitor/field_visitor.rb

Overview

This is the parent class of a lot of built-in visitors for Syntax Tree. It reflects visiting each of the fields on every node in turn. It itself does not do anything with these fields, it leaves that behavior up to the subclass to implement.

In order to properly use this class, you will need to subclass it and implement #comments, #field, #list, #node, #pairs, and #text. Those are documented here.

comments(node)

This accepts the node that is being visited and does something depending on the comments attached to the node.

field(name, value)

This accepts the name of the field being visited as a string (like “value”) and the actual value of that field. The value can be a subclass of Node or any other type that can be held within the tree.

list(name, values)

This accepts the name of the field being visited as well as a list of values. This is used, for example, when visiting something like the body of a Statements node.

node(name, node)

This is the parent serialization method for each node. It is called with the node itself, as well as the type of the node as a string. The type is an internally used value that usually resembles the name of the ripper event that generated the node. The method should yield to the given block which then calls through to visit each of the fields on the node.

text(name, value)

This accepts the name of the field being visited as well as a string value representing the value of the field.

pairs(name, values)

This accepts the name of the field being visited as well as a list of pairs that represent the value of the field. It is used only in a couple of circumstances, like when visiting the list of optional parameters defined on a method.

Direct Known Subclasses

JSONVisitor, MatchVisitor, PrettyPrintVisitor

Instance Method Summary collapse

Methods inherited from BasicVisitor

#visit, #visit_all, #visit_child_nodes, visit_method, visit_methods

Instance Method Details

#visit___end__(node) ⇒ Object



1017
1018
1019
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 1017

def visit___end__(node)
  visit_token(node, "__end__")
end

#visit_alias(node) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 69

def visit_alias(node)
  node(node, "alias") do
    field("left", node.left)
    field("right", node.right)
    comments(node)
  end
end

#visit_aref(node) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 53

def visit_aref(node)
  node(node, "aref") do
    field("collection", node.collection)
    field("index", node.index)
    comments(node)
  end
end

#visit_aref_field(node) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 61

def visit_aref_field(node)
  node(node, "aref_field") do
    field("collection", node.collection)
    field("index", node.index)
    comments(node)
  end
end

#visit_arg_block(node) ⇒ Object



77
78
79
80
81
82
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 77

def visit_arg_block(node)
  node(node, "arg_block") do
    field("value", node.value) if node.value
    comments(node)
  end
end

#visit_arg_paren(node) ⇒ Object



84
85
86
87
88
89
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 84

def visit_arg_paren(node)
  node(node, "arg_paren") do
    field("arguments", node.arguments)
    comments(node)
  end
end

#visit_arg_star(node) ⇒ Object



91
92
93
94
95
96
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 91

def visit_arg_star(node)
  node(node, "arg_star") do
    field("value", node.value)
    comments(node)
  end
end

#visit_args(node) ⇒ Object



98
99
100
101
102
103
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 98

def visit_args(node)
  node(node, "args") do
    list("parts", node.parts)
    comments(node)
  end
end

#visit_args_forward(node) ⇒ Object



105
106
107
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 105

def visit_args_forward(node)
  node(node, "args_forward") { comments(node) }
end

#visit_array(node) ⇒ Object



109
110
111
112
113
114
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 109

def visit_array(node)
  node(node, "array") do
    field("contents", node.contents)
    comments(node)
  end
end

#visit_aryptn(node) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 116

def visit_aryptn(node)
  node(node, "aryptn") do
    field("constant", node.constant) if node.constant
    list("requireds", node.requireds) if node.requireds.any?
    field("rest", node.rest) if node.rest
    list("posts", node.posts) if node.posts.any?
    comments(node)
  end
end

#visit_assign(node) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 126

def visit_assign(node)
  node(node, "assign") do
    field("target", node.target)
    field("value", node.value)
    comments(node)
  end
end

#visit_assoc(node) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 134

def visit_assoc(node)
  node(node, "assoc") do
    field("key", node.key)
    field("value", node.value) if node.value
    comments(node)
  end
end

#visit_assoc_splat(node) ⇒ Object



142
143
144
145
146
147
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 142

def visit_assoc_splat(node)
  node(node, "assoc_splat") do
    field("value", node.value)
    comments(node)
  end
end

#visit_backref(node) ⇒ Object



149
150
151
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 149

def visit_backref(node)
  visit_token(node, "backref")
end

#visit_backtick(node) ⇒ Object



153
154
155
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 153

def visit_backtick(node)
  visit_token(node, "backtick")
end

#visit_bare_assoc_hash(node) ⇒ Object



157
158
159
160
161
162
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 157

def visit_bare_assoc_hash(node)
  node(node, "bare_assoc_hash") do
    list("assocs", node.assocs)
    comments(node)
  end
end

#visit_BEGIN(node) ⇒ Object



164
165
166
167
168
169
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 164

def visit_BEGIN(node)
  node(node, "BEGIN") do
    field("statements", node.statements)
    comments(node)
  end
end

#visit_begin(node) ⇒ Object



171
172
173
174
175
176
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 171

def visit_begin(node)
  node(node, "begin") do
    field("bodystmt", node.bodystmt)
    comments(node)
  end
end

#visit_binary(node) ⇒ Object



178
179
180
181
182
183
184
185
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 178

def visit_binary(node)
  node(node, "binary") do
    field("left", node.left)
    text("operator", node.operator)
    field("right", node.right)
    comments(node)
  end
end

#visit_block(node) ⇒ Object



187
188
189
190
191
192
193
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 187

def visit_block(node)
  node(node, "block") do
    field("block_var", node.block_var) if node.block_var
    field("bodystmt", node.bodystmt)
    comments(node)
  end
end

#visit_block_var(node) ⇒ Object



202
203
204
205
206
207
208
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 202

def visit_block_var(node)
  node(node, "block_var") do
    field("params", node.params)
    list("locals", node.locals) if node.locals.any?
    comments(node)
  end
end

#visit_blockarg(node) ⇒ Object



195
196
197
198
199
200
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 195

def visit_blockarg(node)
  node(node, "blockarg") do
    field("name", node.name) if node.name
    comments(node)
  end
end

#visit_bodystmt(node) ⇒ Object



210
211
212
213
214
215
216
217
218
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 210

def visit_bodystmt(node)
  node(node, "bodystmt") do
    field("statements", node.statements)
    field("rescue_clause", node.rescue_clause) if node.rescue_clause
    field("else_clause", node.else_clause) if node.else_clause
    field("ensure_clause", node.ensure_clause) if node.ensure_clause
    comments(node)
  end
end

#visit_break(node) ⇒ Object



220
221
222
223
224
225
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 220

def visit_break(node)
  node(node, "break") do
    field("arguments", node.arguments)
    comments(node)
  end
end

#visit_call(node) ⇒ Object



227
228
229
230
231
232
233
234
235
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 227

def visit_call(node)
  node(node, "call") do
    field("receiver", node.receiver)
    field("operator", node.operator)
    field("message", node.message)
    field("arguments", node.arguments) if node.arguments
    comments(node)
  end
end

#visit_case(node) ⇒ Object



237
238
239
240
241
242
243
244
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 237

def visit_case(node)
  node(node, "case") do
    field("keyword", node.keyword)
    field("value", node.value) if node.value
    field("consequent", node.consequent)
    comments(node)
  end
end

#visit_CHAR(node) ⇒ Object



246
247
248
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 246

def visit_CHAR(node)
  visit_token(node, "CHAR")
end

#visit_class(node) ⇒ Object



250
251
252
253
254
255
256
257
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 250

def visit_class(node)
  node(node, "class") do
    field("constant", node.constant)
    field("superclass", node.superclass) if node.superclass
    field("bodystmt", node.bodystmt)
    comments(node)
  end
end

#visit_comma(node) ⇒ Object



259
260
261
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 259

def visit_comma(node)
  node(node, "comma") { field("value", node.value) }
end

#visit_command(node) ⇒ Object



263
264
265
266
267
268
269
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 263

def visit_command(node)
  node(node, "command") do
    field("message", node.message)
    field("arguments", node.arguments)
    comments(node)
  end
end

#visit_command_call(node) ⇒ Object



271
272
273
274
275
276
277
278
279
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 271

def visit_command_call(node)
  node(node, "command_call") do
    field("receiver", node.receiver)
    field("operator", node.operator)
    field("message", node.message)
    field("arguments", node.arguments) if node.arguments
    comments(node)
  end
end

#visit_comment(node) ⇒ Object



281
282
283
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 281

def visit_comment(node)
  node(node, "comment") { field("value", node.value) }
end

#visit_const(node) ⇒ Object



285
286
287
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 285

def visit_const(node)
  visit_token(node, "const")
end

#visit_const_path_field(node) ⇒ Object



289
290
291
292
293
294
295
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 289

def visit_const_path_field(node)
  node(node, "const_path_field") do
    field("parent", node.parent)
    field("constant", node.constant)
    comments(node)
  end
end

#visit_const_path_ref(node) ⇒ Object



297
298
299
300
301
302
303
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 297

def visit_const_path_ref(node)
  node(node, "const_path_ref") do
    field("parent", node.parent)
    field("constant", node.constant)
    comments(node)
  end
end

#visit_const_ref(node) ⇒ Object



305
306
307
308
309
310
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 305

def visit_const_ref(node)
  node(node, "const_ref") do
    field("constant", node.constant)
    comments(node)
  end
end

#visit_cvar(node) ⇒ Object



312
313
314
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 312

def visit_cvar(node)
  visit_token(node, "cvar")
end

#visit_def(node) ⇒ Object



316
317
318
319
320
321
322
323
324
325
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 316

def visit_def(node)
  node(node, "def") do
    field("target", node.target)
    field("operator", node.operator)
    field("name", node.name)
    field("params", node.params)
    field("bodystmt", node.bodystmt)
    comments(node)
  end
end

#visit_defined(node) ⇒ Object



327
328
329
330
331
332
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 327

def visit_defined(node)
  node(node, "defined") do
    field("value", node.value)
    comments(node)
  end
end

#visit_dyna_symbol(node) ⇒ Object



334
335
336
337
338
339
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 334

def visit_dyna_symbol(node)
  node(node, "dyna_symbol") do
    list("parts", node.parts)
    comments(node)
  end
end

#visit_else(node) ⇒ Object



348
349
350
351
352
353
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 348

def visit_else(node)
  node(node, "else") do
    field("statements", node.statements)
    comments(node)
  end
end

#visit_elsif(node) ⇒ Object



355
356
357
358
359
360
361
362
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 355

def visit_elsif(node)
  node(node, "elsif") do
    field("predicate", node.predicate)
    field("statements", node.statements)
    field("consequent", node.consequent) if node.consequent
    comments(node)
  end
end

#visit_embdoc(node) ⇒ Object



364
365
366
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 364

def visit_embdoc(node)
  node(node, "embdoc") { field("value", node.value) }
end

#visit_embexpr_beg(node) ⇒ Object



368
369
370
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 368

def visit_embexpr_beg(node)
  node(node, "embexpr_beg") { field("value", node.value) }
end

#visit_embexpr_end(node) ⇒ Object



372
373
374
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 372

def visit_embexpr_end(node)
  node(node, "embexpr_end") { field("value", node.value) }
end

#visit_embvar(node) ⇒ Object



376
377
378
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 376

def visit_embvar(node)
  node(node, "embvar") { field("value", node.value) }
end

#visit_END(node) ⇒ Object



341
342
343
344
345
346
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 341

def visit_END(node)
  node(node, "END") do
    field("statements", node.statements)
    comments(node)
  end
end

#visit_ensure(node) ⇒ Object



380
381
382
383
384
385
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 380

def visit_ensure(node)
  node(node, "ensure") do
    field("statements", node.statements)
    comments(node)
  end
end

#visit_excessed_comma(node) ⇒ Object



387
388
389
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 387

def visit_excessed_comma(node)
  visit_token(node, "excessed_comma")
end

#visit_field(node) ⇒ Object



391
392
393
394
395
396
397
398
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 391

def visit_field(node)
  node(node, "field") do
    field("parent", node.parent)
    field("operator", node.operator)
    field("name", node.name)
    comments(node)
  end
end

#visit_float(node) ⇒ Object



400
401
402
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 400

def visit_float(node)
  visit_token(node, "float")
end

#visit_fndptn(node) ⇒ Object



404
405
406
407
408
409
410
411
412
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 404

def visit_fndptn(node)
  node(node, "fndptn") do
    field("constant", node.constant) if node.constant
    field("left", node.left)
    list("values", node.values)
    field("right", node.right)
    comments(node)
  end
end

#visit_for(node) ⇒ Object



414
415
416
417
418
419
420
421
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 414

def visit_for(node)
  node(node, "for") do
    field("index", node.index)
    field("collection", node.collection)
    field("statements", node.statements)
    comments(node)
  end
end

#visit_gvar(node) ⇒ Object



423
424
425
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 423

def visit_gvar(node)
  visit_token(node, "gvar")
end

#visit_hash(node) ⇒ Object



427
428
429
430
431
432
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 427

def visit_hash(node)
  node(node, "hash") do
    list("assocs", node.assocs) if node.assocs.any?
    comments(node)
  end
end

#visit_heredoc(node) ⇒ Object



434
435
436
437
438
439
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 434

def visit_heredoc(node)
  node(node, "heredoc") do
    list("parts", node.parts)
    comments(node)
  end
end

#visit_heredoc_beg(node) ⇒ Object



441
442
443
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 441

def visit_heredoc_beg(node)
  visit_token(node, "heredoc_beg")
end

#visit_heredoc_end(node) ⇒ Object



445
446
447
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 445

def visit_heredoc_end(node)
  visit_token(node, "heredoc_end")
end

#visit_hshptn(node) ⇒ Object



449
450
451
452
453
454
455
456
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 449

def visit_hshptn(node)
  node(node, "hshptn") do
    field("constant", node.constant) if node.constant
    pairs("keywords", node.keywords) if node.keywords.any?
    field("keyword_rest", node.keyword_rest) if node.keyword_rest
    comments(node)
  end
end

#visit_ident(node) ⇒ Object



458
459
460
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 458

def visit_ident(node)
  visit_token(node, "ident")
end

#visit_if(node) ⇒ Object



462
463
464
465
466
467
468
469
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 462

def visit_if(node)
  node(node, "if") do
    field("predicate", node.predicate)
    field("statements", node.statements)
    field("consequent", node.consequent) if node.consequent
    comments(node)
  end
end

#visit_if_op(node) ⇒ Object



471
472
473
474
475
476
477
478
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 471

def visit_if_op(node)
  node(node, "if_op") do
    field("predicate", node.predicate)
    field("truthy", node.truthy)
    field("falsy", node.falsy)
    comments(node)
  end
end

#visit_imaginary(node) ⇒ Object



480
481
482
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 480

def visit_imaginary(node)
  visit_token(node, "imaginary")
end

#visit_in(node) ⇒ Object



484
485
486
487
488
489
490
491
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 484

def visit_in(node)
  node(node, "in") do
    field("pattern", node.pattern)
    field("statements", node.statements)
    field("consequent", node.consequent) if node.consequent
    comments(node)
  end
end

#visit_int(node) ⇒ Object



493
494
495
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 493

def visit_int(node)
  visit_token(node, "int")
end

#visit_ivar(node) ⇒ Object



497
498
499
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 497

def visit_ivar(node)
  visit_token(node, "ivar")
end

#visit_kw(node) ⇒ Object



501
502
503
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 501

def visit_kw(node)
  visit_token(node, "kw")
end

#visit_kwrest_param(node) ⇒ Object



505
506
507
508
509
510
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 505

def visit_kwrest_param(node)
  node(node, "kwrest_param") do
    field("name", node.name)
    comments(node)
  end
end

#visit_label(node) ⇒ Object



512
513
514
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 512

def visit_label(node)
  visit_token(node, "label")
end

#visit_label_end(node) ⇒ Object



516
517
518
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 516

def visit_label_end(node)
  node(node, "label_end") { field("value", node.value) }
end

#visit_lambda(node) ⇒ Object



520
521
522
523
524
525
526
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 520

def visit_lambda(node)
  node(node, "lambda") do
    field("params", node.params)
    field("statements", node.statements)
    comments(node)
  end
end

#visit_lambda_var(node) ⇒ Object



528
529
530
531
532
533
534
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 528

def visit_lambda_var(node)
  node(node, "lambda_var") do
    field("params", node.params)
    list("locals", node.locals) if node.locals.any?
    comments(node)
  end
end

#visit_lbrace(node) ⇒ Object



536
537
538
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 536

def visit_lbrace(node)
  visit_token(node, "lbrace")
end

#visit_lbracket(node) ⇒ Object



540
541
542
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 540

def visit_lbracket(node)
  visit_token(node, "lbracket")
end

#visit_lparen(node) ⇒ Object



544
545
546
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 544

def visit_lparen(node)
  visit_token(node, "lparen")
end

#visit_massign(node) ⇒ Object



548
549
550
551
552
553
554
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 548

def visit_massign(node)
  node(node, "massign") do
    field("target", node.target)
    field("value", node.value)
    comments(node)
  end
end

#visit_method_add_block(node) ⇒ Object



556
557
558
559
560
561
562
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 556

def visit_method_add_block(node)
  node(node, "method_add_block") do
    field("call", node.call)
    field("block", node.block)
    comments(node)
  end
end

#visit_mlhs(node) ⇒ Object



564
565
566
567
568
569
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 564

def visit_mlhs(node)
  node(node, "mlhs") do
    list("parts", node.parts)
    comments(node)
  end
end

#visit_mlhs_paren(node) ⇒ Object



571
572
573
574
575
576
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 571

def visit_mlhs_paren(node)
  node(node, "mlhs_paren") do
    field("contents", node.contents)
    comments(node)
  end
end

#visit_module(node) ⇒ Object



578
579
580
581
582
583
584
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 578

def visit_module(node)
  node(node, "module") do
    field("constant", node.constant)
    field("bodystmt", node.bodystmt)
    comments(node)
  end
end

#visit_mrhs(node) ⇒ Object



586
587
588
589
590
591
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 586

def visit_mrhs(node)
  node(node, "mrhs") do
    list("parts", node.parts)
    comments(node)
  end
end

#visit_next(node) ⇒ Object



593
594
595
596
597
598
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 593

def visit_next(node)
  node(node, "next") do
    field("arguments", node.arguments)
    comments(node)
  end
end

#visit_not(node) ⇒ Object



600
601
602
603
604
605
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 600

def visit_not(node)
  node(node, "not") do
    field("statement", node.statement)
    comments(node)
  end
end

#visit_op(node) ⇒ Object



607
608
609
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 607

def visit_op(node)
  visit_token(node, "op")
end

#visit_opassign(node) ⇒ Object



611
612
613
614
615
616
617
618
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 611

def visit_opassign(node)
  node(node, "opassign") do
    field("target", node.target)
    field("operator", node.operator)
    field("value", node.value)
    comments(node)
  end
end

#visit_params(node) ⇒ Object



620
621
622
623
624
625
626
627
628
629
630
631
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 620

def visit_params(node)
  node(node, "params") do
    list("requireds", node.requireds) if node.requireds.any?
    pairs("optionals", node.optionals) if node.optionals.any?
    field("rest", node.rest) if node.rest
    list("posts", node.posts) if node.posts.any?
    pairs("keywords", node.keywords) if node.keywords.any?
    field("keyword_rest", node.keyword_rest) if node.keyword_rest
    field("block", node.block) if node.block
    comments(node)
  end
end

#visit_paren(node) ⇒ Object



633
634
635
636
637
638
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 633

def visit_paren(node)
  node(node, "paren") do
    field("contents", node.contents)
    comments(node)
  end
end

#visit_period(node) ⇒ Object



640
641
642
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 640

def visit_period(node)
  visit_token(node, "period")
end

#visit_pinned_begin(node) ⇒ Object



644
645
646
647
648
649
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 644

def visit_pinned_begin(node)
  node(node, "pinned_begin") do
    field("statement", node.statement)
    comments(node)
  end
end

#visit_pinned_var_ref(node) ⇒ Object



651
652
653
654
655
656
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 651

def visit_pinned_var_ref(node)
  node(node, "pinned_var_ref") do
    field("value", node.value)
    comments(node)
  end
end

#visit_program(node) ⇒ Object



658
659
660
661
662
663
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 658

def visit_program(node)
  node(node, "program") do
    field("statements", node.statements)
    comments(node)
  end
end

#visit_qsymbols(node) ⇒ Object



665
666
667
668
669
670
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 665

def visit_qsymbols(node)
  node(node, "qsymbols") do
    list("elements", node.elements)
    comments(node)
  end
end

#visit_qsymbols_beg(node) ⇒ Object



672
673
674
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 672

def visit_qsymbols_beg(node)
  node(node, "qsymbols_beg") { field("value", node.value) }
end

#visit_qwords(node) ⇒ Object



676
677
678
679
680
681
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 676

def visit_qwords(node)
  node(node, "qwords") do
    list("elements", node.elements)
    comments(node)
  end
end

#visit_qwords_beg(node) ⇒ Object



683
684
685
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 683

def visit_qwords_beg(node)
  node(node, "qwords_beg") { field("value", node.value) }
end

#visit_range(node) ⇒ Object



687
688
689
690
691
692
693
694
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 687

def visit_range(node)
  node(node, "range") do
    field("left", node.left) if node.left
    field("operator", node.operator)
    field("right", node.right) if node.right
    comments(node)
  end
end

#visit_rassign(node) ⇒ Object



696
697
698
699
700
701
702
703
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 696

def visit_rassign(node)
  node(node, "rassign") do
    field("value", node.value)
    field("operator", node.operator)
    field("pattern", node.pattern)
    comments(node)
  end
end

#visit_rational(node) ⇒ Object



705
706
707
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 705

def visit_rational(node)
  visit_token(node, "rational")
end

#visit_rbrace(node) ⇒ Object



709
710
711
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 709

def visit_rbrace(node)
  node(node, "rbrace") { field("value", node.value) }
end

#visit_rbracket(node) ⇒ Object



713
714
715
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 713

def visit_rbracket(node)
  node(node, "rbracket") { field("value", node.value) }
end

#visit_redo(node) ⇒ Object



717
718
719
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 717

def visit_redo(node)
  node(node, "redo") { comments(node) }
end

#visit_regexp_beg(node) ⇒ Object



721
722
723
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 721

def visit_regexp_beg(node)
  node(node, "regexp_beg") { field("value", node.value) }
end

#visit_regexp_content(node) ⇒ Object



725
726
727
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 725

def visit_regexp_content(node)
  node(node, "regexp_content") { list("parts", node.parts) }
end

#visit_regexp_end(node) ⇒ Object



729
730
731
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 729

def visit_regexp_end(node)
  node(node, "regexp_end") { field("value", node.value) }
end

#visit_regexp_literal(node) ⇒ Object



733
734
735
736
737
738
739
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 733

def visit_regexp_literal(node)
  node(node, "regexp_literal") do
    list("parts", node.parts)
    field("options", node.options)
    comments(node)
  end
end

#visit_rescue(node) ⇒ Object



741
742
743
744
745
746
747
748
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 741

def visit_rescue(node)
  node(node, "rescue") do
    field("exception", node.exception) if node.exception
    field("statements", node.statements)
    field("consequent", node.consequent) if node.consequent
    comments(node)
  end
end

#visit_rescue_ex(node) ⇒ Object



750
751
752
753
754
755
756
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 750

def visit_rescue_ex(node)
  node(node, "rescue_ex") do
    field("exceptions", node.exceptions)
    field("variable", node.variable)
    comments(node)
  end
end

#visit_rescue_mod(node) ⇒ Object



758
759
760
761
762
763
764
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 758

def visit_rescue_mod(node)
  node(node, "rescue_mod") do
    field("statement", node.statement)
    field("value", node.value)
    comments(node)
  end
end

#visit_rest_param(node) ⇒ Object



766
767
768
769
770
771
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 766

def visit_rest_param(node)
  node(node, "rest_param") do
    field("name", node.name)
    comments(node)
  end
end

#visit_retry(node) ⇒ Object



773
774
775
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 773

def visit_retry(node)
  node(node, "retry") { comments(node) }
end

#visit_return(node) ⇒ Object



777
778
779
780
781
782
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 777

def visit_return(node)
  node(node, "return") do
    field("arguments", node.arguments)
    comments(node)
  end
end

#visit_rparen(node) ⇒ Object



784
785
786
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 784

def visit_rparen(node)
  node(node, "rparen") { field("value", node.value) }
end

#visit_sclass(node) ⇒ Object



788
789
790
791
792
793
794
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 788

def visit_sclass(node)
  node(node, "sclass") do
    field("target", node.target)
    field("bodystmt", node.bodystmt)
    comments(node)
  end
end

#visit_statements(node) ⇒ Object



796
797
798
799
800
801
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 796

def visit_statements(node)
  node(node, "statements") do
    list("body", node.body)
    comments(node)
  end
end

#visit_string_concat(node) ⇒ Object



803
804
805
806
807
808
809
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 803

def visit_string_concat(node)
  node(node, "string_concat") do
    field("left", node.left)
    field("right", node.right)
    comments(node)
  end
end

#visit_string_content(node) ⇒ Object



811
812
813
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 811

def visit_string_content(node)
  node(node, "string_content") { list("parts", node.parts) }
end

#visit_string_dvar(node) ⇒ Object



815
816
817
818
819
820
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 815

def visit_string_dvar(node)
  node(node, "string_dvar") do
    field("variable", node.variable)
    comments(node)
  end
end

#visit_string_embexpr(node) ⇒ Object



822
823
824
825
826
827
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 822

def visit_string_embexpr(node)
  node(node, "string_embexpr") do
    field("statements", node.statements)
    comments(node)
  end
end

#visit_string_literal(node) ⇒ Object



829
830
831
832
833
834
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 829

def visit_string_literal(node)
  node(node, "string_literal") do
    list("parts", node.parts)
    comments(node)
  end
end

#visit_super(node) ⇒ Object



836
837
838
839
840
841
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 836

def visit_super(node)
  node(node, "super") do
    field("arguments", node.arguments)
    comments(node)
  end
end

#visit_symbeg(node) ⇒ Object



843
844
845
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 843

def visit_symbeg(node)
  node(node, "symbeg") { field("value", node.value) }
end

#visit_symbol_content(node) ⇒ Object



847
848
849
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 847

def visit_symbol_content(node)
  node(node, "symbol_content") { field("value", node.value) }
end

#visit_symbol_literal(node) ⇒ Object



851
852
853
854
855
856
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 851

def visit_symbol_literal(node)
  node(node, "symbol_literal") do
    field("value", node.value)
    comments(node)
  end
end

#visit_symbols(node) ⇒ Object



858
859
860
861
862
863
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 858

def visit_symbols(node)
  node(node, "symbols") do
    list("elements", node.elements)
    comments(node)
  end
end

#visit_symbols_beg(node) ⇒ Object



865
866
867
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 865

def visit_symbols_beg(node)
  node(node, "symbols_beg") { field("value", node.value) }
end

#visit_tlambda(node) ⇒ Object



869
870
871
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 869

def visit_tlambda(node)
  node(node, "tlambda") { field("value", node.value) }
end

#visit_tlambeg(node) ⇒ Object



873
874
875
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 873

def visit_tlambeg(node)
  node(node, "tlambeg") { field("value", node.value) }
end

#visit_top_const_field(node) ⇒ Object



877
878
879
880
881
882
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 877

def visit_top_const_field(node)
  node(node, "top_const_field") do
    field("constant", node.constant)
    comments(node)
  end
end

#visit_top_const_ref(node) ⇒ Object



884
885
886
887
888
889
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 884

def visit_top_const_ref(node)
  node(node, "top_const_ref") do
    field("constant", node.constant)
    comments(node)
  end
end

#visit_tstring_beg(node) ⇒ Object



891
892
893
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 891

def visit_tstring_beg(node)
  node(node, "tstring_beg") { field("value", node.value) }
end

#visit_tstring_content(node) ⇒ Object



895
896
897
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 895

def visit_tstring_content(node)
  visit_token(node, "tstring_content")
end

#visit_tstring_end(node) ⇒ Object



899
900
901
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 899

def visit_tstring_end(node)
  node(node, "tstring_end") { field("value", node.value) }
end

#visit_unary(node) ⇒ Object



903
904
905
906
907
908
909
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 903

def visit_unary(node)
  node(node, "unary") do
    field("operator", node.operator)
    field("statement", node.statement)
    comments(node)
  end
end

#visit_undef(node) ⇒ Object



911
912
913
914
915
916
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 911

def visit_undef(node)
  node(node, "undef") do
    list("symbols", node.symbols)
    comments(node)
  end
end

#visit_unless(node) ⇒ Object



918
919
920
921
922
923
924
925
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 918

def visit_unless(node)
  node(node, "unless") do
    field("predicate", node.predicate)
    field("statements", node.statements)
    field("consequent", node.consequent) if node.consequent
    comments(node)
  end
end

#visit_until(node) ⇒ Object



927
928
929
930
931
932
933
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 927

def visit_until(node)
  node(node, "until") do
    field("predicate", node.predicate)
    field("statements", node.statements)
    comments(node)
  end
end

#visit_var_field(node) ⇒ Object



935
936
937
938
939
940
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 935

def visit_var_field(node)
  node(node, "var_field") do
    field("value", node.value)
    comments(node)
  end
end

#visit_var_ref(node) ⇒ Object



942
943
944
945
946
947
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 942

def visit_var_ref(node)
  node(node, "var_ref") do
    field("value", node.value)
    comments(node)
  end
end

#visit_vcall(node) ⇒ Object



949
950
951
952
953
954
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 949

def visit_vcall(node)
  node(node, "vcall") do
    field("value", node.value)
    comments(node)
  end
end

#visit_void_stmt(node) ⇒ Object



956
957
958
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 956

def visit_void_stmt(node)
  node(node, "void_stmt") { comments(node) }
end

#visit_when(node) ⇒ Object



960
961
962
963
964
965
966
967
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 960

def visit_when(node)
  node(node, "when") do
    field("arguments", node.arguments)
    field("statements", node.statements)
    field("consequent", node.consequent) if node.consequent
    comments(node)
  end
end

#visit_while(node) ⇒ Object



969
970
971
972
973
974
975
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 969

def visit_while(node)
  node(node, "while") do
    field("predicate", node.predicate)
    field("statements", node.statements)
    comments(node)
  end
end

#visit_word(node) ⇒ Object



977
978
979
980
981
982
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 977

def visit_word(node)
  node(node, "word") do
    list("parts", node.parts)
    comments(node)
  end
end

#visit_words(node) ⇒ Object



984
985
986
987
988
989
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 984

def visit_words(node)
  node(node, "words") do
    list("elements", node.elements)
    comments(node)
  end
end

#visit_words_beg(node) ⇒ Object



991
992
993
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 991

def visit_words_beg(node)
  node(node, "words_beg") { field("value", node.value) }
end

#visit_xstring(node) ⇒ Object



995
996
997
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 995

def visit_xstring(node)
  node(node, "xstring") { list("parts", node.parts) }
end

#visit_xstring_literal(node) ⇒ Object



999
1000
1001
1002
1003
1004
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 999

def visit_xstring_literal(node)
  node(node, "xstring_literal") do
    list("parts", node.parts)
    comments(node)
  end
end

#visit_yield(node) ⇒ Object



1006
1007
1008
1009
1010
1011
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 1006

def visit_yield(node)
  node(node, "yield") do
    field("arguments", node.arguments)
    comments(node)
  end
end

#visit_zsuper(node) ⇒ Object



1013
1014
1015
# File 'lib/syntax_tree/visitor/field_visitor.rb', line 1013

def visit_zsuper(node)
  node(node, "zsuper") { comments(node) }
end