parser 2.5.0.0 → 2.6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +41 -17
- data/CHANGELOG.md +88 -2
- data/README.md +4 -2
- data/Rakefile +2 -1
- data/ci/run_rubocop_specs +14 -0
- data/doc/AST_FORMAT.md +71 -14
- data/lib/parser/all.rb +1 -0
- data/lib/parser/ast/processor.rb +5 -0
- data/lib/parser/base.rb +6 -1
- data/lib/parser/builders/default.rb +90 -15
- data/lib/parser/color.rb +32 -0
- data/lib/parser/context.rb +9 -0
- data/lib/parser/current.rb +16 -7
- data/lib/parser/lexer/dedenter.rb +31 -3
- data/lib/parser/lexer/explanation.rb +6 -6
- data/lib/parser/lexer/literal.rb +13 -1
- data/lib/parser/lexer/stack_state.rb +4 -0
- data/lib/parser/lexer.rb +10180 -9297
- data/lib/parser/lexer.rl +81 -25
- data/lib/parser/macruby.rb +2 -2
- data/lib/parser/macruby.y +2 -2
- data/lib/parser/meta.rb +1 -1
- data/lib/parser/ruby18.rb +2 -2
- data/lib/parser/ruby18.y +2 -2
- data/lib/parser/ruby19.rb +2 -2
- data/lib/parser/ruby19.y +2 -2
- data/lib/parser/ruby20.rb +2 -2
- data/lib/parser/ruby20.y +2 -2
- data/lib/parser/ruby21.rb +2 -2
- data/lib/parser/ruby21.y +2 -2
- data/lib/parser/ruby22.rb +2 -2
- data/lib/parser/ruby22.y +2 -2
- data/lib/parser/ruby23.rb +2 -2
- data/lib/parser/ruby23.y +2 -2
- data/lib/parser/ruby24.rb +1740 -1719
- data/lib/parser/ruby24.y +56 -31
- data/lib/parser/ruby25.rb +3226 -3243
- data/lib/parser/ruby25.y +87 -68
- data/lib/parser/ruby26.rb +6674 -0
- data/lib/parser/ruby26.y +2413 -0
- data/lib/parser/rubymotion.rb +2 -2
- data/lib/parser/rubymotion.y +2 -2
- data/lib/parser/runner/ruby_parse.rb +4 -3
- data/lib/parser/runner.rb +5 -0
- data/lib/parser/source/buffer.rb +5 -3
- data/lib/parser/source/comment/associator.rb +3 -3
- data/lib/parser/source/comment.rb +4 -4
- data/lib/parser/source/map/index.rb +33 -0
- data/lib/parser/source/map.rb +1 -1
- data/lib/parser/source/range.rb +1 -1
- data/lib/parser/source/rewriter.rb +1 -1
- data/lib/parser/source/tree_rewriter.rb +3 -3
- data/lib/parser/version.rb +1 -1
- data/lib/parser.rb +1 -0
- data/parser.gemspec +2 -2
- data/test/helper.rb +13 -2
- data/test/parse_helper.rb +5 -1
- data/test/test_current.rb +2 -0
- data/test/test_encoding.rb +9 -0
- data/test/test_lexer.rb +44 -2
- data/test/test_parser.rb +539 -38
- data/test/test_source_buffer.rb +6 -0
- data/test/test_source_rewriter.rb +1 -1
- data/test/test_source_tree_rewriter.rb +5 -9
- metadata +10 -5
data/test/test_parser.rb
CHANGED
|
@@ -27,6 +27,7 @@ class TestParser < Minitest::Test
|
|
|
27
27
|
SINCE_2_3 = SINCE_2_2 - %w(2.2)
|
|
28
28
|
SINCE_2_4 = SINCE_2_3 - %w(2.3)
|
|
29
29
|
SINCE_2_5 = SINCE_2_4 - %w(2.4)
|
|
30
|
+
SINCE_2_6 = SINCE_2_5 - %w(2.5)
|
|
30
31
|
|
|
31
32
|
# Guidelines for test naming:
|
|
32
33
|
# * Test structure follows structure of AST_FORMAT.md.
|
|
@@ -832,6 +833,24 @@ class TestParser < Minitest::Test
|
|
|
832
833
|
|~~~~~ expression})
|
|
833
834
|
end
|
|
834
835
|
|
|
836
|
+
def test_range_endless
|
|
837
|
+
assert_parses(
|
|
838
|
+
s(:irange,
|
|
839
|
+
s(:int, 1), nil),
|
|
840
|
+
%q{1..},
|
|
841
|
+
%q{~~~ expression
|
|
842
|
+
| ~~ operator},
|
|
843
|
+
SINCE_2_6)
|
|
844
|
+
|
|
845
|
+
assert_parses(
|
|
846
|
+
s(:erange,
|
|
847
|
+
s(:int, 1), nil),
|
|
848
|
+
%q{1...},
|
|
849
|
+
%q{~~~~ expression
|
|
850
|
+
| ~~~ operator},
|
|
851
|
+
SINCE_2_6)
|
|
852
|
+
end
|
|
853
|
+
|
|
835
854
|
#
|
|
836
855
|
# Access
|
|
837
856
|
#
|
|
@@ -924,11 +943,22 @@ class TestParser < Minitest::Test
|
|
|
924
943
|
end
|
|
925
944
|
|
|
926
945
|
def test___ENCODING__
|
|
946
|
+
assert_parses(
|
|
947
|
+
s(:__ENCODING__),
|
|
948
|
+
%q{__ENCODING__},
|
|
949
|
+
%q{~~~~~~~~~~~~ expression},
|
|
950
|
+
SINCE_1_9)
|
|
951
|
+
end
|
|
952
|
+
|
|
953
|
+
def test___ENCODING___legacy_
|
|
954
|
+
Parser::Builders::Default.emit_encoding = false
|
|
927
955
|
assert_parses(
|
|
928
956
|
s(:const, s(:const, nil, :Encoding), :UTF_8),
|
|
929
957
|
%q{__ENCODING__},
|
|
930
958
|
%q{~~~~~~~~~~~~ expression},
|
|
931
959
|
SINCE_1_9)
|
|
960
|
+
ensure
|
|
961
|
+
Parser::Builders::Default.emit_encoding = true
|
|
932
962
|
end
|
|
933
963
|
|
|
934
964
|
# defined?
|
|
@@ -1270,13 +1300,14 @@ class TestParser < Minitest::Test
|
|
|
1270
1300
|
s(:masgn,
|
|
1271
1301
|
s(:mlhs,
|
|
1272
1302
|
s(:send, s(:self), :a=),
|
|
1273
|
-
s(:
|
|
1303
|
+
s(:indexasgn, s(:self), s(:int, 1), s(:int, 2))),
|
|
1274
1304
|
s(:lvar, :foo)),
|
|
1275
1305
|
%q{self.a, self[1, 2] = foo},
|
|
1276
|
-
%q{~~~~~~ expression (mlhs.send
|
|
1277
|
-
| ~ selector (mlhs.send
|
|
1278
|
-
|
|
|
1279
|
-
|
|
|
1306
|
+
%q{~~~~~~ expression (mlhs.send)
|
|
1307
|
+
| ~ selector (mlhs.send)
|
|
1308
|
+
| ^ begin (mlhs.indexasgn)
|
|
1309
|
+
| ^ end (mlhs.indexasgn)
|
|
1310
|
+
| ~~~~~~~~~~ expression (mlhs.indexasgn)})
|
|
1280
1311
|
|
|
1281
1312
|
assert_parses(
|
|
1282
1313
|
s(:masgn,
|
|
@@ -1541,20 +1572,21 @@ class TestParser < Minitest::Test
|
|
|
1541
1572
|
def test_op_asgn_index
|
|
1542
1573
|
assert_parses(
|
|
1543
1574
|
s(:op_asgn,
|
|
1544
|
-
s(:
|
|
1575
|
+
s(:indexasgn, s(:lvar, :foo),
|
|
1545
1576
|
s(:int, 0), s(:int, 1)), :+,
|
|
1546
1577
|
s(:int, 2)),
|
|
1547
1578
|
%q{foo[0, 1] += 2},
|
|
1548
1579
|
%q{ ^^ operator
|
|
1549
|
-
|
|
|
1550
|
-
|
|
1580
|
+
| ^ begin (indexasgn)
|
|
1581
|
+
| ^ end (indexasgn)
|
|
1582
|
+
|~~~~~~~~~ expression (indexasgn)
|
|
1551
1583
|
|~~~~~~~~~~~~~~ expression})
|
|
1552
1584
|
end
|
|
1553
1585
|
|
|
1554
1586
|
def test_op_asgn_index_cmd
|
|
1555
1587
|
assert_parses(
|
|
1556
1588
|
s(:op_asgn,
|
|
1557
|
-
s(:
|
|
1589
|
+
s(:indexasgn, s(:lvar, :foo),
|
|
1558
1590
|
s(:int, 0), s(:int, 1)), :+,
|
|
1559
1591
|
s(:send, nil, :m, s(:lvar, :foo))),
|
|
1560
1592
|
%q{foo[0, 1] += m foo})
|
|
@@ -1610,13 +1642,14 @@ class TestParser < Minitest::Test
|
|
|
1610
1642
|
|
|
1611
1643
|
assert_parses(
|
|
1612
1644
|
s(:or_asgn,
|
|
1613
|
-
s(:
|
|
1645
|
+
s(:indexasgn, s(:lvar, :foo),
|
|
1614
1646
|
s(:int, 0), s(:int, 1)),
|
|
1615
1647
|
s(:int, 2)),
|
|
1616
1648
|
%q{foo[0, 1] ||= 2},
|
|
1617
1649
|
%q{ ^^^ operator
|
|
1618
|
-
|
|
|
1619
|
-
|
|
1650
|
+
| ^ begin (indexasgn)
|
|
1651
|
+
| ^ end (indexasgn)
|
|
1652
|
+
|~~~~~~~~~ expression (indexasgn)
|
|
1620
1653
|
|~~~~~~~~~~~~~~~ expression})
|
|
1621
1654
|
end
|
|
1622
1655
|
|
|
@@ -1633,13 +1666,14 @@ class TestParser < Minitest::Test
|
|
|
1633
1666
|
|
|
1634
1667
|
assert_parses(
|
|
1635
1668
|
s(:and_asgn,
|
|
1636
|
-
s(:
|
|
1669
|
+
s(:indexasgn, s(:lvar, :foo),
|
|
1637
1670
|
s(:int, 0), s(:int, 1)),
|
|
1638
1671
|
s(:int, 2)),
|
|
1639
1672
|
%q{foo[0, 1] &&= 2},
|
|
1640
1673
|
%q{ ^^^ operator
|
|
1641
|
-
|
|
|
1642
|
-
|
|
1674
|
+
| ^ begin (indexasgn)
|
|
1675
|
+
| ^ end (indexasgn)
|
|
1676
|
+
|~~~~~~~~~ expression (indexasgn)
|
|
1643
1677
|
|~~~~~~~~~~~~~~~ expression})
|
|
1644
1678
|
end
|
|
1645
1679
|
|
|
@@ -1789,6 +1823,14 @@ class TestParser < Minitest::Test
|
|
|
1789
1823
|
assert_parses(
|
|
1790
1824
|
s(:def, :until, s(:args), nil),
|
|
1791
1825
|
%q{def until; end})
|
|
1826
|
+
|
|
1827
|
+
assert_parses(
|
|
1828
|
+
s(:def, :BEGIN, s(:args), nil),
|
|
1829
|
+
%q{def BEGIN; end})
|
|
1830
|
+
|
|
1831
|
+
assert_parses(
|
|
1832
|
+
s(:def, :END, s(:args), nil),
|
|
1833
|
+
%q{def END; end})
|
|
1792
1834
|
end
|
|
1793
1835
|
|
|
1794
1836
|
def test_defs
|
|
@@ -2617,6 +2659,7 @@ class TestParser < Minitest::Test
|
|
|
2617
2659
|
s(:arg, :a)),
|
|
2618
2660
|
%q{|a|}
|
|
2619
2661
|
)
|
|
2662
|
+
ensure
|
|
2620
2663
|
Parser::Builders::Default.emit_procarg0 = true
|
|
2621
2664
|
end
|
|
2622
2665
|
|
|
@@ -3346,22 +3389,47 @@ class TestParser < Minitest::Test
|
|
|
3346
3389
|
end
|
|
3347
3390
|
|
|
3348
3391
|
def test_send_index
|
|
3392
|
+
assert_parses(
|
|
3393
|
+
s(:index, s(:lvar, :foo),
|
|
3394
|
+
s(:int, 1), s(:int, 2)),
|
|
3395
|
+
%q{foo[1, 2]},
|
|
3396
|
+
%q{ ^ begin
|
|
3397
|
+
| ^ end
|
|
3398
|
+
|~~~~~~~~~ expression})
|
|
3399
|
+
end
|
|
3400
|
+
|
|
3401
|
+
def test_send_index_legacy
|
|
3402
|
+
Parser::Builders::Default.emit_index = false
|
|
3349
3403
|
assert_parses(
|
|
3350
3404
|
s(:send, s(:lvar, :foo), :[],
|
|
3351
3405
|
s(:int, 1), s(:int, 2)),
|
|
3352
3406
|
%q{foo[1, 2]},
|
|
3353
3407
|
%q{ ~~~~~~ selector
|
|
3354
3408
|
|~~~~~~~~~ expression})
|
|
3409
|
+
ensure
|
|
3410
|
+
Parser::Builders::Default.emit_index = true
|
|
3355
3411
|
end
|
|
3356
3412
|
|
|
3357
3413
|
def test_send_index_cmd
|
|
3358
3414
|
assert_parses(
|
|
3359
|
-
s(:
|
|
3415
|
+
s(:index, s(:lvar, :foo),
|
|
3360
3416
|
s(:send, nil, :m, s(:lvar, :bar))),
|
|
3361
3417
|
%q{foo[m bar]})
|
|
3362
3418
|
end
|
|
3363
3419
|
|
|
3364
3420
|
def test_send_index_asgn
|
|
3421
|
+
assert_parses(
|
|
3422
|
+
s(:indexasgn, s(:lvar, :foo),
|
|
3423
|
+
s(:int, 1), s(:int, 2), s(:int, 3)),
|
|
3424
|
+
%q{foo[1, 2] = 3},
|
|
3425
|
+
%q{ ^ begin
|
|
3426
|
+
| ^ end
|
|
3427
|
+
| ^ operator
|
|
3428
|
+
|~~~~~~~~~~~~~ expression})
|
|
3429
|
+
end
|
|
3430
|
+
|
|
3431
|
+
def test_send_index_asgn_legacy
|
|
3432
|
+
Parser::Builders::Default.emit_index = false
|
|
3365
3433
|
assert_parses(
|
|
3366
3434
|
s(:send, s(:lvar, :foo), :[]=,
|
|
3367
3435
|
s(:int, 1), s(:int, 2), s(:int, 3)),
|
|
@@ -3369,6 +3437,8 @@ class TestParser < Minitest::Test
|
|
|
3369
3437
|
%q{ ~~~~~~ selector
|
|
3370
3438
|
| ^ operator
|
|
3371
3439
|
|~~~~~~~~~~~~~ expression})
|
|
3440
|
+
ensure
|
|
3441
|
+
Parser::Builders::Default.emit_index = true
|
|
3372
3442
|
end
|
|
3373
3443
|
|
|
3374
3444
|
def test_send_lambda
|
|
@@ -3473,6 +3543,7 @@ class TestParser < Minitest::Test
|
|
|
3473
3543
|
| ^ end
|
|
3474
3544
|
|~~~~~ expression},
|
|
3475
3545
|
SINCE_1_9)
|
|
3546
|
+
ensure
|
|
3476
3547
|
Parser::Builders::Default.emit_lambda = true
|
|
3477
3548
|
end
|
|
3478
3549
|
|
|
@@ -3698,7 +3769,7 @@ class TestParser < Minitest::Test
|
|
|
3698
3769
|
|
|
3699
3770
|
def test_args_args_comma
|
|
3700
3771
|
assert_parses(
|
|
3701
|
-
s(:
|
|
3772
|
+
s(:index, s(:lvar, :foo),
|
|
3702
3773
|
s(:lvar, :bar)),
|
|
3703
3774
|
%q{foo[bar,]},
|
|
3704
3775
|
%q{},
|
|
@@ -3739,7 +3810,7 @@ class TestParser < Minitest::Test
|
|
|
3739
3810
|
|
|
3740
3811
|
def test_args_assocs_comma
|
|
3741
3812
|
assert_parses(
|
|
3742
|
-
s(:
|
|
3813
|
+
s(:index, s(:lvar, :foo),
|
|
3743
3814
|
s(:hash, s(:pair, s(:sym, :baz), s(:int, 1)))),
|
|
3744
3815
|
%q{foo[:baz => 1,]},
|
|
3745
3816
|
%q{},
|
|
@@ -3763,7 +3834,7 @@ class TestParser < Minitest::Test
|
|
|
3763
3834
|
|
|
3764
3835
|
def test_args_args_assocs_comma
|
|
3765
3836
|
assert_parses(
|
|
3766
|
-
s(:
|
|
3837
|
+
s(:index, s(:lvar, :foo),
|
|
3767
3838
|
s(:lvar, :bar),
|
|
3768
3839
|
s(:hash, s(:pair, s(:sym, :baz), s(:int, 1)))),
|
|
3769
3840
|
%q{foo[bar, :baz => 1,]},
|
|
@@ -3863,7 +3934,8 @@ class TestParser < Minitest::Test
|
|
|
3863
3934
|
s(:args),
|
|
3864
3935
|
s(:int, 1)),
|
|
3865
3936
|
%q{f 1, {1 => 2} {1}},
|
|
3866
|
-
%q{}
|
|
3937
|
+
%q{},
|
|
3938
|
+
ALL_VERSIONS - SINCE_2_5)
|
|
3867
3939
|
end
|
|
3868
3940
|
|
|
3869
3941
|
def test_space_args_arg_call
|
|
@@ -4888,7 +4960,8 @@ class TestParser < Minitest::Test
|
|
|
4888
4960
|
s(:begin,
|
|
4889
4961
|
s(:int, 2))),
|
|
4890
4962
|
%q{begin; else; 2; end},
|
|
4891
|
-
%q{ ~~~~ begin (begin)}
|
|
4963
|
+
%q{ ~~~~ begin (begin)},
|
|
4964
|
+
ALL_VERSIONS - SINCE_2_6)
|
|
4892
4965
|
|
|
4893
4966
|
assert_parses(
|
|
4894
4967
|
s(:kwbegin,
|
|
@@ -4896,7 +4969,8 @@ class TestParser < Minitest::Test
|
|
|
4896
4969
|
s(:begin,
|
|
4897
4970
|
s(:int, 2))),
|
|
4898
4971
|
%q{begin; 1; else; 2; end},
|
|
4899
|
-
%q{ ~~~~ begin (begin)}
|
|
4972
|
+
%q{ ~~~~ begin (begin)},
|
|
4973
|
+
ALL_VERSIONS - SINCE_2_6)
|
|
4900
4974
|
|
|
4901
4975
|
assert_parses(
|
|
4902
4976
|
s(:kwbegin,
|
|
@@ -4905,12 +4979,20 @@ class TestParser < Minitest::Test
|
|
|
4905
4979
|
s(:begin,
|
|
4906
4980
|
s(:int, 3))),
|
|
4907
4981
|
%q{begin; 1; 2; else; 3; end},
|
|
4908
|
-
%q{ ~~~~ begin (begin)}
|
|
4982
|
+
%q{ ~~~~ begin (begin)},
|
|
4983
|
+
ALL_VERSIONS - SINCE_2_6)
|
|
4909
4984
|
|
|
4910
4985
|
assert_diagnoses(
|
|
4911
4986
|
[:warning, :useless_else],
|
|
4912
4987
|
%q{begin; 1; else; 2; end},
|
|
4913
|
-
%q{ ~~~~ location}
|
|
4988
|
+
%q{ ~~~~ location},
|
|
4989
|
+
ALL_VERSIONS - SINCE_2_6)
|
|
4990
|
+
|
|
4991
|
+
assert_diagnoses(
|
|
4992
|
+
[:error, :useless_else],
|
|
4993
|
+
%q{begin; 1; else; 2; end},
|
|
4994
|
+
%q{ ~~~~ location},
|
|
4995
|
+
SINCE_2_6)
|
|
4914
4996
|
end
|
|
4915
4997
|
|
|
4916
4998
|
def test_ensure
|
|
@@ -5228,7 +5310,7 @@ class TestParser < Minitest::Test
|
|
|
5228
5310
|
def test_bom
|
|
5229
5311
|
assert_parses(
|
|
5230
5312
|
s(:int, 1),
|
|
5231
|
-
%Q{\xef\xbb\xbf1}.
|
|
5313
|
+
%Q{\xef\xbb\xbf1}.b,
|
|
5232
5314
|
%q{},
|
|
5233
5315
|
%w(1.9 2.0 2.1))
|
|
5234
5316
|
end
|
|
@@ -5240,8 +5322,7 @@ class TestParser < Minitest::Test
|
|
|
5240
5322
|
s(:send, nil, :puts, s(:lvar, :"проверка"))),
|
|
5241
5323
|
%Q{# coding:koi8-r
|
|
5242
5324
|
\xd0\xd2\xcf\xd7\xc5\xd2\xcb\xc1 = 42
|
|
5243
|
-
puts \xd0\xd2\xcf\xd7\xc5\xd2\xcb\xc1}.
|
|
5244
|
-
force_encoding(Encoding::BINARY),
|
|
5325
|
+
puts \xd0\xd2\xcf\xd7\xc5\xd2\xcb\xc1}.b,
|
|
5245
5326
|
%q{},
|
|
5246
5327
|
%w(1.9 2.0 2.1))
|
|
5247
5328
|
end
|
|
@@ -5776,8 +5857,8 @@ class TestParser < Minitest::Test
|
|
|
5776
5857
|
|
|
5777
5858
|
assert_parses(
|
|
5778
5859
|
s(:op_asgn,
|
|
5779
|
-
s(:
|
|
5780
|
-
s(:lvar, :foo),
|
|
5860
|
+
s(:indexasgn,
|
|
5861
|
+
s(:lvar, :foo),
|
|
5781
5862
|
s(:int, 0)), :+,
|
|
5782
5863
|
s(:rescue,
|
|
5783
5864
|
s(:send, nil, :raise,
|
|
@@ -5865,8 +5946,8 @@ class TestParser < Minitest::Test
|
|
|
5865
5946
|
|
|
5866
5947
|
assert_parses(
|
|
5867
5948
|
s(:op_asgn,
|
|
5868
|
-
s(:
|
|
5869
|
-
s(:lvar, :foo),
|
|
5949
|
+
s(:indexasgn,
|
|
5950
|
+
s(:lvar, :foo),
|
|
5870
5951
|
s(:int, 0)), :+,
|
|
5871
5952
|
s(:rescue,
|
|
5872
5953
|
s(:send, nil, :raise,
|
|
@@ -6365,9 +6446,9 @@ class TestParser < Minitest::Test
|
|
|
6365
6446
|
|
|
6366
6447
|
def test_context_cmd_brace_block
|
|
6367
6448
|
[
|
|
6368
|
-
'tap
|
|
6369
|
-
'foo.tap
|
|
6370
|
-
'foo::tap
|
|
6449
|
+
'tap foo {',
|
|
6450
|
+
'foo.tap foo {',
|
|
6451
|
+
'foo::tap foo {'
|
|
6371
6452
|
].each do |code|
|
|
6372
6453
|
assert_context([:block], code, ALL_VERSIONS)
|
|
6373
6454
|
end
|
|
@@ -6484,6 +6565,136 @@ class TestParser < Minitest::Test
|
|
|
6484
6565
|
end
|
|
6485
6566
|
end
|
|
6486
6567
|
|
|
6568
|
+
def test_method_definition_in_while_cond
|
|
6569
|
+
assert_parses(
|
|
6570
|
+
s(:while,
|
|
6571
|
+
s(:def, :foo,
|
|
6572
|
+
s(:args),
|
|
6573
|
+
s(:block,
|
|
6574
|
+
s(:send, nil, :tap),
|
|
6575
|
+
s(:args), nil)),
|
|
6576
|
+
s(:break)),
|
|
6577
|
+
%q{while def foo; tap do end; end; break; end},
|
|
6578
|
+
%q{},
|
|
6579
|
+
SINCE_2_5)
|
|
6580
|
+
|
|
6581
|
+
assert_parses(
|
|
6582
|
+
s(:while,
|
|
6583
|
+
s(:defs,
|
|
6584
|
+
s(:self), :foo,
|
|
6585
|
+
s(:args),
|
|
6586
|
+
s(:block,
|
|
6587
|
+
s(:send, nil, :tap),
|
|
6588
|
+
s(:args), nil)),
|
|
6589
|
+
s(:break)),
|
|
6590
|
+
%q{while def self.foo; tap do end; end; break; end},
|
|
6591
|
+
%q{},
|
|
6592
|
+
SINCE_2_5)
|
|
6593
|
+
|
|
6594
|
+
assert_parses(
|
|
6595
|
+
s(:while,
|
|
6596
|
+
s(:def, :foo,
|
|
6597
|
+
s(:args,
|
|
6598
|
+
s(:optarg, :a,
|
|
6599
|
+
s(:block,
|
|
6600
|
+
s(:send, nil, :tap),
|
|
6601
|
+
s(:args), nil))), nil),
|
|
6602
|
+
s(:break)),
|
|
6603
|
+
%q{while def foo a = tap do end; end; break; end},
|
|
6604
|
+
%q{},
|
|
6605
|
+
SINCE_2_5)
|
|
6606
|
+
|
|
6607
|
+
assert_parses(
|
|
6608
|
+
s(:while,
|
|
6609
|
+
s(:defs,
|
|
6610
|
+
s(:self), :foo,
|
|
6611
|
+
s(:args,
|
|
6612
|
+
s(:optarg, :a,
|
|
6613
|
+
s(:block,
|
|
6614
|
+
s(:send, nil, :tap),
|
|
6615
|
+
s(:args), nil))), nil),
|
|
6616
|
+
s(:break)),
|
|
6617
|
+
%q{while def self.foo a = tap do end; end; break; end},
|
|
6618
|
+
%q{},
|
|
6619
|
+
SINCE_2_5)
|
|
6620
|
+
end
|
|
6621
|
+
|
|
6622
|
+
def test_class_definition_in_while_cond
|
|
6623
|
+
assert_parses(
|
|
6624
|
+
s(:while,
|
|
6625
|
+
s(:class,
|
|
6626
|
+
s(:const, nil, :Foo), nil,
|
|
6627
|
+
s(:block,
|
|
6628
|
+
s(:send, nil, :tap),
|
|
6629
|
+
s(:args), nil)),
|
|
6630
|
+
s(:break)),
|
|
6631
|
+
%q{while class Foo; tap do end; end; break; end},
|
|
6632
|
+
%q{},
|
|
6633
|
+
SINCE_2_5)
|
|
6634
|
+
|
|
6635
|
+
assert_parses(
|
|
6636
|
+
s(:while,
|
|
6637
|
+
s(:class,
|
|
6638
|
+
s(:const, nil, :Foo), nil,
|
|
6639
|
+
s(:lvasgn, :a,
|
|
6640
|
+
s(:block,
|
|
6641
|
+
s(:send, nil, :tap),
|
|
6642
|
+
s(:args), nil))),
|
|
6643
|
+
s(:break)),
|
|
6644
|
+
%q{while class Foo a = tap do end; end; break; end},
|
|
6645
|
+
%q{},
|
|
6646
|
+
SINCE_2_5)
|
|
6647
|
+
|
|
6648
|
+
assert_parses(
|
|
6649
|
+
s(:while,
|
|
6650
|
+
s(:sclass,
|
|
6651
|
+
s(:self),
|
|
6652
|
+
s(:block,
|
|
6653
|
+
s(:send, nil, :tap),
|
|
6654
|
+
s(:args), nil)),
|
|
6655
|
+
s(:break)),
|
|
6656
|
+
%q{while class << self; tap do end; end; break; end},
|
|
6657
|
+
%q{},
|
|
6658
|
+
SINCE_2_5)
|
|
6659
|
+
|
|
6660
|
+
assert_parses(
|
|
6661
|
+
s(:while,
|
|
6662
|
+
s(:sclass,
|
|
6663
|
+
s(:self),
|
|
6664
|
+
s(:lvasgn, :a,
|
|
6665
|
+
s(:block,
|
|
6666
|
+
s(:send, nil, :tap),
|
|
6667
|
+
s(:args), nil))),
|
|
6668
|
+
s(:break)),
|
|
6669
|
+
%q{while class << self; a = tap do end; end; break; end},
|
|
6670
|
+
%q{},
|
|
6671
|
+
SINCE_2_5)
|
|
6672
|
+
end
|
|
6673
|
+
|
|
6674
|
+
def test_rescue_in_lambda_block
|
|
6675
|
+
assert_diagnoses(
|
|
6676
|
+
[:error, :unexpected_token, { :token => 'kRESCUE'}],
|
|
6677
|
+
%q{-> do rescue; end},
|
|
6678
|
+
%q{ ~~~~~~ location},
|
|
6679
|
+
SINCE_1_9 - SINCE_2_6)
|
|
6680
|
+
|
|
6681
|
+
assert_parses(
|
|
6682
|
+
s(:block,
|
|
6683
|
+
s(:lambda),
|
|
6684
|
+
s(:args),
|
|
6685
|
+
s(:rescue, nil,
|
|
6686
|
+
s(:resbody, nil, nil, nil), nil)),
|
|
6687
|
+
%q{-> do rescue; end},
|
|
6688
|
+
%q{ ~~~~~~ keyword (rescue.resbody)},
|
|
6689
|
+
SINCE_2_6)
|
|
6690
|
+
|
|
6691
|
+
assert_diagnoses(
|
|
6692
|
+
[:error, :unexpected_token, { :token => 'kRESCUE'}],
|
|
6693
|
+
%q{-> { rescue; }},
|
|
6694
|
+
%q{ ~~~~~~ location},
|
|
6695
|
+
SINCE_1_9)
|
|
6696
|
+
end
|
|
6697
|
+
|
|
6487
6698
|
def test_ruby_bug_13547
|
|
6488
6699
|
assert_diagnoses(
|
|
6489
6700
|
[:error, :unexpected_token, { :token => 'tLCURLY' }],
|
|
@@ -6555,16 +6766,16 @@ class TestParser < Minitest::Test
|
|
|
6555
6766
|
[:error, :unexpected_token, { :token => 'tLCURLY' }],
|
|
6556
6767
|
%q{m [] {}},
|
|
6557
6768
|
%q{ ^ location},
|
|
6558
|
-
|
|
6769
|
+
SINCE_2_5)
|
|
6559
6770
|
|
|
6560
6771
|
assert_parses(
|
|
6561
6772
|
s(:block,
|
|
6562
|
-
s(:
|
|
6563
|
-
s(:send, nil, :meth)
|
|
6773
|
+
s(:index,
|
|
6774
|
+
s(:send, nil, :meth)),
|
|
6564
6775
|
s(:args), nil),
|
|
6565
6776
|
%q{meth[] {}},
|
|
6566
6777
|
%q{},
|
|
6567
|
-
|
|
6778
|
+
SINCE_2_5
|
|
6568
6779
|
)
|
|
6569
6780
|
|
|
6570
6781
|
assert_diagnoses_many(
|
|
@@ -6583,4 +6794,294 @@ class TestParser < Minitest::Test
|
|
|
6583
6794
|
%q{m /foo/x {}},
|
|
6584
6795
|
SINCE_2_4)
|
|
6585
6796
|
end
|
|
6797
|
+
|
|
6798
|
+
def test_bug_447
|
|
6799
|
+
assert_parses(
|
|
6800
|
+
s(:block,
|
|
6801
|
+
s(:send, nil, :m,
|
|
6802
|
+
s(:array)),
|
|
6803
|
+
s(:args), nil),
|
|
6804
|
+
%q{m [] do end},
|
|
6805
|
+
%q{},
|
|
6806
|
+
ALL_VERSIONS)
|
|
6807
|
+
|
|
6808
|
+
assert_parses(
|
|
6809
|
+
s(:block,
|
|
6810
|
+
s(:send, nil, :m,
|
|
6811
|
+
s(:array),
|
|
6812
|
+
s(:int, 1)),
|
|
6813
|
+
s(:args), nil),
|
|
6814
|
+
%q{m [], 1 do end},
|
|
6815
|
+
%q{},
|
|
6816
|
+
ALL_VERSIONS)
|
|
6817
|
+
end
|
|
6818
|
+
|
|
6819
|
+
def test_bug_435
|
|
6820
|
+
assert_parses(
|
|
6821
|
+
s(:dstr,
|
|
6822
|
+
s(:begin,
|
|
6823
|
+
s(:block,
|
|
6824
|
+
s(:lambda),
|
|
6825
|
+
s(:args,
|
|
6826
|
+
s(:arg, :foo)), nil))),
|
|
6827
|
+
%q{"#{-> foo {}}"},
|
|
6828
|
+
%q{},
|
|
6829
|
+
SINCE_1_9)
|
|
6830
|
+
end
|
|
6831
|
+
|
|
6832
|
+
def test_bug_452
|
|
6833
|
+
assert_parses(
|
|
6834
|
+
s(:begin,
|
|
6835
|
+
s(:send, nil, :td,
|
|
6836
|
+
s(:send,
|
|
6837
|
+
s(:begin,
|
|
6838
|
+
s(:int, 1500)), :toString)),
|
|
6839
|
+
s(:block,
|
|
6840
|
+
s(:send,
|
|
6841
|
+
s(:send, nil, :td), :num),
|
|
6842
|
+
s(:args), nil)),
|
|
6843
|
+
%q{td (1_500).toString(); td.num do; end},
|
|
6844
|
+
%q{},
|
|
6845
|
+
ALL_VERSIONS)
|
|
6846
|
+
end
|
|
6847
|
+
|
|
6848
|
+
def test_bug_466
|
|
6849
|
+
assert_parses(
|
|
6850
|
+
s(:block,
|
|
6851
|
+
s(:send, nil, :foo,
|
|
6852
|
+
s(:dstr,
|
|
6853
|
+
s(:begin,
|
|
6854
|
+
s(:send,
|
|
6855
|
+
s(:begin,
|
|
6856
|
+
s(:send,
|
|
6857
|
+
s(:int, 1), :+,
|
|
6858
|
+
s(:int, 1))), :to_i)))),
|
|
6859
|
+
s(:args), nil),
|
|
6860
|
+
%q{foo "#{(1+1).to_i}" do; end},
|
|
6861
|
+
%q{},
|
|
6862
|
+
ALL_VERSIONS)
|
|
6863
|
+
end
|
|
6864
|
+
|
|
6865
|
+
def test_bug_473
|
|
6866
|
+
assert_parses(
|
|
6867
|
+
s(:send, nil, :m,
|
|
6868
|
+
s(:dstr,
|
|
6869
|
+
s(:begin,
|
|
6870
|
+
s(:array)))),
|
|
6871
|
+
%q{m "#{[]}"},
|
|
6872
|
+
%q{},
|
|
6873
|
+
ALL_VERSIONS)
|
|
6874
|
+
end
|
|
6875
|
+
|
|
6876
|
+
def test_bug_480
|
|
6877
|
+
assert_parses(
|
|
6878
|
+
s(:send, nil, :m,
|
|
6879
|
+
s(:dstr,
|
|
6880
|
+
s(:begin),
|
|
6881
|
+
s(:begin,
|
|
6882
|
+
s(:begin)))),
|
|
6883
|
+
%q{m "#{}#{()}"},
|
|
6884
|
+
%q{},
|
|
6885
|
+
ALL_VERSIONS)
|
|
6886
|
+
end
|
|
6887
|
+
|
|
6888
|
+
def test_bug_481
|
|
6889
|
+
assert_parses(
|
|
6890
|
+
s(:begin,
|
|
6891
|
+
s(:send, nil, :m,
|
|
6892
|
+
s(:def, :x,
|
|
6893
|
+
s(:args), nil)),
|
|
6894
|
+
s(:block,
|
|
6895
|
+
s(:send,
|
|
6896
|
+
s(:int, 1), :tap),
|
|
6897
|
+
s(:args), nil)),
|
|
6898
|
+
%q{m def x(); end; 1.tap do end},
|
|
6899
|
+
%q{},
|
|
6900
|
+
ALL_VERSIONS)
|
|
6901
|
+
end
|
|
6902
|
+
|
|
6903
|
+
def test_parser_bug_490
|
|
6904
|
+
assert_parses(
|
|
6905
|
+
s(:def, :m,
|
|
6906
|
+
s(:args),
|
|
6907
|
+
s(:sclass,
|
|
6908
|
+
s(:self),
|
|
6909
|
+
s(:class,
|
|
6910
|
+
s(:const, nil, :C), nil, nil))),
|
|
6911
|
+
%q{def m; class << self; class C; end; end; end},
|
|
6912
|
+
%q{},
|
|
6913
|
+
ALL_VERSIONS)
|
|
6914
|
+
|
|
6915
|
+
assert_parses(
|
|
6916
|
+
s(:def, :m,
|
|
6917
|
+
s(:args),
|
|
6918
|
+
s(:sclass,
|
|
6919
|
+
s(:self),
|
|
6920
|
+
s(:module,
|
|
6921
|
+
s(:const, nil, :M), nil))),
|
|
6922
|
+
%q{def m; class << self; module M; end; end; end},
|
|
6923
|
+
%q{},
|
|
6924
|
+
ALL_VERSIONS)
|
|
6925
|
+
|
|
6926
|
+
assert_parses(
|
|
6927
|
+
s(:def, :m,
|
|
6928
|
+
s(:args),
|
|
6929
|
+
s(:sclass,
|
|
6930
|
+
s(:self),
|
|
6931
|
+
s(:casgn, nil, :A,
|
|
6932
|
+
s(:nil)))),
|
|
6933
|
+
%q{def m; class << self; A = nil; end; end},
|
|
6934
|
+
%q{},
|
|
6935
|
+
ALL_VERSIONS)
|
|
6936
|
+
end
|
|
6937
|
+
|
|
6938
|
+
def test_slash_newline_in_heredocs
|
|
6939
|
+
assert_parses(
|
|
6940
|
+
s(:dstr,
|
|
6941
|
+
s(:str, "1 2\n"),
|
|
6942
|
+
s(:str, "3\n")),
|
|
6943
|
+
%Q{<<~E\n 1 \\\n 2\n 3\nE\n},
|
|
6944
|
+
%q{},
|
|
6945
|
+
SINCE_2_3)
|
|
6946
|
+
|
|
6947
|
+
assert_parses(
|
|
6948
|
+
s(:dstr,
|
|
6949
|
+
s(:str, " 1 2\n"),
|
|
6950
|
+
s(:str, " 3\n")),
|
|
6951
|
+
%Q{<<-E\n 1 \\\n 2\n 3\nE\n},
|
|
6952
|
+
%q{},
|
|
6953
|
+
ALL_VERSIONS)
|
|
6954
|
+
end
|
|
6955
|
+
|
|
6956
|
+
def test_ambiuous_quoted_label_in_ternary_operator
|
|
6957
|
+
assert_parses(
|
|
6958
|
+
s(:if,
|
|
6959
|
+
s(:send, nil, :a),
|
|
6960
|
+
s(:send,
|
|
6961
|
+
s(:send, nil, :b), :&,
|
|
6962
|
+
s(:str, '')),
|
|
6963
|
+
s(:nil)),
|
|
6964
|
+
%q{a ? b & '': nil},
|
|
6965
|
+
%q{},
|
|
6966
|
+
ALL_VERSIONS)
|
|
6967
|
+
|
|
6968
|
+
assert_diagnoses(
|
|
6969
|
+
[:error, :unexpected_token, { :token => 'tLABEL_END' }],
|
|
6970
|
+
%q{a ? b | '': nil},
|
|
6971
|
+
%q{ ^~ location},
|
|
6972
|
+
SINCE_2_2)
|
|
6973
|
+
|
|
6974
|
+
assert_diagnoses(
|
|
6975
|
+
[:error, :unexpected_token, { :token => 'tTILDE' }],
|
|
6976
|
+
%q{a ? b ~ '': nil},
|
|
6977
|
+
%q{ ^ location},
|
|
6978
|
+
SINCE_2_2)
|
|
6979
|
+
|
|
6980
|
+
assert_diagnoses(
|
|
6981
|
+
[:error, :unexpected_token, { :token => 'tBANG' }],
|
|
6982
|
+
%q{a ? b ! '': nil},
|
|
6983
|
+
%q{ ^ location},
|
|
6984
|
+
SINCE_2_2)
|
|
6985
|
+
end
|
|
6986
|
+
|
|
6987
|
+
def test_lbrace_arg_after_command_args
|
|
6988
|
+
assert_parses(
|
|
6989
|
+
s(:block,
|
|
6990
|
+
s(:send, nil, :let,
|
|
6991
|
+
s(:begin,
|
|
6992
|
+
s(:sym, :a))),
|
|
6993
|
+
s(:args),
|
|
6994
|
+
s(:block,
|
|
6995
|
+
s(:send, nil, :m),
|
|
6996
|
+
s(:args), nil)),
|
|
6997
|
+
%q{let (:a) { m do; end }},
|
|
6998
|
+
%q{},
|
|
6999
|
+
ALL_VERSIONS)
|
|
7000
|
+
end
|
|
7001
|
+
|
|
7002
|
+
def test_ruby_bug_14690
|
|
7003
|
+
assert_parses(
|
|
7004
|
+
s(:block,
|
|
7005
|
+
s(:send, nil, :let,
|
|
7006
|
+
s(:begin)),
|
|
7007
|
+
s(:args),
|
|
7008
|
+
s(:block,
|
|
7009
|
+
s(:send, nil, :m,
|
|
7010
|
+
s(:send, nil, :a)),
|
|
7011
|
+
s(:args), nil)),
|
|
7012
|
+
%q{let () { m(a) do; end }},
|
|
7013
|
+
%q{},
|
|
7014
|
+
SINCE_2_0)
|
|
7015
|
+
end
|
|
7016
|
+
|
|
7017
|
+
def test_parser_bug_507
|
|
7018
|
+
assert_parses(
|
|
7019
|
+
s(:lvasgn, :m,
|
|
7020
|
+
s(:block,
|
|
7021
|
+
s(:lambda),
|
|
7022
|
+
s(:args,
|
|
7023
|
+
s(:restarg, :args)), nil)),
|
|
7024
|
+
%q{m = -> *args do end},
|
|
7025
|
+
%q{},
|
|
7026
|
+
SINCE_1_9)
|
|
7027
|
+
end
|
|
7028
|
+
|
|
7029
|
+
def test_parser_bug_518
|
|
7030
|
+
assert_parses(
|
|
7031
|
+
s(:class,
|
|
7032
|
+
s(:const, nil, :A),
|
|
7033
|
+
s(:const, nil, :B), nil),
|
|
7034
|
+
"class A < B\nend",
|
|
7035
|
+
%q{},
|
|
7036
|
+
ALL_VERSIONS)
|
|
7037
|
+
end
|
|
7038
|
+
|
|
7039
|
+
def test_parser_bug_525
|
|
7040
|
+
assert_parses(
|
|
7041
|
+
s(:block,
|
|
7042
|
+
s(:send, nil, :m1,
|
|
7043
|
+
s(:hash,
|
|
7044
|
+
s(:pair,
|
|
7045
|
+
s(:sym, :k),
|
|
7046
|
+
s(:send, nil, :m2)))),
|
|
7047
|
+
s(:args),
|
|
7048
|
+
s(:block,
|
|
7049
|
+
s(:send, nil, :m3),
|
|
7050
|
+
s(:args), nil)),
|
|
7051
|
+
'm1 :k => m2 do; m3() do end; end',
|
|
7052
|
+
%q{},
|
|
7053
|
+
ALL_VERSIONS)
|
|
7054
|
+
end
|
|
7055
|
+
|
|
7056
|
+
def test_parser_slash_slash_n_escaping_in_literals
|
|
7057
|
+
[
|
|
7058
|
+
["'", "'", s(:dstr, s(:str, "a\\\n"), s(:str, "b")) ],
|
|
7059
|
+
["<<-'HERE'\n", "\nHERE", s(:dstr, s(:str, "a\\\n"), s(:str, "b\n"))],
|
|
7060
|
+
["%q{", "}", s(:dstr, s(:str, "a\\\n"), s(:str, "b")) ],
|
|
7061
|
+
['"', '"', s(:str, "ab") ],
|
|
7062
|
+
["<<-\"HERE\"\n", "\nHERE", s(:str, "ab\n") ],
|
|
7063
|
+
["%{", "}", s(:str, "ab") ],
|
|
7064
|
+
["%Q{", "}", s(:str, "ab") ],
|
|
7065
|
+
["%w{", "}", s(:array, s(:str, "a\nb")) ],
|
|
7066
|
+
["%W{", "}", s(:array, s(:str, "a\nb")) ],
|
|
7067
|
+
["%i{", "}", s(:array, s(:sym, :"a\nb")) ],
|
|
7068
|
+
["%I{", "}", s(:array, s(:sym, :"a\nb")) ],
|
|
7069
|
+
[":'", "'", s(:dsym, s(:str, "a\\\n"), s(:str, "b")) ],
|
|
7070
|
+
["%s{", "}", s(:dsym, s(:str, "a\\\n"), s(:str, "b")) ],
|
|
7071
|
+
[':"', '"', s(:sym, :ab) ],
|
|
7072
|
+
['/', '/', s(:regexp, s(:str, "ab"), s(:regopt)) ],
|
|
7073
|
+
['%r{', '}', s(:regexp, s(:str, "ab"), s(:regopt)) ],
|
|
7074
|
+
['%x{', '}', s(:xstr, s(:str, "ab")) ],
|
|
7075
|
+
['`', '`', s(:xstr, s(:str, "ab")) ],
|
|
7076
|
+
["<<-`HERE`\n", "\nHERE", s(:xstr, s(:str, "ab\n")) ],
|
|
7077
|
+
].each do |literal_s, literal_e, expected|
|
|
7078
|
+
source = literal_s + "a\\\nb" + literal_e
|
|
7079
|
+
|
|
7080
|
+
assert_parses(
|
|
7081
|
+
expected,
|
|
7082
|
+
source,
|
|
7083
|
+
%q{},
|
|
7084
|
+
SINCE_2_0)
|
|
7085
|
+
end
|
|
7086
|
+
end
|
|
6586
7087
|
end
|