parser 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/.gitignore +0 -1
- data/README.md +4 -2
- data/bin/{parse → ruby-parse} +2 -2
- data/bin/ruby-rewrite +6 -0
- data/{AST_FORMAT.md → doc/AST_FORMAT.md} +45 -29
- data/doc/CUSTOMIZATION.md +37 -0
- data/doc/INTERNALS.md +21 -0
- data/lib/parser.rb +14 -3
- data/lib/parser/ast/node.rb +6 -0
- data/lib/parser/ast/processor.rb +216 -0
- data/lib/parser/builders/default.rb +613 -215
- data/lib/parser/compatibility/slop.rb +12 -0
- data/lib/parser/lexer.rl +30 -10
- data/lib/parser/lexer/explanation.rb +1 -1
- data/lib/parser/lexer/literal.rb +5 -6
- data/lib/parser/ruby18.y +31 -24
- data/lib/parser/ruby19.y +26 -19
- data/lib/parser/ruby20.y +27 -20
- data/lib/parser/ruby21.y +27 -20
- data/lib/parser/runner.rb +198 -0
- data/lib/parser/runner/ruby_parse.rb +87 -0
- data/lib/parser/runner/ruby_rewrite.rb +13 -0
- data/lib/parser/source/buffer.rb +1 -0
- data/lib/parser/source/map.rb +20 -0
- data/lib/parser/source/map/block.rb +16 -0
- data/lib/parser/source/map/collection.rb +16 -0
- data/lib/parser/source/map/condition.rb +19 -0
- data/lib/parser/source/map/constant.rb +27 -0
- data/lib/parser/source/map/definition.rb +21 -0
- data/lib/parser/source/map/for.rb +17 -0
- data/lib/parser/source/map/keyword.rb +18 -0
- data/lib/parser/source/map/rescue_body.rb +19 -0
- data/lib/parser/source/map/send.rb +29 -0
- data/lib/parser/source/map/ternary.rb +16 -0
- data/lib/parser/source/map/variable.rb +26 -0
- data/lib/parser/source/range.rb +25 -24
- data/lib/parser/version.rb +3 -0
- data/parser.gemspec +4 -2
- data/test/parse_helper.rb +13 -10
- data/test/test_lexer.rb +32 -11
- data/test/test_parse_helper.rb +1 -0
- data/test/test_parser.rb +176 -128
- data/test/test_source_range.rb +18 -6
- metadata +161 -91
- data/bin/benchmark +0 -47
- data/bin/explain-parse +0 -14
- data/lib/parser/source/map/variable_assignment.rb +0 -15
data/test/test_parse_helper.rb
CHANGED
@@ -68,6 +68,7 @@ class TestParseHelper < MiniTest::Unit::TestCase
|
|
68
68
|
assert_equal nil, traverse_ast(ast, %w(str))
|
69
69
|
|
70
70
|
assert_equal s(:str, "foo"), traverse_ast(ast, %w(dstr str))
|
71
|
+
assert_equal s(:int, 2), traverse_ast(ast, %w(dstr int))
|
71
72
|
assert_equal s(:int, 2), traverse_ast(ast, %w(dstr int/1))
|
72
73
|
assert_equal s(:int, 3), traverse_ast(ast, %w(dstr int/2))
|
73
74
|
assert_equal nil, traverse_ast(ast, %w(dstr int/3))
|
data/test/test_parser.rb
CHANGED
@@ -107,6 +107,13 @@ class TestParser < MiniTest::Unit::TestCase
|
|
107
107
|
%q{^ begin
|
108
108
|
| ^ end
|
109
109
|
|~~~~~~~~ expression})
|
110
|
+
|
111
|
+
assert_parses(
|
112
|
+
s(:str, 'foobar'),
|
113
|
+
%q{%q(foobar)},
|
114
|
+
%q{^^^ begin
|
115
|
+
| ^ end
|
116
|
+
|~~~~~~~~~~ expression})
|
110
117
|
end
|
111
118
|
|
112
119
|
def test_string_interp
|
@@ -140,12 +147,10 @@ class TestParser < MiniTest::Unit::TestCase
|
|
140
147
|
s(:ivar, :@a)),
|
141
148
|
s(:str, 'bar')),
|
142
149
|
%q{"foo#@a" "bar"},
|
143
|
-
%q{^ begin
|
144
|
-
|^ begin (dstr)
|
150
|
+
%q{^ begin (dstr)
|
145
151
|
| ^ end (dstr)
|
146
152
|
| ^ begin (str)
|
147
153
|
| ^ end (str)
|
148
|
-
| ^ end
|
149
154
|
|~~~~~~~~~~~~~~ expression})
|
150
155
|
end
|
151
156
|
|
@@ -167,7 +172,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
167
172
|
assert_parses(
|
168
173
|
s(:sym, :foo),
|
169
174
|
%q{:'foo'},
|
170
|
-
%q{
|
175
|
+
%q{^^ begin
|
171
176
|
| ^ end
|
172
177
|
|~~~~~~ expression})
|
173
178
|
end
|
@@ -179,9 +184,9 @@ class TestParser < MiniTest::Unit::TestCase
|
|
179
184
|
s(:lvar, :bar),
|
180
185
|
s(:str, 'baz')),
|
181
186
|
%q{:"foo#{bar}baz"},
|
182
|
-
%q{
|
187
|
+
%q{^^ begin
|
183
188
|
| ^ end
|
184
|
-
|
189
|
+
|~~~~~~~~~~~~~~~ expression})
|
185
190
|
end
|
186
191
|
|
187
192
|
def test_symbol_empty
|
@@ -429,8 +434,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
429
434
|
%q[{ foo: 2 }],
|
430
435
|
%q{^ begin
|
431
436
|
| ^ end
|
432
|
-
|
|
433
|
-
| ~~~ expression (pair.sym)
|
437
|
+
| ~~~~ expression (pair.sym)
|
434
438
|
| ~~~~~~ expression (pair)
|
435
439
|
|~~~~~~~~~~ expression},
|
436
440
|
ALL_VERSIONS - %w(1.8))
|
@@ -546,6 +550,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
546
550
|
s(:const, s(:cbase), :Foo),
|
547
551
|
%q{::Foo},
|
548
552
|
%q{ ~~~ name
|
553
|
+
|~~ double_colon
|
549
554
|
|~~~~~ expression})
|
550
555
|
end
|
551
556
|
|
@@ -554,6 +559,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
554
559
|
s(:const, s(:const, nil, :Bar), :Foo),
|
555
560
|
%q{Bar::Foo},
|
556
561
|
%q{ ~~~ name
|
562
|
+
| ~~ double_colon
|
557
563
|
|~~~~~~~~ expression})
|
558
564
|
end
|
559
565
|
|
@@ -715,6 +721,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
715
721
|
%q{::Foo = 10},
|
716
722
|
%q{ ~~~ name
|
717
723
|
| ^ operator
|
724
|
+
|~~ double_colon
|
718
725
|
|~~~~~~~~~~ expression
|
719
726
|
})
|
720
727
|
end
|
@@ -725,6 +732,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
725
732
|
%q{Bar::Foo = 10},
|
726
733
|
%q{ ~~~ name
|
727
734
|
| ^ operator
|
735
|
+
| ~~ double_colon
|
728
736
|
|~~~~~~~~~~~~~ expression
|
729
737
|
})
|
730
738
|
end
|
@@ -775,8 +783,10 @@ class TestParser < MiniTest::Unit::TestCase
|
|
775
783
|
s(:mlhs, s(:lvasgn, :foo), s(:lvasgn, :bar)),
|
776
784
|
s(:array, s(:int, 1), s(:int, 2))),
|
777
785
|
%q{(foo, bar) = 1, 2},
|
778
|
-
%q{^ begin
|
779
|
-
| ^ end
|
786
|
+
%q{^ begin (mlhs)
|
787
|
+
| ^ end (mlhs)
|
788
|
+
|~~~~~~~~~~ expression (mlhs)
|
789
|
+
|~~~~~~~~~~~~~~~~~ expression})
|
780
790
|
|
781
791
|
assert_parses(
|
782
792
|
s(:masgn,
|
@@ -962,7 +972,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
962
972
|
s(:lvasgn, :foo,
|
963
973
|
s(:array, s(:lvar, :bar), s(:int, 1))),
|
964
974
|
%q{foo = bar, 1},
|
965
|
-
%q{ ~~~~~~ array
|
975
|
+
%q{ ~~~~~~ expression (array)
|
966
976
|
|~~~~~~~~~~~~ expression})
|
967
977
|
|
968
978
|
assert_parses(
|
@@ -1367,6 +1377,14 @@ class TestParser < MiniTest::Unit::TestCase
|
|
1367
1377
|
%q{~~~ keyword
|
1368
1378
|
| ~~~ name
|
1369
1379
|
| ~~~ end})
|
1380
|
+
|
1381
|
+
assert_parses(
|
1382
|
+
s(:def, :String, s(:args), s(:nil)),
|
1383
|
+
%q{def String; end})
|
1384
|
+
|
1385
|
+
assert_parses(
|
1386
|
+
s(:def, :String=, s(:args), s(:nil)),
|
1387
|
+
%q{def String=; end})
|
1370
1388
|
end
|
1371
1389
|
|
1372
1390
|
def test_defs
|
@@ -1389,6 +1407,16 @@ class TestParser < MiniTest::Unit::TestCase
|
|
1389
1407
|
assert_parses(
|
1390
1408
|
s(:defs, s(:lvar, :foo), :foo, s(:args), s(:nil)),
|
1391
1409
|
%q{def (foo).foo; end})
|
1410
|
+
|
1411
|
+
assert_parses(
|
1412
|
+
s(:defs, s(:const, nil, :String), :foo,
|
1413
|
+
s(:args), s(:nil)),
|
1414
|
+
%q{def String.foo; end})
|
1415
|
+
|
1416
|
+
assert_parses(
|
1417
|
+
s(:defs, s(:const, nil, :String), :foo,
|
1418
|
+
s(:args), s(:nil)),
|
1419
|
+
%q{def String::foo; end})
|
1392
1420
|
end
|
1393
1421
|
|
1394
1422
|
def test_defs_invalid
|
@@ -1410,7 +1438,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
1410
1438
|
assert_diagnoses(
|
1411
1439
|
[:error, :singleton_literal],
|
1412
1440
|
%q{def (:foo).foo; end},
|
1413
|
-
%q{
|
1441
|
+
%q{ ~~~~ location})
|
1414
1442
|
|
1415
1443
|
assert_diagnoses(
|
1416
1444
|
[:error, :singleton_literal],
|
@@ -1442,8 +1470,8 @@ class TestParser < MiniTest::Unit::TestCase
|
|
1442
1470
|
%q{undef foo, :bar, :"foo#{1}"},
|
1443
1471
|
%q{~~~~~ keyword
|
1444
1472
|
| ~~~ expression (sym/1)
|
1445
|
-
|
|
1446
|
-
|
1473
|
+
| ~~~~ expression (sym/2)
|
1474
|
+
|~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression})
|
1447
1475
|
end
|
1448
1476
|
|
1449
1477
|
#
|
@@ -2700,7 +2728,8 @@ class TestParser < MiniTest::Unit::TestCase
|
|
2700
2728
|
assert_parses(
|
2701
2729
|
s(:send, s(:lvar, :foo), :a=, s(:int, 1)),
|
2702
2730
|
%q{foo.a = 1},
|
2703
|
-
%q{
|
2731
|
+
%q{ ~ selector
|
2732
|
+
| ^ operator
|
2704
2733
|
|~~~~~~~~~ expression})
|
2705
2734
|
|
2706
2735
|
assert_parses(
|
@@ -2722,8 +2751,6 @@ class TestParser < MiniTest::Unit::TestCase
|
|
2722
2751
|
s(:int, 1), s(:int, 2)),
|
2723
2752
|
%q{foo[1, 2]},
|
2724
2753
|
%q{ ~~~~~~ selector
|
2725
|
-
| ^ begin
|
2726
|
-
| ^ end
|
2727
2754
|
|~~~~~~~~~ expression})
|
2728
2755
|
end
|
2729
2756
|
|
@@ -2739,9 +2766,8 @@ class TestParser < MiniTest::Unit::TestCase
|
|
2739
2766
|
s(:send, s(:lvar, :foo), :[]=,
|
2740
2767
|
s(:int, 1), s(:int, 2), s(:int, 3)),
|
2741
2768
|
%q{foo[1, 2] = 3},
|
2742
|
-
%q{
|
2743
|
-
|
|
2744
|
-
| ^ end
|
2769
|
+
%q{ ~~~~~~ selector
|
2770
|
+
| ^ operator
|
2745
2771
|
|~~~~~~~~~~~~~ expression})
|
2746
2772
|
end
|
2747
2773
|
|
@@ -2779,7 +2805,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
2779
2805
|
| ^ end (args)
|
2780
2806
|
| ^ begin
|
2781
2807
|
| ^ end
|
2782
|
-
|
2808
|
+
|~~~~~~~~~ expression},
|
2783
2809
|
ALL_VERSIONS - %w(1.8))
|
2784
2810
|
|
2785
2811
|
assert_parses(
|
@@ -3034,32 +3060,32 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3034
3060
|
def test_space_args_cmd
|
3035
3061
|
assert_parses(
|
3036
3062
|
s(:send, nil, :fun,
|
3037
|
-
s(:send, nil, :f, s(:lvar, :bar))),
|
3063
|
+
s(:begin, s(:send, nil, :f, s(:lvar, :bar)))),
|
3038
3064
|
%q{fun (f bar)})
|
3039
3065
|
end
|
3040
3066
|
|
3041
3067
|
def test_space_args_arg
|
3042
3068
|
assert_parses(
|
3043
|
-
s(:send, nil, :fun, s(:int, 1)),
|
3069
|
+
s(:send, nil, :fun, s(:begin, s(:int, 1))),
|
3044
3070
|
%q{fun (1)})
|
3045
3071
|
end
|
3046
3072
|
|
3047
3073
|
def test_space_args_arg_block
|
3048
3074
|
assert_parses(
|
3049
3075
|
s(:block,
|
3050
|
-
s(:send, nil, :fun, s(:int, 1)),
|
3076
|
+
s(:send, nil, :fun, s(:begin, s(:int, 1))),
|
3051
3077
|
s(:args), s(:nil)),
|
3052
3078
|
%q{fun (1) {}})
|
3053
3079
|
|
3054
3080
|
assert_parses(
|
3055
3081
|
s(:block,
|
3056
|
-
s(:send, s(:lvar, :foo), :fun, s(:int, 1)),
|
3082
|
+
s(:send, s(:lvar, :foo), :fun, s(:begin, s(:int, 1))),
|
3057
3083
|
s(:args), s(:nil)),
|
3058
3084
|
%q{foo.fun (1) {}})
|
3059
3085
|
|
3060
3086
|
assert_parses(
|
3061
3087
|
s(:block,
|
3062
|
-
s(:send, s(:lvar, :foo), :fun, s(:int, 1)),
|
3088
|
+
s(:send, s(:lvar, :foo), :fun, s(:begin, s(:int, 1))),
|
3063
3089
|
s(:args), s(:nil)),
|
3064
3090
|
%q{foo::fun (1) {}})
|
3065
3091
|
end
|
@@ -3067,7 +3093,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3067
3093
|
def test_space_args_arg_call
|
3068
3094
|
assert_parses(
|
3069
3095
|
s(:send, nil, :fun,
|
3070
|
-
s(:send, s(:int, 1), :to_i)),
|
3096
|
+
s(:send, s(:begin, s(:int, 1)), :to_i)),
|
3071
3097
|
%q{fun (1).to_i})
|
3072
3098
|
end
|
3073
3099
|
|
@@ -3461,8 +3487,8 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3461
3487
|
%q{~~ keyword
|
3462
3488
|
| ~~~~~ else
|
3463
3489
|
| ~~~~~ keyword (if)
|
3490
|
+
| ~~~~ else (if)
|
3464
3491
|
| ~~~ end
|
3465
|
-
| ~~~ end (if)
|
3466
3492
|
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression})
|
3467
3493
|
end
|
3468
3494
|
|
@@ -3479,21 +3505,28 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3479
3505
|
assert_diagnoses(
|
3480
3506
|
[:error, :masgn_as_condition],
|
3481
3507
|
%q{if (a, b = foo); end},
|
3482
|
-
%q{
|
3508
|
+
%q{ ~~~~~~~~~~ location})
|
3483
3509
|
end
|
3484
3510
|
|
3485
3511
|
def test_if_mod_masgn
|
3486
3512
|
assert_diagnoses(
|
3487
3513
|
[:error, :masgn_as_condition],
|
3488
3514
|
%q{1 if (a, b = foo)},
|
3489
|
-
%q{
|
3515
|
+
%q{ ~~~~~~~~~~ location})
|
3490
3516
|
end
|
3491
3517
|
|
3492
3518
|
def test_tern_masgn
|
3493
3519
|
assert_diagnoses(
|
3494
3520
|
[:error, :masgn_as_condition],
|
3495
3521
|
%q{(a, b = foo) ? 1 : 2},
|
3496
|
-
%q{
|
3522
|
+
%q{ ~~~~~~~~~~ location})
|
3523
|
+
end
|
3524
|
+
|
3525
|
+
def test_cond_begin_masgn
|
3526
|
+
assert_diagnoses(
|
3527
|
+
[:error, :masgn_as_condition],
|
3528
|
+
%q{if (bar; a, b = foo); end},
|
3529
|
+
%q{ ~~~~~~~~~~ location})
|
3497
3530
|
end
|
3498
3531
|
|
3499
3532
|
# Case matching
|
@@ -3672,14 +3705,14 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3672
3705
|
assert_diagnoses(
|
3673
3706
|
[:error, :masgn_as_condition],
|
3674
3707
|
%q{while (a, b = foo); end},
|
3675
|
-
%q{
|
3708
|
+
%q{ ~~~~~~~~~~ location})
|
3676
3709
|
end
|
3677
3710
|
|
3678
3711
|
def test_while_mod_masgn
|
3679
3712
|
assert_diagnoses(
|
3680
3713
|
[:error, :masgn_as_condition],
|
3681
3714
|
%q{foo while (a, b = foo)},
|
3682
|
-
%q{
|
3715
|
+
%q{ ~~~~~~~~~~ location})
|
3683
3716
|
end
|
3684
3717
|
|
3685
3718
|
def test_for
|
@@ -3719,16 +3752,14 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3719
3752
|
|
3720
3753
|
def test_break
|
3721
3754
|
assert_parses(
|
3722
|
-
s(:break, s(:lvar, :foo)),
|
3755
|
+
s(:break, s(:begin, s(:lvar, :foo))),
|
3723
3756
|
%q{break(foo)},
|
3724
3757
|
%q{~~~~~ keyword
|
3725
|
-
| ^ begin
|
3726
|
-
| ^ end
|
3727
3758
|
|~~~~~~~~~~ expression},
|
3728
3759
|
ALL_VERSIONS - %w(1.8))
|
3729
3760
|
|
3730
3761
|
assert_parses(
|
3731
|
-
s(:break, s(:lvar, :foo)),
|
3762
|
+
s(:break, s(:begin, s(:lvar, :foo))),
|
3732
3763
|
%q{break(foo)},
|
3733
3764
|
%q{~~~~~ keyword
|
3734
3765
|
|~~~~~~~~~~ expression},
|
@@ -3756,16 +3787,14 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3756
3787
|
|
3757
3788
|
def test_return
|
3758
3789
|
assert_parses(
|
3759
|
-
s(:return, s(:lvar, :foo)),
|
3790
|
+
s(:return, s(:begin, s(:lvar, :foo))),
|
3760
3791
|
%q{return(foo)},
|
3761
3792
|
%q{~~~~~~ keyword
|
3762
|
-
| ^ begin
|
3763
|
-
| ^ end
|
3764
3793
|
|~~~~~~~~~~~ expression},
|
3765
3794
|
ALL_VERSIONS - %w(1.8))
|
3766
3795
|
|
3767
3796
|
assert_parses(
|
3768
|
-
s(:return, s(:lvar, :foo)),
|
3797
|
+
s(:return, s(:begin, s(:lvar, :foo))),
|
3769
3798
|
%q{return(foo)},
|
3770
3799
|
%q{~~~~~~ keyword
|
3771
3800
|
|~~~~~~~~~~~ expression},
|
@@ -3793,16 +3822,14 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3793
3822
|
|
3794
3823
|
def test_next
|
3795
3824
|
assert_parses(
|
3796
|
-
s(:next, s(:lvar, :foo)),
|
3825
|
+
s(:next, s(:begin, s(:lvar, :foo))),
|
3797
3826
|
%q{next(foo)},
|
3798
3827
|
%q{~~~~ keyword
|
3799
|
-
| ^ begin
|
3800
|
-
| ^ end
|
3801
3828
|
|~~~~~~~~~ expression},
|
3802
3829
|
ALL_VERSIONS - %w(1.8))
|
3803
3830
|
|
3804
3831
|
assert_parses(
|
3805
|
-
s(:next, s(:lvar, :foo)),
|
3832
|
+
s(:next, s(:begin, s(:lvar, :foo))),
|
3806
3833
|
%q{next(foo)},
|
3807
3834
|
%q{~~~~ keyword
|
3808
3835
|
|~~~~~~~~~ expression},
|
@@ -3840,25 +3867,28 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3840
3867
|
|
3841
3868
|
def test_rescue
|
3842
3869
|
assert_parses(
|
3843
|
-
s(:
|
3844
|
-
s(:
|
3845
|
-
|
3870
|
+
s(:begin,
|
3871
|
+
s(:rescue, s(:send, nil, :meth),
|
3872
|
+
s(:resbody, nil, nil, s(:lvar, :foo)),
|
3873
|
+
nil)),
|
3846
3874
|
%q{begin; meth; rescue; foo; end},
|
3847
3875
|
%q{~~~~~ begin
|
3876
|
+
| ~~~~~~ keyword (rescue.resbody)
|
3877
|
+
| ~~~~~~~~~~~ expression (rescue.resbody)
|
3878
|
+
| ~~~~~~~~~~~~~~~~~ expression (rescue)
|
3848
3879
|
| ~~~ end
|
3849
3880
|
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression})
|
3850
3881
|
end
|
3851
3882
|
|
3852
3883
|
def test_rescue_else
|
3853
3884
|
assert_parses(
|
3854
|
-
s(:
|
3855
|
-
s(:
|
3856
|
-
|
3885
|
+
s(:begin,
|
3886
|
+
s(:rescue, s(:send, nil, :meth),
|
3887
|
+
s(:resbody, nil, nil, s(:lvar, :foo)),
|
3888
|
+
s(:lvar, :bar))),
|
3857
3889
|
%q{begin; meth; rescue; foo; else; bar; end},
|
3858
|
-
%q{
|
3859
|
-
|
|
3860
|
-
| ~~~ end
|
3861
|
-
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression})
|
3890
|
+
%q{ ~~~~ else (rescue)
|
3891
|
+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression (rescue)})
|
3862
3892
|
end
|
3863
3893
|
|
3864
3894
|
def test_rescue_else_useless
|
@@ -3870,52 +3900,61 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3870
3900
|
|
3871
3901
|
def test_ensure
|
3872
3902
|
assert_parses(
|
3873
|
-
s(:
|
3874
|
-
s(:
|
3903
|
+
s(:begin,
|
3904
|
+
s(:ensure, s(:send, nil, :meth),
|
3905
|
+
s(:lvar, :bar))),
|
3875
3906
|
%q{begin; meth; ensure; bar; end},
|
3876
3907
|
%q{~~~~~ begin
|
3877
|
-
| ~~~~~~ keyword
|
3908
|
+
| ~~~~~~ keyword (ensure)
|
3909
|
+
| ~~~~~~~~~~~~~~~~~ expression (ensure)
|
3878
3910
|
| ~~~ end
|
3879
3911
|
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression})
|
3880
3912
|
end
|
3881
3913
|
|
3914
|
+
def test_ensure_empty
|
3915
|
+
assert_parses(
|
3916
|
+
s(:begin,
|
3917
|
+
s(:ensure, s(:nil),
|
3918
|
+
s(:nil))),
|
3919
|
+
%q{begin ensure end},
|
3920
|
+
%q{~~~~~ begin
|
3921
|
+
| ~~~~~~ keyword (ensure)
|
3922
|
+
| ~~~~~~ expression (ensure)
|
3923
|
+
| ~~~ end
|
3924
|
+
|~~~~~~~~~~~~~~~~ expression})
|
3925
|
+
end
|
3926
|
+
|
3882
3927
|
def test_rescue_ensure
|
3883
3928
|
assert_parses(
|
3884
|
-
s(:
|
3885
|
-
s(:
|
3886
|
-
s(:
|
3887
|
-
|
3888
|
-
|
3889
|
-
|
3929
|
+
s(:begin,
|
3930
|
+
s(:ensure,
|
3931
|
+
s(:rescue,
|
3932
|
+
s(:send, nil, :meth),
|
3933
|
+
s(:resbody, nil, nil, s(:lvar, :baz)),
|
3934
|
+
nil),
|
3935
|
+
s(:lvar, :bar))),
|
3890
3936
|
%q{begin; meth; rescue; baz; ensure; bar; end},
|
3891
|
-
%q{
|
3892
|
-
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
| ~~~ end
|
3896
|
-
| ~~~ end (rescue)
|
3897
|
-
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
|
3898
|
-
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression (rescue)})
|
3937
|
+
%q{ ~~~~~~ keyword (ensure)
|
3938
|
+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression (ensure)
|
3939
|
+
| ~~~~~~ keyword (ensure.rescue.resbody)
|
3940
|
+
| ~~~~~~~~~~~~~~~~~ expression (ensure.rescue)})
|
3899
3941
|
end
|
3900
3942
|
|
3901
3943
|
def test_rescue_else_ensure
|
3902
3944
|
assert_parses(
|
3903
|
-
s(:
|
3904
|
-
s(:
|
3905
|
-
s(:
|
3906
|
-
|
3907
|
-
|
3908
|
-
|
3945
|
+
s(:begin,
|
3946
|
+
s(:ensure,
|
3947
|
+
s(:rescue,
|
3948
|
+
s(:send, nil, :meth),
|
3949
|
+
s(:resbody, nil, nil, s(:lvar, :baz)),
|
3950
|
+
s(:lvar, :foo)),
|
3951
|
+
s(:lvar, :bar))),
|
3909
3952
|
%q{begin; meth; rescue; baz; else foo; ensure; bar end},
|
3910
|
-
%q{
|
3911
|
-
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
| ~~~ end
|
3916
|
-
| ~~~ end (rescue)
|
3917
|
-
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
|
3918
|
-
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression (rescue)})
|
3953
|
+
%q{ ~~~~~~ keyword (ensure)
|
3954
|
+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression (ensure)
|
3955
|
+
| ~~~~~~ keyword (ensure.rescue.resbody)
|
3956
|
+
| ~~~~ else (ensure.rescue)
|
3957
|
+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression (ensure.rescue)})
|
3919
3958
|
end
|
3920
3959
|
|
3921
3960
|
def test_rescue_mod
|
@@ -3926,6 +3965,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3926
3965
|
nil),
|
3927
3966
|
%q{meth rescue bar},
|
3928
3967
|
%q{ ~~~~~~ keyword (resbody)
|
3968
|
+
| ~~~~~~~~~~ expression (resbody)
|
3929
3969
|
|~~~~~~~~~~~~~~~ expression})
|
3930
3970
|
end
|
3931
3971
|
|
@@ -3938,6 +3978,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3938
3978
|
nil)),
|
3939
3979
|
%q{foo = meth rescue bar},
|
3940
3980
|
%q{ ~~~~~~ keyword (rescue.resbody)
|
3981
|
+
| ~~~~~~~~~~ expression (rescue.resbody)
|
3941
3982
|
| ~~~~~~~~~~~~~~~ expression (rescue)
|
3942
3983
|
|~~~~~~~~~~~~~~~~~~~~~ expression})
|
3943
3984
|
end
|
@@ -3952,6 +3993,7 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3952
3993
|
nil)),
|
3953
3994
|
%q{foo += meth rescue bar},
|
3954
3995
|
%q{ ~~~~~~ keyword (rescue.resbody)
|
3996
|
+
| ~~~~~~~~~~ expression (rescue.resbody)
|
3955
3997
|
| ~~~~~~~~~~~~~~~ expression (rescue)
|
3956
3998
|
|~~~~~~~~~~~~~~~~~~~~~~ expression},
|
3957
3999
|
ALL_VERSIONS - %w(1.8))
|
@@ -3959,55 +4001,60 @@ class TestParser < MiniTest::Unit::TestCase
|
|
3959
4001
|
|
3960
4002
|
def test_resbody_list
|
3961
4003
|
assert_parses(
|
3962
|
-
s(:
|
3963
|
-
s(:
|
3964
|
-
|
3965
|
-
s(:
|
3966
|
-
|
3967
|
-
|
3968
|
-
|
4004
|
+
s(:begin,
|
4005
|
+
s(:rescue,
|
4006
|
+
s(:send, nil, :meth),
|
4007
|
+
s(:resbody,
|
4008
|
+
s(:array, s(:const, nil, :Exception)),
|
4009
|
+
nil,
|
4010
|
+
s(:lvar, :bar)),
|
4011
|
+
nil)),
|
3969
4012
|
%q{begin; meth; rescue Exception; bar; end})
|
3970
4013
|
end
|
3971
4014
|
|
3972
4015
|
def test_resbody_list_mrhs
|
3973
4016
|
assert_parses(
|
3974
|
-
s(:
|
3975
|
-
s(:
|
3976
|
-
|
3977
|
-
s(:
|
3978
|
-
s(:
|
3979
|
-
|
3980
|
-
|
3981
|
-
|
3982
|
-
|
4017
|
+
s(:begin,
|
4018
|
+
s(:rescue,
|
4019
|
+
s(:send, nil, :meth),
|
4020
|
+
s(:resbody,
|
4021
|
+
s(:array,
|
4022
|
+
s(:const, nil, :Exception),
|
4023
|
+
s(:lvar, :foo)),
|
4024
|
+
nil,
|
4025
|
+
s(:lvar, :bar)),
|
4026
|
+
nil)),
|
3983
4027
|
%q{begin; meth; rescue Exception, foo; bar; end})
|
3984
4028
|
end
|
3985
4029
|
|
3986
4030
|
def test_resbody_var
|
3987
4031
|
assert_parses(
|
3988
|
-
s(:
|
3989
|
-
s(:
|
3990
|
-
|
3991
|
-
|
4032
|
+
s(:begin,
|
4033
|
+
s(:rescue,
|
4034
|
+
s(:send, nil, :meth),
|
4035
|
+
s(:resbody, nil, s(:lvasgn, :ex), s(:lvar, :bar)),
|
4036
|
+
nil)),
|
3992
4037
|
%q{begin; meth; rescue => ex; bar; end})
|
3993
4038
|
|
3994
4039
|
assert_parses(
|
3995
|
-
s(:
|
3996
|
-
s(:
|
3997
|
-
|
3998
|
-
|
4040
|
+
s(:begin,
|
4041
|
+
s(:rescue,
|
4042
|
+
s(:send, nil, :meth),
|
4043
|
+
s(:resbody, nil, s(:ivasgn, :@ex), s(:lvar, :bar)),
|
4044
|
+
nil)),
|
3999
4045
|
%q{begin; meth; rescue => @ex; bar; end})
|
4000
4046
|
end
|
4001
4047
|
|
4002
4048
|
def test_resbody_list_var
|
4003
4049
|
assert_parses(
|
4004
|
-
s(:
|
4005
|
-
s(:
|
4006
|
-
|
4007
|
-
s(:
|
4008
|
-
|
4009
|
-
|
4010
|
-
|
4050
|
+
s(:begin,
|
4051
|
+
s(:rescue,
|
4052
|
+
s(:send, nil, :meth),
|
4053
|
+
s(:resbody,
|
4054
|
+
s(:array, s(:lvar, :foo)),
|
4055
|
+
s(:lvasgn, :ex),
|
4056
|
+
s(:lvar, :bar)),
|
4057
|
+
nil)),
|
4011
4058
|
%q{begin; meth; rescue foo => ex; bar; end})
|
4012
4059
|
end
|
4013
4060
|
|
@@ -4025,9 +4072,9 @@ class TestParser < MiniTest::Unit::TestCase
|
|
4025
4072
|
assert_parses(
|
4026
4073
|
s(:preexe, s(:int, 1)),
|
4027
4074
|
%q{BEGIN { 1 }},
|
4028
|
-
%q{
|
4029
|
-
|
|
4030
|
-
|
4075
|
+
%q{ ^ begin
|
4076
|
+
| ^ end
|
4077
|
+
|~~~~~~~~~~~ expression})
|
4031
4078
|
end
|
4032
4079
|
|
4033
4080
|
def test_preexe_invalid
|
@@ -4043,9 +4090,9 @@ class TestParser < MiniTest::Unit::TestCase
|
|
4043
4090
|
assert_parses(
|
4044
4091
|
s(:postexe, s(:int, 1)),
|
4045
4092
|
%q{END { 1 }},
|
4046
|
-
%q{
|
4047
|
-
|
|
4048
|
-
|
4093
|
+
%q{ ^ begin
|
4094
|
+
| ^ end
|
4095
|
+
|~~~~~~~~~ expression})
|
4049
4096
|
|
4050
4097
|
assert_diagnoses(
|
4051
4098
|
[:warning, :end_in_method],
|
@@ -4060,10 +4107,11 @@ class TestParser < MiniTest::Unit::TestCase
|
|
4060
4107
|
def test_begin_cmdarg
|
4061
4108
|
assert_parses(
|
4062
4109
|
s(:send, nil, :p,
|
4063
|
-
s(:
|
4064
|
-
s(:
|
4065
|
-
|
4066
|
-
|
4110
|
+
s(:begin,
|
4111
|
+
s(:block,
|
4112
|
+
s(:send, s(:int, 1), :times),
|
4113
|
+
s(:args),
|
4114
|
+
s(:int, 1)))),
|
4067
4115
|
%q{p begin 1.times do 1 end end},
|
4068
4116
|
%{},
|
4069
4117
|
ALL_VERSIONS - %w(1.8 1.9))
|