parser 2.7.1.4 → 3.0.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 +4 -4
- data/lib/parser/all.rb +1 -1
- data/lib/parser/ast/processor.rb +3 -7
- data/lib/parser/base.rb +7 -5
- data/lib/parser/builders/default.rb +177 -28
- data/lib/parser/context.rb +4 -0
- data/lib/parser/current.rb +9 -9
- data/lib/parser/current_arg_stack.rb +5 -2
- data/lib/parser/lexer.rb +813 -803
- data/lib/parser/macruby.rb +1 -1
- data/lib/parser/max_numparam_stack.rb +13 -5
- data/lib/parser/messages.rb +3 -0
- data/lib/parser/meta.rb +7 -6
- data/lib/parser/ruby18.rb +7 -3
- data/lib/parser/ruby19.rb +1 -1
- data/lib/parser/ruby20.rb +1 -1
- data/lib/parser/ruby21.rb +1 -1
- data/lib/parser/ruby22.rb +1 -1
- data/lib/parser/ruby23.rb +1 -1
- data/lib/parser/ruby24.rb +1 -1
- data/lib/parser/ruby25.rb +1 -1
- data/lib/parser/ruby26.rb +1 -1
- data/lib/parser/ruby27.rb +3720 -3701
- data/lib/parser/ruby30.rb +8060 -0
- data/lib/parser/rubymotion.rb +1 -1
- data/lib/parser/runner.rb +4 -4
- data/lib/parser/source/buffer.rb +45 -27
- data/lib/parser/source/comment/associator.rb +1 -1
- data/lib/parser/source/comment.rb +1 -1
- data/lib/parser/source/map/{endless_definition.rb → method_definition.rb} +5 -3
- data/lib/parser/source/range.rb +2 -2
- data/lib/parser/static_environment.rb +4 -0
- data/lib/parser/variables_stack.rb +4 -0
- data/lib/parser/version.rb +1 -1
- data/lib/parser.rb +1 -1
- data/parser.gemspec +1 -17
- metadata +8 -97
- data/.gitignore +0 -34
- data/.travis.yml +0 -40
- data/.yardopts +0 -21
- data/CHANGELOG.md +0 -1116
- data/CONTRIBUTING.md +0 -17
- data/Gemfile +0 -10
- data/README.md +0 -309
- data/Rakefile +0 -167
- data/ci/run_rubocop_specs +0 -14
- data/doc/AST_FORMAT.md +0 -2283
- data/doc/CUSTOMIZATION.md +0 -37
- data/doc/INTERNALS.md +0 -21
- data/doc/css/.gitkeep +0 -0
- data/doc/css/common.css +0 -68
- data/lib/parser/lexer.rl +0 -2550
- data/lib/parser/macruby.y +0 -2208
- data/lib/parser/ruby18.y +0 -1936
- data/lib/parser/ruby19.y +0 -2185
- data/lib/parser/ruby20.y +0 -2363
- data/lib/parser/ruby21.y +0 -2364
- data/lib/parser/ruby22.y +0 -2371
- data/lib/parser/ruby23.y +0 -2377
- data/lib/parser/ruby24.y +0 -2415
- data/lib/parser/ruby25.y +0 -2412
- data/lib/parser/ruby26.y +0 -2420
- data/lib/parser/ruby27.y +0 -2950
- data/lib/parser/ruby28.y +0 -3043
- data/lib/parser/rubymotion.y +0 -2192
- data/test/bug_163/fixtures/input.rb +0 -5
- data/test/bug_163/fixtures/output.rb +0 -5
- data/test/bug_163/rewriter.rb +0 -20
- data/test/helper.rb +0 -103
- data/test/parse_helper.rb +0 -323
- data/test/racc_coverage_helper.rb +0 -133
- data/test/test_ast_processor.rb +0 -32
- data/test/test_base.rb +0 -31
- data/test/test_current.rb +0 -31
- data/test/test_diagnostic.rb +0 -95
- data/test/test_diagnostic_engine.rb +0 -59
- data/test/test_encoding.rb +0 -99
- data/test/test_lexer.rb +0 -3617
- data/test/test_lexer_stack_state.rb +0 -78
- data/test/test_meta.rb +0 -12
- data/test/test_parse_helper.rb +0 -80
- data/test/test_parser.rb +0 -9780
- data/test/test_runner_parse.rb +0 -56
- data/test/test_runner_rewrite.rb +0 -47
- data/test/test_source_buffer.rb +0 -165
- data/test/test_source_comment.rb +0 -36
- data/test/test_source_comment_associator.rb +0 -399
- data/test/test_source_map.rb +0 -14
- data/test/test_source_range.rb +0 -192
- data/test/test_source_rewriter.rb +0 -541
- data/test/test_source_rewriter_action.rb +0 -46
- data/test/test_source_tree_rewriter.rb +0 -361
- data/test/test_static_environment.rb +0 -45
- data/test/using_tree_rewriter/fixtures/input.rb +0 -3
- data/test/using_tree_rewriter/fixtures/output.rb +0 -3
- data/test/using_tree_rewriter/using_tree_rewriter.rb +0 -9
data/test/test_diagnostic.rb
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'helper'
|
|
4
|
-
|
|
5
|
-
class TestDiagnostic < Minitest::Test
|
|
6
|
-
def setup
|
|
7
|
-
@buffer = Parser::Source::Buffer.new('(string)',
|
|
8
|
-
source: 'if (this is some bad code + bugs)')
|
|
9
|
-
|
|
10
|
-
@range1 = Parser::Source::Range.new(@buffer, 0, 2) # if
|
|
11
|
-
@range2 = Parser::Source::Range.new(@buffer, 4, 8) # this
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def test_verifies_levels
|
|
15
|
-
error = assert_raises ArgumentError do
|
|
16
|
-
Parser::Diagnostic.new(:foobar, :escape_eof, {}, @range1)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
assert_match(/level/, error.message)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def test_freezes
|
|
23
|
-
string = 'foo'.dup
|
|
24
|
-
highlights = [@range2]
|
|
25
|
-
|
|
26
|
-
diag = Parser::Diagnostic.new(:error, :escape_eof, @range1, highlights)
|
|
27
|
-
assert diag.frozen?
|
|
28
|
-
assert diag.arguments.frozen?
|
|
29
|
-
assert diag.highlights.frozen?
|
|
30
|
-
|
|
31
|
-
refute string.frozen?
|
|
32
|
-
refute highlights.frozen?
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def test_render
|
|
36
|
-
location = Parser::Source::Range.new(@buffer, 26, 27)
|
|
37
|
-
|
|
38
|
-
highlights = [
|
|
39
|
-
Parser::Source::Range.new(@buffer, 21, 25),
|
|
40
|
-
Parser::Source::Range.new(@buffer, 28, 32)
|
|
41
|
-
]
|
|
42
|
-
|
|
43
|
-
diag = Parser::Diagnostic.new(:error, :unexpected, { :character => '+' },
|
|
44
|
-
location, highlights)
|
|
45
|
-
assert_equal([
|
|
46
|
-
"(string):1:27: error: unexpected `+'",
|
|
47
|
-
'(string):1: if (this is some bad code + bugs)',
|
|
48
|
-
'(string):1: ~~~~ ^ ~~~~ '
|
|
49
|
-
], diag.render)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def test_multiline_render
|
|
53
|
-
@buffer = Parser::Source::Buffer.new('(string)',
|
|
54
|
-
source: "abc abc abc\ndef def def\nghi ghi ghi\n")
|
|
55
|
-
|
|
56
|
-
location = Parser::Source::Range.new(@buffer, 4, 27)
|
|
57
|
-
|
|
58
|
-
highlights = [
|
|
59
|
-
Parser::Source::Range.new(@buffer, 0, 3),
|
|
60
|
-
Parser::Source::Range.new(@buffer, 28, 31)
|
|
61
|
-
]
|
|
62
|
-
|
|
63
|
-
diag = Parser::Diagnostic.new(:error, :unexpected_token, { :token => 'ghi' },
|
|
64
|
-
location, highlights)
|
|
65
|
-
|
|
66
|
-
assert_equal([
|
|
67
|
-
"(string):1:5-3:3: error: unexpected token ghi",
|
|
68
|
-
'(string):1: abc abc abc',
|
|
69
|
-
'(string):1: ~~~ ^~~~~~~...',
|
|
70
|
-
'(string):3: ghi ghi ghi',
|
|
71
|
-
'(string):3: ~~~ ~~~ '
|
|
72
|
-
], diag.render)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def test_bug_error_on_newline
|
|
76
|
-
# regression test; see GitHub issue 273
|
|
77
|
-
source = <<-CODE
|
|
78
|
-
{
|
|
79
|
-
foo: ->() # I forgot my brace
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
CODE
|
|
83
|
-
@buffer = Parser::Source::Buffer.new('(string)', source: source)
|
|
84
|
-
|
|
85
|
-
location = Parser::Source::Range.new(@buffer, 33, 34)
|
|
86
|
-
diag = Parser::Diagnostic.new(:error, :unexpected_token, { :token => 'tNL' },
|
|
87
|
-
location)
|
|
88
|
-
|
|
89
|
-
assert_equal([
|
|
90
|
-
'(string):2:32: error: unexpected token tNL',
|
|
91
|
-
'(string):2: foo: ->() # I forgot my brace',
|
|
92
|
-
'(string):2: ^'
|
|
93
|
-
], diag.render)
|
|
94
|
-
end
|
|
95
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'helper'
|
|
4
|
-
|
|
5
|
-
class TestDiagnosticEngine < Minitest::Test
|
|
6
|
-
def setup
|
|
7
|
-
@engine = Parser::Diagnostic::Engine.new
|
|
8
|
-
|
|
9
|
-
@queue = []
|
|
10
|
-
@engine.consumer = lambda { |diag| @queue << diag }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def test_process_warnings
|
|
14
|
-
warn = Parser::Diagnostic.new(:warning, :invalid_escape, {}, 1..2)
|
|
15
|
-
@engine.process(warn)
|
|
16
|
-
|
|
17
|
-
assert_equal [warn], @queue
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_ignore_warnings
|
|
21
|
-
@engine.ignore_warnings = true
|
|
22
|
-
|
|
23
|
-
warn = Parser::Diagnostic.new(:warning, :invalid_escape, {}, 1..2)
|
|
24
|
-
@engine.process(warn)
|
|
25
|
-
|
|
26
|
-
assert_equal [], @queue
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_all_errors_are_fatal
|
|
30
|
-
@engine.all_errors_are_fatal = true
|
|
31
|
-
|
|
32
|
-
error = Parser::Diagnostic.new(:error, :invalid_escape, {}, 1..2)
|
|
33
|
-
|
|
34
|
-
err = assert_raises Parser::SyntaxError do
|
|
35
|
-
@engine.process(error)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
assert_equal error, err.diagnostic
|
|
39
|
-
|
|
40
|
-
assert_equal [error], @queue
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def test_all_errors_are_collected
|
|
44
|
-
error = Parser::Diagnostic.new(:error, :invalid_escape, {}, 1..2)
|
|
45
|
-
@engine.process(error)
|
|
46
|
-
|
|
47
|
-
assert_equal [error], @queue
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def test_fatal_error
|
|
51
|
-
fatal = Parser::Diagnostic.new(:fatal, :invalid_escape, {}, 1..2)
|
|
52
|
-
|
|
53
|
-
assert_raises Parser::SyntaxError do
|
|
54
|
-
@engine.process(fatal)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
assert_equal [fatal], @queue
|
|
58
|
-
end
|
|
59
|
-
end
|
data/test/test_encoding.rb
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# encoding: binary
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require 'helper'
|
|
5
|
-
|
|
6
|
-
class TestEncoding < Minitest::Test
|
|
7
|
-
include AST::Sexp
|
|
8
|
-
|
|
9
|
-
def recognize(string)
|
|
10
|
-
Parser::Source::Buffer.recognize_encoding(string)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
require 'parser/all'
|
|
14
|
-
|
|
15
|
-
def test_default
|
|
16
|
-
assert_nil recognize('foobar')
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_bom
|
|
20
|
-
assert_equal Encoding::UTF_8, recognize("\xef\xbb\xbf\nfoobar")
|
|
21
|
-
assert_equal Encoding::UTF_8, recognize("\xef\xbb\xbf# coding:koi8-r\nfoobar")
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def test_magic_comment
|
|
25
|
-
assert_equal Encoding::KOI8_R, recognize("# coding:koi8-r\nfoobar")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def test_shebang
|
|
29
|
-
assert_equal Encoding::KOI8_R, recognize("#!/bin/foo\n# coding:koi8-r\nfoobar")
|
|
30
|
-
assert_nil recognize("#!/bin/foo\n")
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def test_case
|
|
34
|
-
assert_equal Encoding::KOI8_R, recognize("# coding:KoI8-r\nfoobar")
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def test_space
|
|
38
|
-
assert_equal Encoding::KOI8_R, recognize("# coding : koi8-r\nfoobar")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def test_empty
|
|
42
|
-
assert_nil recognize('')
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_no_comment
|
|
46
|
-
assert_nil recognize(%{require 'cane/encoding_aware_iterator'})
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_adjacent
|
|
50
|
-
assert_nil recognize('# codingkoi8-r')
|
|
51
|
-
assert_nil recognize('# coding koi8-r')
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_utf8_mac
|
|
55
|
-
assert_equal Encoding::UTF8_MAC, recognize('# coding: utf8-mac')
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def test_suffix
|
|
59
|
-
assert_equal Encoding::UTF_8, recognize('# coding: utf-8-dos')
|
|
60
|
-
assert_equal Encoding::UTF_8, recognize('# coding: utf-8-unix')
|
|
61
|
-
assert_equal Encoding::UTF_8, recognize('# coding: utf-8-mac')
|
|
62
|
-
|
|
63
|
-
assert_raises(ArgumentError) do
|
|
64
|
-
assert_nil recognize('# coding: utf-8-dicks')
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def test_parse_18_invalid_enc
|
|
69
|
-
ast = Parser::Ruby18.parse("# encoding:feynman-diagram\n1")
|
|
70
|
-
assert_equal ast, s(:int, 1)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def test_parse_19_invalid_enc
|
|
74
|
-
assert_raises(ArgumentError) do
|
|
75
|
-
Parser::Ruby19.parse("# encoding:feynman-diagram\n1")
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def test_ending_comment
|
|
80
|
-
assert_nil recognize('foo # coding: koi8-r')
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def test_wrong_prefix
|
|
84
|
-
assert_nil recognize('# decoding: koi8-r')
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def test_no_spaces
|
|
88
|
-
assert_equal Encoding::KOI8_R, recognize('#encoding:koi8-r')
|
|
89
|
-
assert_equal Encoding::KOI8_R, recognize('#coding:koi8-r')
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def test_underscore_and_star_characters
|
|
93
|
-
assert_equal Encoding::KOI8_R, recognize('# -*- encoding: koi8-r -*-')
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def test_garbage_around_encoding_comment
|
|
97
|
-
assert_equal Encoding::KOI8_R, recognize('# 1$# -*- &)* encoding: koi8-r 1$# -*- &)*')
|
|
98
|
-
end
|
|
99
|
-
end
|