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/lib/parser/current.rb
CHANGED
|
@@ -30,7 +30,7 @@ module Parser
|
|
|
30
30
|
CurrentRuby = Ruby21
|
|
31
31
|
|
|
32
32
|
when /^2\.2\./
|
|
33
|
-
current_version = '2.2.
|
|
33
|
+
current_version = '2.2.10'
|
|
34
34
|
if RUBY_VERSION != current_version
|
|
35
35
|
warn_syntax_deviation 'parser/ruby22', current_version
|
|
36
36
|
end
|
|
@@ -39,7 +39,7 @@ module Parser
|
|
|
39
39
|
CurrentRuby = Ruby22
|
|
40
40
|
|
|
41
41
|
when /^2\.3\./
|
|
42
|
-
current_version = '2.3.
|
|
42
|
+
current_version = '2.3.8'
|
|
43
43
|
if RUBY_VERSION != current_version
|
|
44
44
|
warn_syntax_deviation 'parser/ruby23', current_version
|
|
45
45
|
end
|
|
@@ -48,7 +48,7 @@ module Parser
|
|
|
48
48
|
CurrentRuby = Ruby23
|
|
49
49
|
|
|
50
50
|
when /^2\.4\./
|
|
51
|
-
current_version = '2.4.
|
|
51
|
+
current_version = '2.4.5'
|
|
52
52
|
if RUBY_VERSION != current_version
|
|
53
53
|
warn_syntax_deviation 'parser/ruby24', current_version
|
|
54
54
|
end
|
|
@@ -57,7 +57,7 @@ module Parser
|
|
|
57
57
|
CurrentRuby = Ruby24
|
|
58
58
|
|
|
59
59
|
when /^2\.5\./
|
|
60
|
-
current_version = '2.5.
|
|
60
|
+
current_version = '2.5.3'
|
|
61
61
|
if RUBY_VERSION != current_version
|
|
62
62
|
warn_syntax_deviation 'parser/ruby25', current_version
|
|
63
63
|
end
|
|
@@ -65,10 +65,19 @@ module Parser
|
|
|
65
65
|
require 'parser/ruby25'
|
|
66
66
|
CurrentRuby = Ruby25
|
|
67
67
|
|
|
68
|
+
when /^2\.6\./
|
|
69
|
+
current_version = '2.6.0'
|
|
70
|
+
if RUBY_VERSION != current_version
|
|
71
|
+
warn_syntax_deviation 'parser/ruby26', current_version
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
require 'parser/ruby26'
|
|
75
|
+
CurrentRuby = Ruby26
|
|
76
|
+
|
|
68
77
|
else # :nocov:
|
|
69
78
|
# Keep this in sync with released Ruby.
|
|
70
|
-
warn_syntax_deviation 'parser/
|
|
71
|
-
require 'parser/
|
|
72
|
-
CurrentRuby =
|
|
79
|
+
warn_syntax_deviation 'parser/ruby25', '2.5.x'
|
|
80
|
+
require 'parser/ruby25'
|
|
81
|
+
CurrentRuby = Ruby25
|
|
73
82
|
end
|
|
74
83
|
end
|
|
@@ -12,13 +12,41 @@ module Parser
|
|
|
12
12
|
def dedent(string)
|
|
13
13
|
space_begin = space_end = offset = 0
|
|
14
14
|
last_index = string.length - 1
|
|
15
|
+
escape = false
|
|
16
|
+
_at_line_begin = nil
|
|
17
|
+
|
|
15
18
|
string.chars.each_with_index do |char, index|
|
|
16
|
-
if
|
|
19
|
+
if char == '\\'
|
|
20
|
+
# entering escape mode
|
|
21
|
+
escape = true
|
|
22
|
+
string.slice!(index - offset)
|
|
23
|
+
offset += 1
|
|
24
|
+
_at_line_begin = @at_line_begin
|
|
25
|
+
@at_line_begin = false
|
|
26
|
+
elsif escape
|
|
27
|
+
if char == ?\n
|
|
28
|
+
# trimming \n, starting a new line
|
|
29
|
+
string.slice!(index - offset)
|
|
30
|
+
offset += 1
|
|
31
|
+
@at_line_begin = true
|
|
32
|
+
space_begin = space_end = index - offset
|
|
33
|
+
@indent_level = 0
|
|
34
|
+
elsif char == ?n
|
|
35
|
+
# replacing \\n to \n
|
|
36
|
+
string.slice!(index - offset)
|
|
37
|
+
string.insert(index - offset, ?\n)
|
|
38
|
+
else
|
|
39
|
+
# exiting escape mode as it's not an escape sequence
|
|
40
|
+
@at_line_begin = _at_line_begin
|
|
41
|
+
escape = false
|
|
42
|
+
redo
|
|
43
|
+
end
|
|
44
|
+
escape = false
|
|
45
|
+
elsif @at_line_begin
|
|
17
46
|
if char == ?\n || @indent_level >= @dedent_level
|
|
18
47
|
string.slice!(space_begin...space_end)
|
|
19
|
-
offset += space_end - space_begin
|
|
48
|
+
offset += space_end - space_begin
|
|
20
49
|
@at_line_begin = false
|
|
21
|
-
redo if char == ?\n
|
|
22
50
|
end
|
|
23
51
|
|
|
24
52
|
case char
|
|
@@ -21,14 +21,14 @@ module Parser
|
|
|
21
21
|
more = "(in-kwarg)" if @in_kwarg
|
|
22
22
|
|
|
23
23
|
puts decorate(range,
|
|
24
|
-
"
|
|
25
|
-
"#{state.to_s.ljust(12)} #{@cond} #{@cmdarg} #{more}
|
|
24
|
+
Color.green("#{type} #{val.inspect}"),
|
|
25
|
+
"#{state.to_s.ljust(12)} #{@cond} #{@cmdarg} #{more}")
|
|
26
26
|
|
|
27
27
|
[ type, [val, range] ]
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def state=(new_state)
|
|
31
|
-
puts "
|
|
31
|
+
puts " #{Color.yellow(">>> STATE SET <<<", bold: true)} " +
|
|
32
32
|
"#{new_state.to_s.ljust(12)} #{@cond} #{@cmdarg}".rjust(66)
|
|
33
33
|
|
|
34
34
|
self.state_before_explanation = new_state
|
|
@@ -40,12 +40,12 @@ module Parser
|
|
|
40
40
|
from, to = range.begin.column, range.end.column
|
|
41
41
|
|
|
42
42
|
line = range.source_line + ' '
|
|
43
|
-
line[from...to] =
|
|
43
|
+
line[from...to] = Color.underline(line[from...to])
|
|
44
44
|
|
|
45
45
|
tail_len = to - from - 1
|
|
46
46
|
tail = '~' * (tail_len >= 0 ? tail_len : 0)
|
|
47
|
-
decoration = "#{" " * from}
|
|
48
|
-
ljust(
|
|
47
|
+
decoration = "#{" " * from}#{Color.red("^#{tail}", bold: true)} #{token} ".
|
|
48
|
+
ljust(68) + info
|
|
49
49
|
|
|
50
50
|
[ line, decoration ]
|
|
51
51
|
end
|
data/lib/parser/lexer/literal.rb
CHANGED
|
@@ -103,6 +103,14 @@ module Parser
|
|
|
103
103
|
!!@heredoc_e
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
+
def plain_heredoc?
|
|
107
|
+
heredoc? && !@dedent_body
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def squiggly_heredoc?
|
|
111
|
+
heredoc? && @dedent_body
|
|
112
|
+
end
|
|
113
|
+
|
|
106
114
|
def backslash_delimited?
|
|
107
115
|
@end_delim == '\\'.freeze
|
|
108
116
|
end
|
|
@@ -219,6 +227,10 @@ module Parser
|
|
|
219
227
|
end
|
|
220
228
|
end
|
|
221
229
|
|
|
230
|
+
def supports_line_continuation_via_slash?
|
|
231
|
+
!words? && @interpolate
|
|
232
|
+
end
|
|
233
|
+
|
|
222
234
|
protected
|
|
223
235
|
|
|
224
236
|
def delimiter?(delimiter)
|
|
@@ -230,7 +242,7 @@ module Parser
|
|
|
230
242
|
end
|
|
231
243
|
|
|
232
244
|
def coerce_encoding(string)
|
|
233
|
-
string.
|
|
245
|
+
string.b
|
|
234
246
|
end
|
|
235
247
|
|
|
236
248
|
def clear_buffer
|