parser 2.7.0.3 → 2.7.1.2
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/.gitignore +1 -0
- data/.travis.yml +14 -23
- data/CHANGELOG.md +42 -0
- data/README.md +5 -4
- data/Rakefile +1 -0
- data/doc/AST_FORMAT.md +32 -5
- data/lib/parser.rb +1 -0
- data/lib/parser/all.rb +1 -0
- data/lib/parser/ast/processor.rb +4 -0
- data/lib/parser/builders/default.rb +54 -14
- data/lib/parser/current.rb +13 -4
- data/lib/parser/lexer.rl +1 -1
- data/lib/parser/meta.rb +1 -1
- data/lib/parser/ruby27.y +16 -5
- data/lib/parser/ruby28.y +2974 -0
- data/lib/parser/runner.rb +5 -0
- data/lib/parser/source/map/endless_definition.rb +23 -0
- data/lib/parser/source/range.rb +9 -0
- data/lib/parser/source/tree_rewriter.rb +50 -13
- data/lib/parser/source/tree_rewriter/action.rb +96 -26
- data/lib/parser/version.rb +1 -1
- data/parser.gemspec +1 -0
- data/test/helper.rb +1 -0
- data/test/parse_helper.rb +2 -1
- data/test/test_current.rb +2 -0
- data/test/test_lexer.rb +12 -0
- data/test/test_parser.rb +190 -8
- data/test/test_source_range.rb +15 -0
- data/test/test_source_tree_rewriter.rb +93 -3
- metadata +8 -5
data/test/test_source_range.rb
CHANGED
@@ -169,4 +169,19 @@ class TestSourceRange < Minitest::Test
|
|
169
169
|
assert_equal 1, sr3.begin_pos
|
170
170
|
assert_equal 4, sr3.end_pos
|
171
171
|
end
|
172
|
+
|
173
|
+
def test_eql_and_hash
|
174
|
+
assert_equal false, @sr1_3.eql?(@sr3_3)
|
175
|
+
assert @sr1_3.hash != @sr3_3.hash
|
176
|
+
|
177
|
+
also_1_3 = @sr3_3.with(begin_pos: 1)
|
178
|
+
assert_equal true, @sr1_3.eql?(also_1_3)
|
179
|
+
assert_equal @sr1_3.hash, also_1_3.hash
|
180
|
+
|
181
|
+
buf2 = Parser::Source::Buffer.new('(string)')
|
182
|
+
buf2.source = "foobar\nbaz"
|
183
|
+
from_other_buf = Parser::Source::Range.new(buf2, 1, 3)
|
184
|
+
assert_equal false, @sr1_3.eql?(from_other_buf)
|
185
|
+
assert @sr1_3.hash != from_other_buf.hash
|
186
|
+
end
|
172
187
|
end
|
@@ -8,8 +8,10 @@ class TestSourceTreeRewriter < Minitest::Test
|
|
8
8
|
@buf.source = 'puts(:hello, :world)'
|
9
9
|
|
10
10
|
@hello = range(5, 6)
|
11
|
+
@ll = range(7, 2)
|
11
12
|
@comma_space = range(11,2)
|
12
13
|
@world = range(13,6)
|
14
|
+
@whole = range(0, @buf.source.length)
|
13
15
|
end
|
14
16
|
|
15
17
|
def range(from, len)
|
@@ -17,11 +19,11 @@ class TestSourceTreeRewriter < Minitest::Test
|
|
17
19
|
end
|
18
20
|
|
19
21
|
# Returns either:
|
20
|
-
# -
|
22
|
+
# - yield rewriter
|
21
23
|
# - [diagnostic, ...] (Diagnostics)
|
22
24
|
# - Parser::ClobberingError
|
23
25
|
#
|
24
|
-
def
|
26
|
+
def build(actions, **policy)
|
25
27
|
diagnostics = []
|
26
28
|
diags = -> { diagnostics.flatten.map(&:strip).join("\n") }
|
27
29
|
rewriter = Parser::Source::TreeRewriter.new(@buf, **policy)
|
@@ -30,7 +32,7 @@ class TestSourceTreeRewriter < Minitest::Test
|
|
30
32
|
rewriter.public_send(action, range, *args)
|
31
33
|
end
|
32
34
|
if diagnostics.empty?
|
33
|
-
rewriter
|
35
|
+
yield rewriter
|
34
36
|
else
|
35
37
|
diags.call
|
36
38
|
end
|
@@ -38,6 +40,15 @@ class TestSourceTreeRewriter < Minitest::Test
|
|
38
40
|
[::Parser::ClobberingError, diags.call]
|
39
41
|
end
|
40
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
|
+
|
41
52
|
# Expects ordered actions to be grouped together
|
42
53
|
def check_actions(expected, grouped_actions, **policy)
|
43
54
|
grouped_actions.permutation do |sequence|
|
@@ -140,6 +151,16 @@ DIAGNOSTIC
|
|
140
151
|
[:wrap, @hello, '[', ']']]
|
141
152
|
end
|
142
153
|
|
154
|
+
def test_inserts_on_empty_ranges
|
155
|
+
assert_actions_result 'puts({x}:hello[y], :world)',
|
156
|
+
[:insert_before, @hello.begin, '{'],
|
157
|
+
[:replace, @hello.begin, 'x'],
|
158
|
+
[:insert_after, @hello.begin, '}'],
|
159
|
+
[:insert_before, @hello.end, '['],
|
160
|
+
[:replace, @hello.end, 'y'],
|
161
|
+
[:insert_after, @hello.end, ']']
|
162
|
+
end
|
163
|
+
|
143
164
|
def test_replace_same_range
|
144
165
|
assert_actions_result 'puts(:hey, :world)',
|
145
166
|
[[:replace, @hello, ':hi'],
|
@@ -170,4 +191,73 @@ DIAGNOSTIC
|
|
170
191
|
rewriter = Parser::Source::TreeRewriter.new(@buf)
|
171
192
|
assert_raises(IndexError) { rewriter.insert_before(range(0, 100), 'hola') }
|
172
193
|
end
|
194
|
+
|
195
|
+
def test_empty
|
196
|
+
rewriter = Parser::Source::TreeRewriter.new(@buf)
|
197
|
+
assert_equal true, rewriter.empty?
|
198
|
+
|
199
|
+
# This is a trivial wrap
|
200
|
+
rewriter.wrap(range(2,3), '', '')
|
201
|
+
assert_equal true, rewriter.empty?
|
202
|
+
|
203
|
+
# This is a trivial deletion
|
204
|
+
rewriter.remove(range(2,0))
|
205
|
+
assert_equal true, rewriter.empty?
|
206
|
+
|
207
|
+
rewriter.remove(range(2,3))
|
208
|
+
assert_equal false, rewriter.empty?
|
209
|
+
end
|
210
|
+
|
211
|
+
# splits array into two groups, yield all such possible pairs of groups
|
212
|
+
# each_split([1, 2, 3, 4]) yields [1, 2], [3, 4];
|
213
|
+
# then [1, 3], [2, 4]
|
214
|
+
# ...
|
215
|
+
# and finally [3, 4], [1, 2]
|
216
|
+
def each_split(array)
|
217
|
+
n = array.size
|
218
|
+
first_split_size = n.div(2)
|
219
|
+
splitting = (0...n).to_set
|
220
|
+
splitting.to_a.combination(first_split_size) do |indices|
|
221
|
+
yield array.values_at(*indices),
|
222
|
+
array.values_at(*(splitting - indices))
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
# Checks that `actions+extra` give the same result when
|
227
|
+
# made in order or from subgroups that are later merged.
|
228
|
+
# The `extra` actions are always added at the end of the second group.
|
229
|
+
#
|
230
|
+
def check_all_merge_possibilities(actions, extra, **policy)
|
231
|
+
expected = apply(actions + extra, **policy)
|
232
|
+
|
233
|
+
each_split(actions) do |actions_1, actions_2|
|
234
|
+
build(actions_1, **policy) do |rewriter_1|
|
235
|
+
build(actions_2 + extra, **policy) do |rewriter_2|
|
236
|
+
result = rewriter_1.merge(rewriter_2).process
|
237
|
+
assert_equal(expected, result,
|
238
|
+
"Group 1: #{actions_1.inspect}\n\n" +
|
239
|
+
"Group 2: #{(actions_2 + extra).inspect}"
|
240
|
+
)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_merge
|
247
|
+
check_all_merge_possibilities([
|
248
|
+
[:wrap, @whole, '<', '>'],
|
249
|
+
[:replace, @comma_space, ' => '],
|
250
|
+
[:wrap, @hello, '!', '!'],
|
251
|
+
# Following two wraps must have same value as they
|
252
|
+
# will be applied in different orders...
|
253
|
+
[:wrap, @hello.join(@world), '{', '}'],
|
254
|
+
[:wrap, @hello.join(@world), '{', '}'],
|
255
|
+
[:remove, @ll],
|
256
|
+
[:replace, @world, ':everybody'],
|
257
|
+
[:wrap, @world, '[', ']']
|
258
|
+
],
|
259
|
+
[ # ... but this one is always going to be applied last (extra)
|
260
|
+
[:wrap, @hello.join(@world), '@', '@'],
|
261
|
+
])
|
262
|
+
end
|
173
263
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.7.
|
4
|
+
version: 2.7.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- whitequark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|
@@ -229,6 +229,8 @@ files:
|
|
229
229
|
- lib/parser/ruby26.y
|
230
230
|
- lib/parser/ruby27.rb
|
231
231
|
- lib/parser/ruby27.y
|
232
|
+
- lib/parser/ruby28.rb
|
233
|
+
- lib/parser/ruby28.y
|
232
234
|
- lib/parser/rubymotion.rb
|
233
235
|
- lib/parser/rubymotion.y
|
234
236
|
- lib/parser/runner.rb
|
@@ -242,6 +244,7 @@ files:
|
|
242
244
|
- lib/parser/source/map/condition.rb
|
243
245
|
- lib/parser/source/map/constant.rb
|
244
246
|
- lib/parser/source/map/definition.rb
|
247
|
+
- lib/parser/source/map/endless_definition.rb
|
245
248
|
- lib/parser/source/map/for.rb
|
246
249
|
- lib/parser/source/map/heredoc.rb
|
247
250
|
- lib/parser/source/map/index.rb
|
@@ -297,9 +300,9 @@ licenses:
|
|
297
300
|
- MIT
|
298
301
|
metadata:
|
299
302
|
bug_tracker_uri: https://github.com/whitequark/parser/issues
|
300
|
-
changelog_uri: https://github.com/whitequark/parser/blob/v2.7.
|
301
|
-
documentation_uri: https://www.rubydoc.info/gems/parser/2.7.
|
302
|
-
source_code_uri: https://github.com/whitequark/parser/tree/v2.7.
|
303
|
+
changelog_uri: https://github.com/whitequark/parser/blob/v2.7.1.2/CHANGELOG.md
|
304
|
+
documentation_uri: https://www.rubydoc.info/gems/parser/2.7.1.2
|
305
|
+
source_code_uri: https://github.com/whitequark/parser/tree/v2.7.1.2
|
303
306
|
post_install_message:
|
304
307
|
rdoc_options: []
|
305
308
|
require_paths:
|