parser 2.7.1.1 → 3.0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/parser.rb +1 -0
- data/lib/parser/all.rb +2 -0
- data/lib/parser/ast/processor.rb +5 -0
- data/lib/parser/base.rb +7 -5
- data/lib/parser/builders/default.rb +263 -23
- data/lib/parser/context.rb +5 -0
- data/lib/parser/current.rb +24 -6
- data/lib/parser/current_arg_stack.rb +5 -2
- data/lib/parser/diagnostic.rb +1 -1
- data/lib/parser/diagnostic/engine.rb +1 -2
- data/lib/parser/lexer.rb +887 -803
- data/lib/parser/macruby.rb +2214 -2189
- data/lib/parser/max_numparam_stack.rb +13 -5
- data/lib/parser/messages.rb +18 -0
- data/lib/parser/meta.rb +6 -5
- data/lib/parser/ruby18.rb +9 -3
- data/lib/parser/ruby19.rb +2297 -2289
- data/lib/parser/ruby20.rb +2413 -2397
- data/lib/parser/ruby21.rb +2419 -2411
- data/lib/parser/ruby22.rb +2468 -2460
- data/lib/parser/ruby23.rb +2452 -2452
- data/lib/parser/ruby24.rb +2435 -2430
- data/lib/parser/ruby25.rb +2220 -2214
- data/lib/parser/ruby26.rb +2220 -2214
- data/lib/parser/ruby27.rb +3715 -3615
- data/lib/parser/ruby28.rb +8047 -0
- data/lib/parser/ruby30.rb +8060 -0
- data/lib/parser/ruby31.rb +8226 -0
- data/lib/parser/rubymotion.rb +2190 -2182
- data/lib/parser/runner.rb +31 -2
- data/lib/parser/runner/ruby_rewrite.rb +2 -2
- data/lib/parser/source/buffer.rb +53 -28
- data/lib/parser/source/comment.rb +14 -1
- data/lib/parser/source/comment/associator.rb +31 -8
- data/lib/parser/source/map/method_definition.rb +25 -0
- data/lib/parser/source/range.rb +10 -3
- data/lib/parser/source/tree_rewriter.rb +100 -10
- data/lib/parser/source/tree_rewriter/action.rb +114 -21
- data/lib/parser/static_environment.rb +4 -0
- data/lib/parser/tree_rewriter.rb +1 -2
- data/lib/parser/variables_stack.rb +4 -0
- data/lib/parser/version.rb +1 -1
- data/parser.gemspec +3 -18
- metadata +17 -98
- data/.gitignore +0 -33
- data/.travis.yml +0 -42
- data/.yardopts +0 -21
- data/CHANGELOG.md +0 -1075
- data/CONTRIBUTING.md +0 -17
- data/Gemfile +0 -10
- data/README.md +0 -309
- data/Rakefile +0 -166
- data/ci/run_rubocop_specs +0 -14
- data/doc/AST_FORMAT.md +0 -2180
- 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 -2536
- data/lib/parser/macruby.y +0 -2198
- data/lib/parser/ruby18.y +0 -1934
- data/lib/parser/ruby19.y +0 -2175
- data/lib/parser/ruby20.y +0 -2353
- data/lib/parser/ruby21.y +0 -2357
- data/lib/parser/ruby22.y +0 -2364
- data/lib/parser/ruby23.y +0 -2370
- data/lib/parser/ruby24.y +0 -2408
- data/lib/parser/ruby25.y +0 -2405
- data/lib/parser/ruby26.y +0 -2413
- data/lib/parser/ruby27.y +0 -2941
- data/lib/parser/rubymotion.y +0 -2182
- 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 -60
- data/test/parse_helper.rb +0 -319
- data/test/racc_coverage_helper.rb +0 -133
- data/test/test_base.rb +0 -31
- data/test/test_current.rb +0 -29
- data/test/test_diagnostic.rb +0 -96
- data/test/test_diagnostic_engine.rb +0 -62
- data/test/test_encoding.rb +0 -99
- data/test/test_lexer.rb +0 -3608
- data/test/test_lexer_stack_state.rb +0 -78
- data/test/test_parse_helper.rb +0 -80
- data/test/test_parser.rb +0 -9430
- data/test/test_runner_parse.rb +0 -35
- data/test/test_runner_rewrite.rb +0 -47
- data/test/test_source_buffer.rb +0 -162
- data/test/test_source_comment.rb +0 -36
- data/test/test_source_comment_associator.rb +0 -367
- data/test/test_source_map.rb +0 -15
- data/test/test_source_range.rb +0 -187
- 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 -253
- 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
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
class TestSourceRewriterAction < Minitest::Test
|
6
|
-
def setup
|
7
|
-
@buf = Parser::Source::Buffer.new('(rewriter_action)')
|
8
|
-
@buf.source = 'foo bar baz'
|
9
|
-
end
|
10
|
-
|
11
|
-
def range(from, len)
|
12
|
-
Parser::Source::Range.new(@buf, from, from + len)
|
13
|
-
end
|
14
|
-
|
15
|
-
def action(range, replacement)
|
16
|
-
Parser::Source::Rewriter::Action.new(range, replacement)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_accessors
|
20
|
-
action = action(range(1, 10), 'foo')
|
21
|
-
|
22
|
-
assert action.frozen?
|
23
|
-
assert_equal range(1, 10), action.range
|
24
|
-
assert_equal 'foo', action.replacement
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_to_s_replace
|
28
|
-
action = action(range(3, 1), 'foo')
|
29
|
-
assert_equal "replace 1 character(s) with \"foo\"", action.to_s
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_to_s_insert
|
33
|
-
action = action(range(3, 0), 'foo')
|
34
|
-
assert_equal "insert \"foo\"", action.to_s
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_to_s_remove
|
38
|
-
action = action(range(3, 2), '')
|
39
|
-
assert_equal 'remove 2 character(s)', action.to_s
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_to_s_nop
|
43
|
-
action = action(range(3, 0), '')
|
44
|
-
assert_equal 'do nothing', action.to_s
|
45
|
-
end
|
46
|
-
end
|
@@ -1,253 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
class TestSourceTreeRewriter < Minitest::Test
|
6
|
-
def setup
|
7
|
-
@buf = Parser::Source::Buffer.new('(rewriter)')
|
8
|
-
@buf.source = 'puts(:hello, :world)'
|
9
|
-
|
10
|
-
@hello = range(5, 6)
|
11
|
-
@ll = range(7, 2)
|
12
|
-
@comma_space = range(11,2)
|
13
|
-
@world = range(13,6)
|
14
|
-
@whole = range(0, @buf.source.length)
|
15
|
-
end
|
16
|
-
|
17
|
-
def range(from, len)
|
18
|
-
Parser::Source::Range.new(@buf, from, from + len)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Returns either:
|
22
|
-
# - yield rewriter
|
23
|
-
# - [diagnostic, ...] (Diagnostics)
|
24
|
-
# - Parser::ClobberingError
|
25
|
-
#
|
26
|
-
def build(actions, **policy)
|
27
|
-
diagnostics = []
|
28
|
-
diags = -> { diagnostics.flatten.map(&:strip).join("\n") }
|
29
|
-
rewriter = Parser::Source::TreeRewriter.new(@buf, **policy)
|
30
|
-
rewriter.diagnostics.consumer = -> diag { diagnostics << diag.render }
|
31
|
-
actions.each do |action, range, *args|
|
32
|
-
rewriter.public_send(action, range, *args)
|
33
|
-
end
|
34
|
-
if diagnostics.empty?
|
35
|
-
yield rewriter
|
36
|
-
else
|
37
|
-
diags.call
|
38
|
-
end
|
39
|
-
rescue ::Parser::ClobberingError => e
|
40
|
-
[::Parser::ClobberingError, diags.call]
|
41
|
-
end
|
42
|
-
|
43
|
-
# Returns either:
|
44
|
-
# - String (Normal operation)
|
45
|
-
# - [diagnostic, ...] (Diagnostics)
|
46
|
-
# - Parser::ClobberingError
|
47
|
-
#
|
48
|
-
def apply(actions, **policy)
|
49
|
-
build(actions, **policy) { |rewriter| rewriter.process }
|
50
|
-
end
|
51
|
-
|
52
|
-
# Expects ordered actions to be grouped together
|
53
|
-
def check_actions(expected, grouped_actions, **policy)
|
54
|
-
grouped_actions.permutation do |sequence|
|
55
|
-
# [action, [action, action]] => [action, action, action]
|
56
|
-
# except we can't use flatten because "action" are arrays themselves
|
57
|
-
actions = sequence.flat_map { |group| group.first.is_a?(Array) ? group : [group] }
|
58
|
-
assert_equal(expected, apply(actions, **policy))
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def assert_actions_result(expected, *actions, **rest)
|
63
|
-
if expected == :raise
|
64
|
-
diagnostic = rest.values.first
|
65
|
-
check_actions([::Parser::ClobberingError, diagnostic], actions)
|
66
|
-
elsif rest.empty?
|
67
|
-
check_actions(expected, actions)
|
68
|
-
else
|
69
|
-
policy, diagnostic = rest.first
|
70
|
-
check_actions(expected, actions, policy => :accept)
|
71
|
-
check_actions(diagnostic, actions, policy => :warn)
|
72
|
-
diagnostic.gsub!(/warning: /, 'error: ')
|
73
|
-
check_actions([::Parser::ClobberingError, diagnostic], actions, policy => :raise)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
### Simple cases
|
78
|
-
|
79
|
-
def test_remove
|
80
|
-
assert_actions_result 'puts(, :world)', [:remove, @hello]
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_insert_before
|
84
|
-
assert_actions_result 'puts(:hello, 42, :world)', [:insert_before, @world, '42, ']
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_insert_after
|
88
|
-
assert_actions_result 'puts(:hello, 42, :world)', [:insert_after, @hello, ', 42']
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_wrap
|
92
|
-
assert_actions_result 'puts([:hello], :world)', [:wrap, @hello, '[', ']']
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_replace
|
96
|
-
assert_actions_result 'puts(:hi, :world)', [:replace, @hello, ':hi']
|
97
|
-
end
|
98
|
-
|
99
|
-
#
|
100
|
-
# All other cases, as per doc
|
101
|
-
#
|
102
|
-
|
103
|
-
def test_crossing_non_deletions
|
104
|
-
check = [
|
105
|
-
[:wrap, '(', ')'],
|
106
|
-
[:remove],
|
107
|
-
[:replace, 'xx'],
|
108
|
-
]
|
109
|
-
check.combination(2) do |(action, *args), (action_b, *args_b)|
|
110
|
-
next if action == :remove && action_b == :remove
|
111
|
-
assert_actions_result :raise,
|
112
|
-
[[action, @hello.join(@comma_space), *args],
|
113
|
-
[action_b, @world.join(@comma_space), *args_b]],
|
114
|
-
diagnostic: <<-DIAGNOSTIC.chomp
|
115
|
-
(rewriter):1:12: error: the rewriting action on:
|
116
|
-
(rewriter):1: puts(:hello, :world)
|
117
|
-
(rewriter):1: ^~~~~~~~
|
118
|
-
(rewriter):1:6: error: is crossing that on:
|
119
|
-
(rewriter):1: puts(:hello, :world)
|
120
|
-
(rewriter):1: ^~~~~~~~
|
121
|
-
DIAGNOSTIC
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
|
126
|
-
def test_crossing_deletions
|
127
|
-
assert_actions_result 'puts()',
|
128
|
-
[[:remove, @hello.join(@comma_space)],
|
129
|
-
[:remove, @world.join(@comma_space)]],
|
130
|
-
crossing_deletions: <<-DIAGNOSTIC.chomp
|
131
|
-
(rewriter):1:12: warning: the deletion of:
|
132
|
-
(rewriter):1: puts(:hello, :world)
|
133
|
-
(rewriter):1: ^~~~~~~~
|
134
|
-
(rewriter):1:6: warning: is crossing:
|
135
|
-
(rewriter):1: puts(:hello, :world)
|
136
|
-
(rewriter):1: ^~~~~~~~
|
137
|
-
DIAGNOSTIC
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_multiple_actions
|
141
|
-
assert_actions_result 'puts({:hello => [:everybody]})',
|
142
|
-
[:replace, @comma_space, ' => '],
|
143
|
-
[:wrap, @hello.join(@world), '{', '}'],
|
144
|
-
[:replace, @world, ':everybody'],
|
145
|
-
[:wrap, @world, '[', ']']
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_wraps_same_range
|
149
|
-
assert_actions_result 'puts([(:hello)], :world)',
|
150
|
-
[[:wrap, @hello, '(', ')'],
|
151
|
-
[:wrap, @hello, '[', ']']]
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_replace_same_range
|
155
|
-
assert_actions_result 'puts(:hey, :world)',
|
156
|
-
[[:replace, @hello, ':hi'],
|
157
|
-
[:replace, @hello, ':hey']],
|
158
|
-
different_replacements: <<-DIAGNOSTIC.chomp
|
159
|
-
(rewriter):1:6: warning: different replacements: :hey vs :hi
|
160
|
-
(rewriter):1: puts(:hello, :world)
|
161
|
-
(rewriter):1: ^~~~~~
|
162
|
-
DIAGNOSTIC
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_swallowed_insertions
|
166
|
-
assert_actions_result 'puts(:hi)',
|
167
|
-
[[:wrap, @hello.adjust(begin_pos: 1), '__', '__'],
|
168
|
-
[:replace, @world.adjust(end_pos: -2), 'xx'],
|
169
|
-
[:replace, @hello.join(@world), ':hi']],
|
170
|
-
swallowed_insertions: <<-DIAGNOSTIC.chomp
|
171
|
-
(rewriter):1:6: warning: this replacement:
|
172
|
-
(rewriter):1: puts(:hello, :world)
|
173
|
-
(rewriter):1: ^~~~~~~~~~~~~~
|
174
|
-
(rewriter):1:7: warning: swallows some inner rewriting actions:
|
175
|
-
(rewriter):1: puts(:hello, :world)
|
176
|
-
(rewriter):1: ^~~~~ ~~~~
|
177
|
-
DIAGNOSTIC
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_out_of_range_ranges
|
181
|
-
rewriter = Parser::Source::TreeRewriter.new(@buf)
|
182
|
-
assert_raises(IndexError) { rewriter.insert_before(range(0, 100), 'hola') }
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_empty
|
186
|
-
rewriter = Parser::Source::TreeRewriter.new(@buf)
|
187
|
-
assert_equal true, rewriter.empty?
|
188
|
-
|
189
|
-
# This is a trivial wrap
|
190
|
-
rewriter.wrap(range(2,3), '', '')
|
191
|
-
assert_equal true, rewriter.empty?
|
192
|
-
|
193
|
-
# This is a trivial deletion
|
194
|
-
rewriter.remove(range(2,0))
|
195
|
-
assert_equal true, rewriter.empty?
|
196
|
-
|
197
|
-
rewriter.remove(range(2,3))
|
198
|
-
assert_equal false, rewriter.empty?
|
199
|
-
end
|
200
|
-
|
201
|
-
# splits array into two groups, yield all such possible pairs of groups
|
202
|
-
# each_split([1, 2, 3, 4]) yields [1, 2], [3, 4];
|
203
|
-
# then [1, 3], [2, 4]
|
204
|
-
# ...
|
205
|
-
# and finally [3, 4], [1, 2]
|
206
|
-
def each_split(array)
|
207
|
-
n = array.size
|
208
|
-
first_split_size = n.div(2)
|
209
|
-
splitting = (0...n).to_set
|
210
|
-
splitting.to_a.combination(first_split_size) do |indices|
|
211
|
-
yield array.values_at(*indices),
|
212
|
-
array.values_at(*(splitting - indices))
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
# Checks that `actions+extra` give the same result when
|
217
|
-
# made in order or from subgroups that are later merged.
|
218
|
-
# The `extra` actions are always added at the end of the second group.
|
219
|
-
#
|
220
|
-
def check_all_merge_possibilities(actions, extra, **policy)
|
221
|
-
expected = apply(actions + extra, **policy)
|
222
|
-
|
223
|
-
each_split(actions) do |actions_1, actions_2|
|
224
|
-
build(actions_1, **policy) do |rewriter_1|
|
225
|
-
build(actions_2 + extra, **policy) do |rewriter_2|
|
226
|
-
result = rewriter_1.merge(rewriter_2).process
|
227
|
-
assert_equal(expected, result,
|
228
|
-
"Group 1: #{actions_1.inspect}\n\n" +
|
229
|
-
"Group 2: #{(actions_2 + extra).inspect}"
|
230
|
-
)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
def test_merge
|
237
|
-
check_all_merge_possibilities([
|
238
|
-
[:wrap, @whole, '<', '>'],
|
239
|
-
[:replace, @comma_space, ' => '],
|
240
|
-
[:wrap, @hello, '!', '!'],
|
241
|
-
# Following two wraps must have same value as they
|
242
|
-
# will be applied in different orders...
|
243
|
-
[:wrap, @hello.join(@world), '{', '}'],
|
244
|
-
[:wrap, @hello.join(@world), '{', '}'],
|
245
|
-
[:remove, @ll],
|
246
|
-
[:replace, @world, ':everybody'],
|
247
|
-
[:wrap, @world, '[', ']']
|
248
|
-
],
|
249
|
-
[ # ... but this one is always going to be applied last (extra)
|
250
|
-
[:wrap, @hello.join(@world), '@', '@'],
|
251
|
-
])
|
252
|
-
end
|
253
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
class TestStaticEnvironment < Minitest::Test
|
6
|
-
def setup
|
7
|
-
@env = Parser::StaticEnvironment.new
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_declare
|
11
|
-
refute @env.declared?(:foo)
|
12
|
-
|
13
|
-
@env.declare :foo
|
14
|
-
|
15
|
-
assert @env.declared?(:foo)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_extend_static
|
19
|
-
@env.declare :foo
|
20
|
-
@env.extend_static
|
21
|
-
@env.declare :bar
|
22
|
-
|
23
|
-
refute @env.declared?(:foo)
|
24
|
-
assert @env.declared?(:bar)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_extend_dynamic
|
28
|
-
@env.declare :foo
|
29
|
-
@env.extend_dynamic
|
30
|
-
@env.declare :bar
|
31
|
-
|
32
|
-
assert @env.declared?(:foo)
|
33
|
-
assert @env.declared?(:bar)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_unextend
|
37
|
-
@env.declare :foo
|
38
|
-
@env.extend_dynamic
|
39
|
-
@env.declare :bar
|
40
|
-
@env.unextend
|
41
|
-
|
42
|
-
assert @env.declared?(:foo)
|
43
|
-
refute @env.declared?(:bar)
|
44
|
-
end
|
45
|
-
end
|