syntax_tree 4.3.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +1 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +26 -1
- data/Gemfile.lock +4 -4
- data/README.md +111 -12
- data/lib/syntax_tree/cli.rb +57 -25
- data/lib/syntax_tree/formatter.rb +56 -20
- data/lib/syntax_tree/node.rb +3119 -1409
- data/lib/syntax_tree/parser.rb +118 -92
- data/lib/syntax_tree/pattern.rb +3 -3
- data/lib/syntax_tree/plugin/single_quotes.rb +5 -1
- data/lib/syntax_tree/plugin/trailing_comma.rb +5 -1
- data/lib/syntax_tree/version.rb +1 -1
- data/lib/syntax_tree/visitor/environment.rb +7 -4
- data/lib/syntax_tree/visitor/field_visitor.rb +23 -117
- data/lib/syntax_tree/visitor/mutation_visitor.rb +924 -0
- data/lib/syntax_tree/visitor/with_environment.rb +0 -8
- data/lib/syntax_tree/visitor.rb +12 -48
- data/lib/syntax_tree.rb +14 -2
- data/syntax_tree.gemspec +1 -1
- metadata +6 -4
@@ -103,7 +103,7 @@ module SyntaxTree
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def visit_args_forward(node)
|
106
|
-
|
106
|
+
node(node, "args_forward") { comments(node) }
|
107
107
|
end
|
108
108
|
|
109
109
|
def visit_array(node)
|
@@ -184,6 +184,14 @@ module SyntaxTree
|
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
+
def visit_block(node)
|
188
|
+
node(node, "block") do
|
189
|
+
field("block_var", node.block_var) if node.block_var
|
190
|
+
field("bodystmt", node.bodystmt)
|
191
|
+
comments(node)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
187
195
|
def visit_blockarg(node)
|
188
196
|
node(node, "blockarg") do
|
189
197
|
field("name", node.name) if node.name
|
@@ -209,14 +217,6 @@ module SyntaxTree
|
|
209
217
|
end
|
210
218
|
end
|
211
219
|
|
212
|
-
def visit_brace_block(node)
|
213
|
-
node(node, "brace_block") do
|
214
|
-
field("block_var", node.block_var) if node.block_var
|
215
|
-
field("statements", node.statements)
|
216
|
-
comments(node)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
220
|
def visit_break(node)
|
221
221
|
node(node, "break") do
|
222
222
|
field("arguments", node.arguments)
|
@@ -315,6 +315,8 @@ module SyntaxTree
|
|
315
315
|
|
316
316
|
def visit_def(node)
|
317
317
|
node(node, "def") do
|
318
|
+
field("target", node.target)
|
319
|
+
field("operator", node.operator)
|
318
320
|
field("name", node.name)
|
319
321
|
field("params", node.params)
|
320
322
|
field("bodystmt", node.bodystmt)
|
@@ -322,20 +324,6 @@ module SyntaxTree
|
|
322
324
|
end
|
323
325
|
end
|
324
326
|
|
325
|
-
def visit_def_endless(node)
|
326
|
-
node(node, "def_endless") do
|
327
|
-
if node.target
|
328
|
-
field("target", node.target)
|
329
|
-
field("operator", node.operator)
|
330
|
-
end
|
331
|
-
|
332
|
-
field("name", node.name)
|
333
|
-
field("paren", node.paren) if node.paren
|
334
|
-
field("statement", node.statement)
|
335
|
-
comments(node)
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
327
|
def visit_defined(node)
|
340
328
|
node(node, "defined") do
|
341
329
|
field("value", node.value)
|
@@ -343,41 +331,6 @@ module SyntaxTree
|
|
343
331
|
end
|
344
332
|
end
|
345
333
|
|
346
|
-
def visit_defs(node)
|
347
|
-
node(node, "defs") do
|
348
|
-
field("target", node.target)
|
349
|
-
field("operator", node.operator)
|
350
|
-
field("name", node.name)
|
351
|
-
field("params", node.params)
|
352
|
-
field("bodystmt", node.bodystmt)
|
353
|
-
comments(node)
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
def visit_do_block(node)
|
358
|
-
node(node, "do_block") do
|
359
|
-
field("block_var", node.block_var) if node.block_var
|
360
|
-
field("bodystmt", node.bodystmt)
|
361
|
-
comments(node)
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
def visit_dot2(node)
|
366
|
-
node(node, "dot2") do
|
367
|
-
field("left", node.left) if node.left
|
368
|
-
field("right", node.right) if node.right
|
369
|
-
comments(node)
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
def visit_dot3(node)
|
374
|
-
node(node, "dot3") do
|
375
|
-
field("left", node.left) if node.left
|
376
|
-
field("right", node.right) if node.right
|
377
|
-
comments(node)
|
378
|
-
end
|
379
|
-
end
|
380
|
-
|
381
334
|
def visit_dyna_symbol(node)
|
382
335
|
node(node, "dyna_symbol") do
|
383
336
|
list("parts", node.parts)
|
@@ -435,14 +388,6 @@ module SyntaxTree
|
|
435
388
|
visit_token(node, "excessed_comma")
|
436
389
|
end
|
437
390
|
|
438
|
-
def visit_fcall(node)
|
439
|
-
node(node, "fcall") do
|
440
|
-
field("value", node.value)
|
441
|
-
field("arguments", node.arguments) if node.arguments
|
442
|
-
comments(node)
|
443
|
-
end
|
444
|
-
end
|
445
|
-
|
446
391
|
def visit_field(node)
|
447
392
|
node(node, "field") do
|
448
393
|
field("parent", node.parent)
|
@@ -523,14 +468,6 @@ module SyntaxTree
|
|
523
468
|
end
|
524
469
|
end
|
525
470
|
|
526
|
-
def visit_if_mod(node)
|
527
|
-
node(node, "if_mod") do
|
528
|
-
field("statement", node.statement)
|
529
|
-
field("predicate", node.predicate)
|
530
|
-
comments(node)
|
531
|
-
end
|
532
|
-
end
|
533
|
-
|
534
471
|
def visit_if_op(node)
|
535
472
|
node(node, "if_op") do
|
536
473
|
field("predicate", node.predicate)
|
@@ -747,6 +684,15 @@ module SyntaxTree
|
|
747
684
|
node(node, "qwords_beg") { field("value", node.value) }
|
748
685
|
end
|
749
686
|
|
687
|
+
def visit_range(node)
|
688
|
+
node(node, "range") do
|
689
|
+
field("left", node.left) if node.left
|
690
|
+
field("operator", node.operator)
|
691
|
+
field("right", node.right) if node.right
|
692
|
+
comments(node)
|
693
|
+
end
|
694
|
+
end
|
695
|
+
|
750
696
|
def visit_rassign(node)
|
751
697
|
node(node, "rassign") do
|
752
698
|
field("value", node.value)
|
@@ -769,7 +715,7 @@ module SyntaxTree
|
|
769
715
|
end
|
770
716
|
|
771
717
|
def visit_redo(node)
|
772
|
-
|
718
|
+
node(node, "redo") { comments(node) }
|
773
719
|
end
|
774
720
|
|
775
721
|
def visit_regexp_beg(node)
|
@@ -825,7 +771,7 @@ module SyntaxTree
|
|
825
771
|
end
|
826
772
|
|
827
773
|
def visit_retry(node)
|
828
|
-
|
774
|
+
node(node, "retry") { comments(node) }
|
829
775
|
end
|
830
776
|
|
831
777
|
def visit_return(node)
|
@@ -835,10 +781,6 @@ module SyntaxTree
|
|
835
781
|
end
|
836
782
|
end
|
837
783
|
|
838
|
-
def visit_return0(node)
|
839
|
-
visit_token(node, "return0")
|
840
|
-
end
|
841
|
-
|
842
784
|
def visit_rparen(node)
|
843
785
|
node(node, "rparen") { field("value", node.value) }
|
844
786
|
end
|
@@ -982,14 +924,6 @@ module SyntaxTree
|
|
982
924
|
end
|
983
925
|
end
|
984
926
|
|
985
|
-
def visit_unless_mod(node)
|
986
|
-
node(node, "unless_mod") do
|
987
|
-
field("statement", node.statement)
|
988
|
-
field("predicate", node.predicate)
|
989
|
-
comments(node)
|
990
|
-
end
|
991
|
-
end
|
992
|
-
|
993
927
|
def visit_until(node)
|
994
928
|
node(node, "until") do
|
995
929
|
field("predicate", node.predicate)
|
@@ -998,22 +932,6 @@ module SyntaxTree
|
|
998
932
|
end
|
999
933
|
end
|
1000
934
|
|
1001
|
-
def visit_until_mod(node)
|
1002
|
-
node(node, "until_mod") do
|
1003
|
-
field("statement", node.statement)
|
1004
|
-
field("predicate", node.predicate)
|
1005
|
-
comments(node)
|
1006
|
-
end
|
1007
|
-
end
|
1008
|
-
|
1009
|
-
def visit_var_alias(node)
|
1010
|
-
node(node, "var_alias") do
|
1011
|
-
field("left", node.left)
|
1012
|
-
field("right", node.right)
|
1013
|
-
comments(node)
|
1014
|
-
end
|
1015
|
-
end
|
1016
|
-
|
1017
935
|
def visit_var_field(node)
|
1018
936
|
node(node, "var_field") do
|
1019
937
|
field("value", node.value)
|
@@ -1056,14 +974,6 @@ module SyntaxTree
|
|
1056
974
|
end
|
1057
975
|
end
|
1058
976
|
|
1059
|
-
def visit_while_mod(node)
|
1060
|
-
node(node, "while_mod") do
|
1061
|
-
field("statement", node.statement)
|
1062
|
-
field("predicate", node.predicate)
|
1063
|
-
comments(node)
|
1064
|
-
end
|
1065
|
-
end
|
1066
|
-
|
1067
977
|
def visit_word(node)
|
1068
978
|
node(node, "word") do
|
1069
979
|
list("parts", node.parts)
|
@@ -1100,12 +1010,8 @@ module SyntaxTree
|
|
1100
1010
|
end
|
1101
1011
|
end
|
1102
1012
|
|
1103
|
-
def visit_yield0(node)
|
1104
|
-
visit_token(node, "yield0")
|
1105
|
-
end
|
1106
|
-
|
1107
1013
|
def visit_zsuper(node)
|
1108
|
-
|
1014
|
+
node(node, "zsuper") { comments(node) }
|
1109
1015
|
end
|
1110
1016
|
|
1111
1017
|
def visit___end__(node)
|