parser 2.0.0.beta6 → 2.0.0.beta7
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 +4 -4
- data/.rubocop.yml +15 -0
- data/CHANGELOG.md +12 -0
- data/README.md +1 -1
- data/Rakefile +15 -0
- data/lib/parser.rb +39 -39
- data/lib/parser/base.rb +2 -5
- data/lib/parser/builders/default.rb +25 -5
- data/lib/parser/lexer/explanation.rb +1 -1
- data/lib/parser/ruby18.y +4 -9
- data/lib/parser/ruby19.y +4 -9
- data/lib/parser/ruby20.y +4 -9
- data/lib/parser/ruby21.y +4 -9
- data/lib/parser/runner.rb +7 -2
- data/lib/parser/runner/ruby_parse.rb +3 -3
- data/lib/parser/runner/ruby_rewrite.rb +1 -1
- data/lib/parser/source/buffer.rb +11 -9
- data/lib/parser/source/rewriter.rb +1 -1
- data/lib/parser/source/rewriter/action.rb +2 -2
- data/lib/parser/version.rb +1 -1
- data/test/helper.rb +2 -2
- data/test/parse_helper.rb +5 -5
- data/test/test_diagnostic.rb +7 -7
- data/test/test_diagnostic_engine.rb +5 -5
- data/test/test_encoding.rb +7 -7
- data/test/test_lexer.rb +2 -2
- data/test/test_parse_helper.rb +2 -2
- data/test/test_parser.rb +89 -56
- data/test/test_source_buffer.rb +6 -6
- data/test/test_source_range.rb +3 -3
- data/test/test_source_rewriter.rb +1 -1
- data/test/test_source_rewriter_action.rb +8 -8
- metadata +2 -2
@@ -11,15 +11,15 @@ module Parser
|
|
11
11
|
p node
|
12
12
|
|
13
13
|
source_line_no = nil
|
14
|
-
source_line =
|
15
|
-
hilight_line =
|
14
|
+
source_line = ''
|
15
|
+
hilight_line = ''
|
16
16
|
|
17
17
|
print_line = lambda do
|
18
18
|
unless hilight_line.empty?
|
19
19
|
puts hilight_line.
|
20
20
|
gsub(/[a-z_]+/) { |m| "\e[1;33m#{m}\e[0m" }.
|
21
21
|
gsub(/[~.]+/) { |m| "\e[1;35m#{m}\e[0m" }
|
22
|
-
hilight_line =
|
22
|
+
hilight_line = ''
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
data/lib/parser/source/buffer.rb
CHANGED
@@ -7,7 +7,7 @@ module Parser
|
|
7
7
|
attr_reader :name, :first_line
|
8
8
|
|
9
9
|
def self.recognize_encoding(string)
|
10
|
-
return
|
10
|
+
return if string.empty?
|
11
11
|
|
12
12
|
# extract the first two lines in an efficient way
|
13
13
|
string =~ /(.*)\n?(.*\n)?/
|
@@ -28,7 +28,7 @@ module Parser
|
|
28
28
|
if encoding_line =~ /^#.*coding\s*[:=]\s*([A-Za-z0-9_-]+)/
|
29
29
|
Encoding.find($1)
|
30
30
|
else
|
31
|
-
|
31
|
+
nil
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -39,13 +39,15 @@ module Parser
|
|
39
39
|
def self.reencode_string(string)
|
40
40
|
encoding = recognize_encoding(string)
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
if encoding.nil?
|
43
|
+
string
|
44
|
+
elsif encoding == Encoding::BINARY
|
45
|
+
string.force_encoding(Encoding::BINARY)
|
46
|
+
else
|
47
|
+
string.
|
48
|
+
force_encoding(encoding).
|
49
|
+
encode(Encoding::UTF_8)
|
44
50
|
end
|
45
|
-
|
46
|
-
string.
|
47
|
-
force_encoding(encoding).
|
48
|
-
encode(Encoding::UTF_8)
|
49
51
|
end
|
50
52
|
|
51
53
|
def initialize(name, first_line = 1)
|
@@ -75,7 +77,7 @@ module Parser
|
|
75
77
|
|
76
78
|
def source=(source)
|
77
79
|
if @source
|
78
|
-
raise ArgumentError,
|
80
|
+
raise ArgumentError, 'Source::Buffer is immutable'
|
79
81
|
end
|
80
82
|
|
81
83
|
if source.respond_to? :encoding
|
@@ -4,7 +4,7 @@ module Parser
|
|
4
4
|
class Rewriter::Action
|
5
5
|
attr_reader :range, :replacement
|
6
6
|
|
7
|
-
def initialize(range, replacement=
|
7
|
+
def initialize(range, replacement='')
|
8
8
|
@range, @replacement = range, replacement
|
9
9
|
|
10
10
|
freeze
|
@@ -12,7 +12,7 @@ module Parser
|
|
12
12
|
|
13
13
|
def to_s
|
14
14
|
if @range.length == 0 && @replacement.empty?
|
15
|
-
|
15
|
+
'do nothing'
|
16
16
|
elsif @range.length == 0
|
17
17
|
"insert #{@replacement.inspect}"
|
18
18
|
elsif @replacement.empty?
|
data/lib/parser/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -23,12 +23,12 @@ if SimpleCov.usable?
|
|
23
23
|
Coveralls::SimpleCov::Formatter
|
24
24
|
]
|
25
25
|
|
26
|
-
add_group
|
26
|
+
add_group 'Grammars' do |source_file|
|
27
27
|
source_file.filename =~ %r{\.y$}
|
28
28
|
end
|
29
29
|
|
30
30
|
# Exclude the testsuite itself.
|
31
|
-
add_filter
|
31
|
+
add_filter '/test/'
|
32
32
|
|
33
33
|
# Exclude generated files.
|
34
34
|
add_filter do |source_file|
|
data/test/parse_helper.rb
CHANGED
@@ -20,10 +20,10 @@ module ParseHelper
|
|
20
20
|
|
21
21
|
def parser_for_ruby_version(version)
|
22
22
|
case version
|
23
|
-
when '1.8'
|
24
|
-
when '1.9'
|
25
|
-
when '2.0'
|
26
|
-
when '2.1'
|
23
|
+
when '1.8' then parser = Parser::Ruby18.new
|
24
|
+
when '1.9' then parser = Parser::Ruby19.new
|
25
|
+
when '2.0' then parser = Parser::Ruby20.new
|
26
|
+
when '2.1' then parser = Parser::Ruby21.new
|
27
27
|
else raise "Unrecognized Ruby version #{version}"
|
28
28
|
end
|
29
29
|
|
@@ -143,7 +143,7 @@ module ParseHelper
|
|
143
143
|
when 'location'
|
144
144
|
assert_source_range begin_pos, end_pos,
|
145
145
|
emitted_diagnostic.location,
|
146
|
-
version,
|
146
|
+
version, 'location'
|
147
147
|
|
148
148
|
when 'highlights'
|
149
149
|
index = ast_path.first.to_i
|
data/test/test_diagnostic.rb
CHANGED
@@ -3,7 +3,7 @@ require 'helper'
|
|
3
3
|
class TestDiagnostic < Minitest::Test
|
4
4
|
def setup
|
5
5
|
@buffer = Parser::Source::Buffer.new('(string)')
|
6
|
-
@buffer.source =
|
6
|
+
@buffer.source = 'if (this is some bad code + bugs)'
|
7
7
|
|
8
8
|
@range1 = Parser::Source::Range.new(@buffer, 0, 2) # if
|
9
9
|
@range2 = Parser::Source::Range.new(@buffer, 4, 8) # this
|
@@ -11,12 +11,12 @@ class TestDiagnostic < Minitest::Test
|
|
11
11
|
|
12
12
|
def test_verifies_levels
|
13
13
|
assert_raises ArgumentError, /level/ do
|
14
|
-
Parser::Diagnostic.new(:foobar,
|
14
|
+
Parser::Diagnostic.new(:foobar, 'foo', @range1)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_freezes
|
19
|
-
string =
|
19
|
+
string = 'foo'
|
20
20
|
highlights = [@range2]
|
21
21
|
|
22
22
|
diag = Parser::Diagnostic.new(:error, string, @range1, highlights)
|
@@ -36,12 +36,12 @@ class TestDiagnostic < Minitest::Test
|
|
36
36
|
Parser::Source::Range.new(@buffer, 28, 32)
|
37
37
|
]
|
38
38
|
|
39
|
-
diag = Parser::Diagnostic.new(:error,
|
39
|
+
diag = Parser::Diagnostic.new(:error, 'code far too bad',
|
40
40
|
location, highlights)
|
41
41
|
assert_equal([
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
'(string):1:27: error: code far too bad',
|
43
|
+
'if (this is some bad code + bugs)',
|
44
|
+
' ~~~~ ^ ~~~~ '
|
45
45
|
], diag.render)
|
46
46
|
end
|
47
47
|
end
|
@@ -12,7 +12,7 @@ class TestDiagnosticEngine < Minitest::Test
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_process_warnings
|
15
|
-
warn = Parser::Diagnostic.new(:warning,
|
15
|
+
warn = Parser::Diagnostic.new(:warning, 'foo', @buffer, 1..2)
|
16
16
|
@engine.process(warn)
|
17
17
|
|
18
18
|
assert_equal [warn], @queue
|
@@ -21,7 +21,7 @@ class TestDiagnosticEngine < Minitest::Test
|
|
21
21
|
def test_ignore_warnings
|
22
22
|
@engine.ignore_warnings = true
|
23
23
|
|
24
|
-
warn = Parser::Diagnostic.new(:warning,
|
24
|
+
warn = Parser::Diagnostic.new(:warning, 'foo', @buffer, 1..2)
|
25
25
|
@engine.process(warn)
|
26
26
|
|
27
27
|
assert_equal [], @queue
|
@@ -30,7 +30,7 @@ class TestDiagnosticEngine < Minitest::Test
|
|
30
30
|
def test_all_errors_are_fatal
|
31
31
|
@engine.all_errors_are_fatal = true
|
32
32
|
|
33
|
-
error = Parser::Diagnostic.new(:error,
|
33
|
+
error = Parser::Diagnostic.new(:error, 'foo', @buffer, 1..2)
|
34
34
|
|
35
35
|
assert_raises Parser::SyntaxError do
|
36
36
|
@engine.process(error)
|
@@ -40,14 +40,14 @@ class TestDiagnosticEngine < Minitest::Test
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_all_errors_are_collected
|
43
|
-
error = Parser::Diagnostic.new(:error,
|
43
|
+
error = Parser::Diagnostic.new(:error, 'foo', @buffer, 1..2)
|
44
44
|
@engine.process(error)
|
45
45
|
|
46
46
|
assert_equal [error], @queue
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_fatal_error
|
50
|
-
fatal = Parser::Diagnostic.new(:fatal,
|
50
|
+
fatal = Parser::Diagnostic.new(:fatal, 'foo', @buffer, 1..2)
|
51
51
|
|
52
52
|
assert_raises Parser::SyntaxError do
|
53
53
|
@engine.process(fatal)
|
data/test/test_encoding.rb
CHANGED
@@ -9,7 +9,7 @@ class TestEncoding < Minitest::Test
|
|
9
9
|
|
10
10
|
if defined?(Encoding)
|
11
11
|
def test_default
|
12
|
-
assert_equal
|
12
|
+
assert_equal nil, recognize('foobar')
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_bom
|
@@ -26,24 +26,24 @@ class TestEncoding < Minitest::Test
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_case
|
29
|
-
assert_equal Encoding::KOI8_R, recognize("
|
29
|
+
assert_equal Encoding::KOI8_R, recognize("# coding:KoI8-r\nfoobar")
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_space
|
33
|
-
assert_equal Encoding::KOI8_R, recognize("
|
33
|
+
assert_equal Encoding::KOI8_R, recognize("# coding : koi8-r\nfoobar")
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_empty
|
37
|
-
assert_equal
|
37
|
+
assert_equal nil, recognize('')
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_no_comment
|
41
|
-
assert_equal
|
41
|
+
assert_equal nil, recognize(%{require 'cane/encoding_aware_iterator'})
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_adjacent
|
45
|
-
assert_equal
|
46
|
-
assert_equal
|
45
|
+
assert_equal nil, recognize('# codingkoi8-r')
|
46
|
+
assert_equal nil, recognize('# coding koi8-r')
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
data/test/test_lexer.rb
CHANGED
@@ -2417,14 +2417,14 @@ class TestLexer < Minitest::Test
|
|
2417
2417
|
def test_bug_expr_beg_document
|
2418
2418
|
@lex.state = :expr_beg
|
2419
2419
|
util_lex_token(" \n=begin\n=end\nend",
|
2420
|
-
:kEND,
|
2420
|
+
:kEND, "end")
|
2421
2421
|
|
2422
2422
|
end
|
2423
2423
|
|
2424
2424
|
def test_bug_expr_beg_number
|
2425
2425
|
@lex.state = :expr_beg
|
2426
2426
|
util_lex_token("86400_000_000",
|
2427
|
-
:tINTEGER,
|
2427
|
+
:tINTEGER, 86400_000_000)
|
2428
2428
|
end
|
2429
2429
|
|
2430
2430
|
def test_bug_expr_beg_backspace_nl
|
data/test/test_parse_helper.rb
CHANGED
@@ -58,7 +58,7 @@ class TestParseHelper < Minitest::Test
|
|
58
58
|
ast = s(:send,
|
59
59
|
s(:int, 1), :+,
|
60
60
|
s(:dstr,
|
61
|
-
s(:str,
|
61
|
+
s(:str, 'foo'),
|
62
62
|
s(:int, 2),
|
63
63
|
s(:int, 3)))
|
64
64
|
|
@@ -67,7 +67,7 @@ class TestParseHelper < Minitest::Test
|
|
67
67
|
assert_equal s(:int, 1), traverse_ast(ast, %w(int))
|
68
68
|
assert_equal nil, traverse_ast(ast, %w(str))
|
69
69
|
|
70
|
-
assert_equal s(:str,
|
70
|
+
assert_equal s(:str, 'foo'), traverse_ast(ast, %w(dstr str))
|
71
71
|
assert_equal s(:int, 2), traverse_ast(ast, %w(dstr int))
|
72
72
|
assert_equal s(:int, 2), traverse_ast(ast, %w(dstr int/1))
|
73
73
|
assert_equal s(:int, 3), traverse_ast(ast, %w(dstr int/2))
|
data/test/test_parser.rb
CHANGED
@@ -53,6 +53,22 @@ class TestParser < Minitest::Test
|
|
53
53
|
%q{~~~ expression})
|
54
54
|
end
|
55
55
|
|
56
|
+
def test_nil_expression
|
57
|
+
assert_parses(
|
58
|
+
s(:begin),
|
59
|
+
%q{()},
|
60
|
+
%q{^ begin
|
61
|
+
| ^ end
|
62
|
+
|~~ expression})
|
63
|
+
|
64
|
+
assert_parses(
|
65
|
+
s(:kwbegin),
|
66
|
+
%q{begin end},
|
67
|
+
%q{~~~~~ begin
|
68
|
+
| ~~~ end
|
69
|
+
|~~~~~~~~~ expression})
|
70
|
+
end
|
71
|
+
|
56
72
|
def test_true
|
57
73
|
assert_parses(
|
58
74
|
s(:true),
|
@@ -325,7 +341,7 @@ class TestParser < Minitest::Test
|
|
325
341
|
|
326
342
|
def test_array_words
|
327
343
|
assert_parses(
|
328
|
-
s(:array, s(:str,
|
344
|
+
s(:array, s(:str, 'foo'), s(:str, 'bar')),
|
329
345
|
%q{%w[foo bar]},
|
330
346
|
%q{^^^ begin
|
331
347
|
| ^ end
|
@@ -336,7 +352,7 @@ class TestParser < Minitest::Test
|
|
336
352
|
def test_array_words_interp
|
337
353
|
assert_parses(
|
338
354
|
s(:array,
|
339
|
-
s(:str,
|
355
|
+
s(:str, 'foo'),
|
340
356
|
s(:dstr, s(:begin, s(:lvar, :bar)))),
|
341
357
|
%q{%W[foo #{bar}]},
|
342
358
|
%q{^^^ begin
|
@@ -350,7 +366,7 @@ class TestParser < Minitest::Test
|
|
350
366
|
|
351
367
|
assert_parses(
|
352
368
|
s(:array,
|
353
|
-
s(:str,
|
369
|
+
s(:str, 'foo'),
|
354
370
|
s(:dstr,
|
355
371
|
s(:begin, s(:lvar, :bar)),
|
356
372
|
s(:str, 'foo'),
|
@@ -401,7 +417,7 @@ class TestParser < Minitest::Test
|
|
401
417
|
assert_parses(
|
402
418
|
s(:array,
|
403
419
|
s(:dsym,
|
404
|
-
s(:str,
|
420
|
+
s(:str, 'foo'),
|
405
421
|
s(:begin, s(:lvar, :bar)))),
|
406
422
|
%q{%I[foo#{bar}]},
|
407
423
|
%q{},
|
@@ -1490,7 +1506,7 @@ class TestParser < Minitest::Test
|
|
1490
1506
|
s(:undef,
|
1491
1507
|
s(:sym, :foo),
|
1492
1508
|
s(:sym, :bar),
|
1493
|
-
s(:dsym, s(:str,
|
1509
|
+
s(:dsym, s(:str, 'foo'), s(:begin, s(:int, 1)))),
|
1494
1510
|
%q{undef foo, :bar, :"foo#{1}"},
|
1495
1511
|
%q{~~~~~ keyword
|
1496
1512
|
| ~~~ expression (sym/1)
|
@@ -1539,8 +1555,8 @@ class TestParser < Minitest::Test
|
|
1539
1555
|
assert_parses(
|
1540
1556
|
s(:def, :f,
|
1541
1557
|
s(:args, s(:arg, :foo)),
|
1542
|
-
|
1543
|
-
%q{def f(foo);
|
1558
|
+
nil),
|
1559
|
+
%q{def f(foo); end},
|
1544
1560
|
%q{ ~~~ name (args.arg)
|
1545
1561
|
| ~~~ expression (args.arg)
|
1546
1562
|
| ^ begin (args)
|
@@ -1550,16 +1566,16 @@ class TestParser < Minitest::Test
|
|
1550
1566
|
assert_parses(
|
1551
1567
|
s(:def, :f,
|
1552
1568
|
s(:args, s(:arg, :foo), s(:arg, :bar)),
|
1553
|
-
|
1554
|
-
%q{def f(foo, bar);
|
1569
|
+
nil),
|
1570
|
+
%q{def f(foo, bar); end})
|
1555
1571
|
end
|
1556
1572
|
|
1557
1573
|
def test_optarg
|
1558
1574
|
assert_parses(
|
1559
1575
|
s(:def, :f,
|
1560
1576
|
s(:args, s(:optarg, :foo, s(:int, 1))),
|
1561
|
-
|
1562
|
-
%q{def f foo = 1;
|
1577
|
+
nil),
|
1578
|
+
%q{def f foo = 1; end},
|
1563
1579
|
%q{ ~~~ name (args.optarg)
|
1564
1580
|
| ^ operator (args.optarg)
|
1565
1581
|
| ~~~~~~~ expression (args.optarg)
|
@@ -1570,16 +1586,16 @@ class TestParser < Minitest::Test
|
|
1570
1586
|
s(:args,
|
1571
1587
|
s(:optarg, :foo, s(:int, 1)),
|
1572
1588
|
s(:optarg, :bar, s(:int, 2))),
|
1573
|
-
|
1574
|
-
%q{def f(foo=1, bar=2);
|
1589
|
+
nil),
|
1590
|
+
%q{def f(foo=1, bar=2); end})
|
1575
1591
|
end
|
1576
1592
|
|
1577
1593
|
def test_restarg_named
|
1578
1594
|
assert_parses(
|
1579
1595
|
s(:def, :f,
|
1580
1596
|
s(:args, s(:restarg, :foo)),
|
1581
|
-
|
1582
|
-
%q{def f(*foo);
|
1597
|
+
nil),
|
1598
|
+
%q{def f(*foo); end},
|
1583
1599
|
%q{ ~~~ name (args.restarg)
|
1584
1600
|
| ~~~~ expression (args.restarg)})
|
1585
1601
|
end
|
@@ -1588,8 +1604,8 @@ class TestParser < Minitest::Test
|
|
1588
1604
|
assert_parses(
|
1589
1605
|
s(:def, :f,
|
1590
1606
|
s(:args, s(:restarg)),
|
1591
|
-
|
1592
|
-
%q{def f(*);
|
1607
|
+
nil),
|
1608
|
+
%q{def f(*); end},
|
1593
1609
|
%q{ ~ expression (args.restarg)})
|
1594
1610
|
end
|
1595
1611
|
|
@@ -1597,8 +1613,8 @@ class TestParser < Minitest::Test
|
|
1597
1613
|
assert_parses(
|
1598
1614
|
s(:def, :f,
|
1599
1615
|
s(:args, s(:kwarg, :foo)),
|
1600
|
-
|
1601
|
-
%q{def f(foo:);
|
1616
|
+
nil),
|
1617
|
+
%q{def f(foo:); end},
|
1602
1618
|
%q{ ~~~ name (args.kwarg)
|
1603
1619
|
| ~~~~ expression (args.kwarg)},
|
1604
1620
|
ALL_VERSIONS - %w(1.8 1.9 2.0))
|
@@ -1608,8 +1624,8 @@ class TestParser < Minitest::Test
|
|
1608
1624
|
assert_parses(
|
1609
1625
|
s(:def, :f,
|
1610
1626
|
s(:args, s(:kwoptarg, :foo, s(:int, 1))),
|
1611
|
-
|
1612
|
-
%q{def f(foo: 1);
|
1627
|
+
nil),
|
1628
|
+
%q{def f(foo: 1); end},
|
1613
1629
|
%q{ ~~~ name (args.kwoptarg)
|
1614
1630
|
| ~~~~~~ expression (args.kwoptarg)},
|
1615
1631
|
ALL_VERSIONS - %w(1.8 1.9))
|
@@ -1619,8 +1635,8 @@ class TestParser < Minitest::Test
|
|
1619
1635
|
assert_parses(
|
1620
1636
|
s(:def, :f,
|
1621
1637
|
s(:args, s(:kwrestarg, :foo)),
|
1622
|
-
|
1623
|
-
%q{def f(**foo);
|
1638
|
+
nil),
|
1639
|
+
%q{def f(**foo); end},
|
1624
1640
|
%q{ ~~~ name (args.kwrestarg)
|
1625
1641
|
| ~~~~~ expression (args.kwrestarg)},
|
1626
1642
|
ALL_VERSIONS - %w(1.8 1.9))
|
@@ -1630,8 +1646,8 @@ class TestParser < Minitest::Test
|
|
1630
1646
|
assert_parses(
|
1631
1647
|
s(:def, :f,
|
1632
1648
|
s(:args, s(:kwrestarg)),
|
1633
|
-
|
1634
|
-
%q{def f(**);
|
1649
|
+
nil),
|
1650
|
+
%q{def f(**); end},
|
1635
1651
|
%q{ ~~ expression (args.kwrestarg)},
|
1636
1652
|
ALL_VERSIONS - %w(1.8 1.9))
|
1637
1653
|
end
|
@@ -1640,16 +1656,16 @@ class TestParser < Minitest::Test
|
|
1640
1656
|
assert_parses(
|
1641
1657
|
s(:def, :f,
|
1642
1658
|
s(:args, s(:blockarg, :block)),
|
1643
|
-
|
1644
|
-
%q{def f(&block);
|
1659
|
+
nil),
|
1660
|
+
%q{def f(&block); end},
|
1645
1661
|
%q{ ~~~~~ name (args.blockarg)
|
1646
1662
|
| ~~~~~~ expression (args.blockarg)})
|
1647
1663
|
end
|
1648
1664
|
|
1649
1665
|
def assert_parses_args(ast, code, versions=ALL_VERSIONS)
|
1650
1666
|
assert_parses(
|
1651
|
-
s(:def, :f, ast,
|
1652
|
-
%Q{def f #{code};
|
1667
|
+
s(:def, :f, ast, nil),
|
1668
|
+
%Q{def f #{code}; end},
|
1653
1669
|
%q{},
|
1654
1670
|
versions)
|
1655
1671
|
end
|
@@ -3620,6 +3636,15 @@ class TestParser < Minitest::Test
|
|
3620
3636
|
%q{ ~~~~~~~~~~ location})
|
3621
3637
|
end
|
3622
3638
|
|
3639
|
+
def test_cond_begin
|
3640
|
+
assert_parses(
|
3641
|
+
s(:if,
|
3642
|
+
s(:begin, s(:lvar, :bar)),
|
3643
|
+
s(:lvar, :foo),
|
3644
|
+
nil),
|
3645
|
+
%q{if (bar); foo; end})
|
3646
|
+
end
|
3647
|
+
|
3623
3648
|
def test_cond_begin_masgn
|
3624
3649
|
assert_parses(
|
3625
3650
|
s(:if,
|
@@ -3829,21 +3854,21 @@ class TestParser < Minitest::Test
|
|
3829
3854
|
%q{ ~~~~~ keyword})
|
3830
3855
|
end
|
3831
3856
|
|
3832
|
-
|
3833
|
-
|
3834
|
-
|
3835
|
-
|
3836
|
-
|
3837
|
-
|
3838
|
-
|
3857
|
+
def test_while_post
|
3858
|
+
assert_parses(
|
3859
|
+
s(:while_post, s(:lvar, :foo),
|
3860
|
+
s(:kwbegin, s(:send, nil, :meth))),
|
3861
|
+
%q{begin meth end while foo},
|
3862
|
+
%q{ ~~~~~ keyword})
|
3863
|
+
end
|
3839
3864
|
|
3840
|
-
|
3841
|
-
|
3842
|
-
|
3843
|
-
|
3844
|
-
|
3845
|
-
|
3846
|
-
|
3865
|
+
def test_until_post
|
3866
|
+
assert_parses(
|
3867
|
+
s(:until_post, s(:lvar, :foo),
|
3868
|
+
s(:kwbegin, s(:send, nil, :meth))),
|
3869
|
+
%q{begin meth end until foo},
|
3870
|
+
%q{ ~~~~~ keyword})
|
3871
|
+
end
|
3847
3872
|
|
3848
3873
|
def test_while_masgn
|
3849
3874
|
assert_diagnoses(
|
@@ -4011,7 +4036,7 @@ class TestParser < Minitest::Test
|
|
4011
4036
|
|
4012
4037
|
def test_rescue
|
4013
4038
|
assert_parses(
|
4014
|
-
s(:
|
4039
|
+
s(:kwbegin,
|
4015
4040
|
s(:rescue, s(:send, nil, :meth),
|
4016
4041
|
s(:resbody, nil, nil, s(:lvar, :foo)),
|
4017
4042
|
nil)),
|
@@ -4026,7 +4051,7 @@ class TestParser < Minitest::Test
|
|
4026
4051
|
|
4027
4052
|
def test_rescue_else
|
4028
4053
|
assert_parses(
|
4029
|
-
s(:
|
4054
|
+
s(:kwbegin,
|
4030
4055
|
s(:rescue, s(:send, nil, :meth),
|
4031
4056
|
s(:resbody, nil, nil, s(:lvar, :foo)),
|
4032
4057
|
s(:lvar, :bar))),
|
@@ -4044,7 +4069,7 @@ class TestParser < Minitest::Test
|
|
4044
4069
|
|
4045
4070
|
def test_ensure
|
4046
4071
|
assert_parses(
|
4047
|
-
s(:
|
4072
|
+
s(:kwbegin,
|
4048
4073
|
s(:ensure, s(:send, nil, :meth),
|
4049
4074
|
s(:lvar, :bar))),
|
4050
4075
|
%q{begin; meth; ensure; bar; end},
|
@@ -4057,7 +4082,7 @@ class TestParser < Minitest::Test
|
|
4057
4082
|
|
4058
4083
|
def test_ensure_empty
|
4059
4084
|
assert_parses(
|
4060
|
-
s(:
|
4085
|
+
s(:kwbegin,
|
4061
4086
|
s(:ensure, nil, nil)),
|
4062
4087
|
%q{begin ensure end},
|
4063
4088
|
%q{~~~~~ begin
|
@@ -4069,7 +4094,7 @@ class TestParser < Minitest::Test
|
|
4069
4094
|
|
4070
4095
|
def test_rescue_ensure
|
4071
4096
|
assert_parses(
|
4072
|
-
s(:
|
4097
|
+
s(:kwbegin,
|
4073
4098
|
s(:ensure,
|
4074
4099
|
s(:rescue,
|
4075
4100
|
s(:send, nil, :meth),
|
@@ -4085,7 +4110,7 @@ class TestParser < Minitest::Test
|
|
4085
4110
|
|
4086
4111
|
def test_rescue_else_ensure
|
4087
4112
|
assert_parses(
|
4088
|
-
s(:
|
4113
|
+
s(:kwbegin,
|
4089
4114
|
s(:ensure,
|
4090
4115
|
s(:rescue,
|
4091
4116
|
s(:send, nil, :meth),
|
@@ -4144,7 +4169,7 @@ class TestParser < Minitest::Test
|
|
4144
4169
|
|
4145
4170
|
def test_resbody_list
|
4146
4171
|
assert_parses(
|
4147
|
-
s(:
|
4172
|
+
s(:kwbegin,
|
4148
4173
|
s(:rescue,
|
4149
4174
|
s(:send, nil, :meth),
|
4150
4175
|
s(:resbody,
|
@@ -4157,7 +4182,7 @@ class TestParser < Minitest::Test
|
|
4157
4182
|
|
4158
4183
|
def test_resbody_list_mrhs
|
4159
4184
|
assert_parses(
|
4160
|
-
s(:
|
4185
|
+
s(:kwbegin,
|
4161
4186
|
s(:rescue,
|
4162
4187
|
s(:send, nil, :meth),
|
4163
4188
|
s(:resbody,
|
@@ -4172,7 +4197,7 @@ class TestParser < Minitest::Test
|
|
4172
4197
|
|
4173
4198
|
def test_resbody_var
|
4174
4199
|
assert_parses(
|
4175
|
-
s(:
|
4200
|
+
s(:kwbegin,
|
4176
4201
|
s(:rescue,
|
4177
4202
|
s(:send, nil, :meth),
|
4178
4203
|
s(:resbody, nil, s(:lvasgn, :ex), s(:lvar, :bar)),
|
@@ -4180,7 +4205,7 @@ class TestParser < Minitest::Test
|
|
4180
4205
|
%q{begin; meth; rescue => ex; bar; end})
|
4181
4206
|
|
4182
4207
|
assert_parses(
|
4183
|
-
s(:
|
4208
|
+
s(:kwbegin,
|
4184
4209
|
s(:rescue,
|
4185
4210
|
s(:send, nil, :meth),
|
4186
4211
|
s(:resbody, nil, s(:ivasgn, :@ex), s(:lvar, :bar)),
|
@@ -4190,7 +4215,7 @@ class TestParser < Minitest::Test
|
|
4190
4215
|
|
4191
4216
|
def test_resbody_list_var
|
4192
4217
|
assert_parses(
|
4193
|
-
s(:
|
4218
|
+
s(:kwbegin,
|
4194
4219
|
s(:rescue,
|
4195
4220
|
s(:send, nil, :meth),
|
4196
4221
|
s(:resbody,
|
@@ -4247,6 +4272,14 @@ class TestParser < Minitest::Test
|
|
4247
4272
|
# Miscellanea
|
4248
4273
|
#
|
4249
4274
|
|
4275
|
+
def test_kwbegin_compstmt
|
4276
|
+
assert_parses(
|
4277
|
+
s(:kwbegin,
|
4278
|
+
s(:send, nil, :foo!),
|
4279
|
+
s(:send, nil, :bar!)),
|
4280
|
+
%q{begin foo!; bar! end})
|
4281
|
+
end
|
4282
|
+
|
4250
4283
|
def test_crlf_line_endings
|
4251
4284
|
with_versions(ALL_VERSIONS) do |_ver, parser|
|
4252
4285
|
source_file = Parser::Source::Buffer.new('(comments)')
|
@@ -4269,7 +4302,7 @@ class TestParser < Minitest::Test
|
|
4269
4302
|
def test_begin_cmdarg
|
4270
4303
|
assert_parses(
|
4271
4304
|
s(:send, nil, :p,
|
4272
|
-
s(:
|
4305
|
+
s(:kwbegin,
|
4273
4306
|
s(:block,
|
4274
4307
|
s(:send, s(:int, 1), :times),
|
4275
4308
|
s(:args),
|
@@ -4391,7 +4424,7 @@ class TestParser < Minitest::Test
|
|
4391
4424
|
assert_parses(
|
4392
4425
|
s(:block,
|
4393
4426
|
s(:send, nil, :desc,
|
4394
|
-
s(:str,
|
4427
|
+
s(:str, 'foo')),
|
4395
4428
|
s(:args), nil),
|
4396
4429
|
%q{desc "foo" do end})
|
4397
4430
|
end
|