ripper_ruby_parser 1.7.0 → 1.7.1
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/CHANGELOG.md +15 -0
- data/README.md +3 -1
- data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +7 -2
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +7 -3
- data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +1 -1
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +1 -0
- data/lib/ripper_ruby_parser/sexp_processor.rb +4 -2
- data/lib/ripper_ruby_parser/unescape.rb +13 -13
- data/lib/ripper_ruby_parser/version.rb +1 -1
- data/test/end_to_end/comparison_test.rb +6 -6
- data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +50 -53
- data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +16 -0
- data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +8 -0
- data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +6 -0
- data/test/samples/assignment.rb +5 -0
- data/test/samples/strings.rb +1 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 943fa1c037a2a2a257d13aed73d33194756f57d0d582207062331f60b5629cd3
|
4
|
+
data.tar.gz: 94fffed38a9e3354a8f9a903add44e26d5bbc8ea599afb72141fbb877f4e2e22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b677389067d2759571fb431a8055a4909b58026c127b43fde51d158e6de48633f423cb88f448a996da0406e2e02ff60e9834a25aeff2c5eb49274e80d63d6558
|
7
|
+
data.tar.gz: 47df66fb3e972978919e3224522957ef7ccc3a430ee09318775efd1191c1d87aaf54432aca181ea36b4abc729847eda1355809e5d785a6e68ea1c2ae15c96968
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.7.1 / 2019-11-03
|
4
|
+
|
5
|
+
* Handle unicode escapes with five or six hex digits ([#94])
|
6
|
+
* Handle safe attribute assignment ([#92])
|
7
|
+
* Handle endless ranges on Ruby 2.6+ ([#90])
|
8
|
+
* Add preliminary support for Ruby 2.7 ([#89])
|
9
|
+
* Improve line number handling for stabby lambdas ([#88])
|
10
|
+
|
3
11
|
## 1.7.0 / 2019-11-01
|
4
12
|
|
5
13
|
* Make results compatible with RubyParser 3.14.0 ([#85])
|
@@ -179,6 +187,13 @@
|
|
179
187
|
* Initial release
|
180
188
|
|
181
189
|
<!-- Pull request links -->
|
190
|
+
[#94]: https://github.com/mvz/ripper_ruby_parser/pull/94
|
191
|
+
[#92]: https://github.com/mvz/ripper_ruby_parser/pull/92
|
192
|
+
[#90]: https://github.com/mvz/ripper_ruby_parser/pull/90
|
193
|
+
[#89]: https://github.com/mvz/ripper_ruby_parser/pull/89
|
194
|
+
[#88]: https://github.com/mvz/ripper_ruby_parser/pull/88
|
195
|
+
[#86]: https://github.com/mvz/ripper_ruby_parser/pull/86
|
196
|
+
[#85]: https://github.com/mvz/ripper_ruby_parser/pull/85
|
182
197
|
[#82]: https://github.com/mvz/ripper_ruby_parser/pull/82
|
183
198
|
[#80]: https://github.com/mvz/ripper_ruby_parser/pull/80
|
184
199
|
[#79]: https://github.com/mvz/ripper_ruby_parser/pull/79
|
data/README.md
CHANGED
@@ -20,6 +20,8 @@ RipperRubyParser has a few incompatibilities with RubyParser.
|
|
20
20
|
* RipperRubyParser won't handle non-UTF-8 files without an encoding comment,
|
21
21
|
just like regular Ruby
|
22
22
|
* RipperRubyParser does not always match RubyParser's line numbering
|
23
|
+
* RipperRubyParser dedents auto-dedenting heredocs
|
24
|
+
* RipperRubyParser does not include postfix comments
|
23
25
|
|
24
26
|
## Install
|
25
27
|
|
@@ -42,7 +44,7 @@ parser.parse "foo[bar] += baz qux"
|
|
42
44
|
|
43
45
|
## Requirements
|
44
46
|
|
45
|
-
* Ruby 2.
|
47
|
+
* Ruby 2.4 or higher
|
46
48
|
* `sexp_processor`
|
47
49
|
|
48
50
|
## Hacking and contributing
|
@@ -150,8 +150,13 @@ module RipperRubyParser
|
|
150
150
|
arglist.shift
|
151
151
|
s(:attrasgn, arr, :[]=, *arglist)
|
152
152
|
when :field
|
153
|
-
_, obj,
|
154
|
-
|
153
|
+
_, obj, call_op, (_, field) = lvalue
|
154
|
+
case call_op
|
155
|
+
when :"&.", s(:op, :"&.") # Handle both 2.5 and 2.6 style ops
|
156
|
+
s(:safe_attrasgn, obj, :"#{field}=", value)
|
157
|
+
else
|
158
|
+
s(:attrasgn, obj, :"#{field}=", value)
|
159
|
+
end
|
155
160
|
else
|
156
161
|
create_assignment_sub_type lvalue, value
|
157
162
|
end
|
@@ -132,12 +132,16 @@ module RipperRubyParser
|
|
132
132
|
|
133
133
|
def process_lambda(exp)
|
134
134
|
_, args, statements = exp.shift 3
|
135
|
+
|
135
136
|
old_type = args.sexp_type
|
136
137
|
args = convert_arguments(process(args))
|
138
|
+
statements = process(statements)
|
139
|
+
line = args.line || statements.line
|
137
140
|
args = nil if args == s(:args) && old_type == :params
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
+
call = s(:lambda)
|
142
|
+
call.line = line
|
143
|
+
|
144
|
+
make_iter call, args, safe_unwrap_void_stmt(statements)
|
141
145
|
end
|
142
146
|
|
143
147
|
private
|
@@ -79,10 +79,12 @@ module RipperRubyParser
|
|
79
79
|
|
80
80
|
def process_stmts(exp)
|
81
81
|
_, *statements = shift_all(exp)
|
82
|
-
statements =
|
82
|
+
statements = map_unwrap_begin_list map_process_list statements
|
83
|
+
line = statements.first.line
|
84
|
+
statements = reject_void_stmt statements
|
83
85
|
case statements.count
|
84
86
|
when 0
|
85
|
-
s(:void_stmt)
|
87
|
+
s(:void_stmt).line(line)
|
86
88
|
when 1
|
87
89
|
statements.first
|
88
90
|
else
|
@@ -7,19 +7,19 @@ module RipperRubyParser
|
|
7
7
|
module Unescape
|
8
8
|
ESCAPE_SEQUENCE_REGEXP =
|
9
9
|
/\\(
|
10
|
-
[0-7]{1,3}
|
11
|
-
x[0-9a-fA-F]{1,2}
|
12
|
-
u[0-9a-fA-F]+
|
13
|
-
u{[0-9a-fA-F]{4}} | # unicode character
|
14
|
-
M-\\C-.
|
15
|
-
C-\\M-.
|
16
|
-
M-\\c.
|
17
|
-
c\\M-.
|
18
|
-
C-.
|
19
|
-
c.
|
20
|
-
M-.
|
21
|
-
\n
|
22
|
-
.
|
10
|
+
[0-7]{1,3} | # octal character
|
11
|
+
x[0-9a-fA-F]{1,2} | # hex byte
|
12
|
+
u[0-9a-fA-F]+ | # unicode character
|
13
|
+
u{[0-9a-fA-F]{4,6}} | # unicode character
|
14
|
+
M-\\C-. | # meta-ctrl
|
15
|
+
C-\\M-. | # ctrl-meta
|
16
|
+
M-\\c. | # meta-ctrl (shorthand)
|
17
|
+
c\\M-. | # ctrl-meta (shorthand)
|
18
|
+
C-. | # control (regular)
|
19
|
+
c. | # control (shorthand)
|
20
|
+
M-. | # meta
|
21
|
+
\n | # line continuation
|
22
|
+
. # single-character
|
23
23
|
)/x.freeze
|
24
24
|
|
25
25
|
SINGLE_LETTER_ESCAPES = {
|
@@ -35,8 +35,8 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
35
35
|
RUBY
|
36
36
|
end
|
37
37
|
|
38
|
-
it "gives the same result" do
|
39
|
-
_(program).must_be_parsed_as_before
|
38
|
+
it "gives the same result with line numbers" do
|
39
|
+
_(program).must_be_parsed_as_before with_line_numbers: true
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -63,8 +63,8 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
63
63
|
RUBY
|
64
64
|
end
|
65
65
|
|
66
|
-
it "gives the same result" do
|
67
|
-
_(program).must_be_parsed_as_before
|
66
|
+
it "gives the same result with line numbers" do
|
67
|
+
_(program).must_be_parsed_as_before with_line_numbers: true
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -87,8 +87,8 @@ describe "Using RipperRubyParser and RubyParser" do
|
|
87
87
|
RUBY
|
88
88
|
end
|
89
89
|
|
90
|
-
it "gives the same result" do
|
91
|
-
_(program).must_be_parsed_as_before
|
90
|
+
it "gives the same result with line numbers" do
|
91
|
+
_(program).must_be_parsed_as_before with_line_numbers: true
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -104,6 +104,14 @@ describe RipperRubyParser::Parser do
|
|
104
104
|
s(:call, nil, :baz))
|
105
105
|
end
|
106
106
|
|
107
|
+
it "works when safe-assigning to an attribute" do
|
108
|
+
_("foo&.bar = baz")
|
109
|
+
.must_be_parsed_as s(:safe_attrasgn,
|
110
|
+
s(:call, nil, :foo),
|
111
|
+
:bar=,
|
112
|
+
s(:call, nil, :baz))
|
113
|
+
end
|
114
|
+
|
107
115
|
describe "when assigning to a class variable" do
|
108
116
|
it "works outside a method" do
|
109
117
|
_("@@foo = bar")
|
@@ -183,65 +191,35 @@ describe RipperRubyParser::Parser do
|
|
183
191
|
end
|
184
192
|
|
185
193
|
it "works with a method call with argument without brackets" do
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
else
|
192
|
-
s(:lasgn, :foo,
|
193
|
-
s(:rescue,
|
194
|
-
s(:call, nil, :bar, s(:call, nil, :baz)),
|
195
|
-
s(:resbody, s(:array), s(:call, nil, :qux))))
|
196
|
-
end
|
197
|
-
_("foo = bar baz rescue qux").must_be_parsed_as expected
|
194
|
+
_("foo = bar baz rescue qux")
|
195
|
+
.must_be_parsed_as s(:lasgn, :foo,
|
196
|
+
s(:rescue,
|
197
|
+
s(:call, nil, :bar, s(:call, nil, :baz)),
|
198
|
+
s(:resbody, s(:array), s(:call, nil, :qux))))
|
198
199
|
end
|
199
200
|
|
200
201
|
it "works with a class method call with argument without brackets" do
|
201
|
-
expected = if RUBY_VERSION < "2.4.0"
|
202
|
-
s(:rescue,
|
203
|
-
s(:lasgn, :foo,
|
204
|
-
s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux))),
|
205
|
-
s(:resbody, s(:array), s(:call, nil, :quuz)))
|
206
|
-
else
|
207
|
-
s(:lasgn, :foo,
|
208
|
-
s(:rescue,
|
209
|
-
s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux)),
|
210
|
-
s(:resbody, s(:array), s(:call, nil, :quuz))))
|
211
|
-
end
|
212
202
|
_("foo = Bar.baz qux rescue quuz")
|
213
|
-
.must_be_parsed_as
|
203
|
+
.must_be_parsed_as s(:lasgn, :foo,
|
204
|
+
s(:rescue,
|
205
|
+
s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux)),
|
206
|
+
s(:resbody, s(:array), s(:call, nil, :quuz))))
|
214
207
|
end
|
215
208
|
|
216
209
|
it "works with a method call with argument without brackets" do
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
else
|
223
|
-
s(:lasgn, :foo,
|
224
|
-
s(:rescue,
|
225
|
-
s(:call, nil, :bar, s(:call, nil, :baz)),
|
226
|
-
s(:resbody, s(:array), s(:call, nil, :qux))))
|
227
|
-
end
|
228
|
-
_("foo = bar baz rescue qux").must_be_parsed_as expected
|
210
|
+
_("foo = bar baz rescue qux")
|
211
|
+
.must_be_parsed_as s(:lasgn, :foo,
|
212
|
+
s(:rescue,
|
213
|
+
s(:call, nil, :bar, s(:call, nil, :baz)),
|
214
|
+
s(:resbody, s(:array), s(:call, nil, :qux))))
|
229
215
|
end
|
230
216
|
|
231
217
|
it "works with a class method call with argument without brackets" do
|
232
|
-
expected = if RUBY_VERSION < "2.4.0"
|
233
|
-
s(:rescue,
|
234
|
-
s(:lasgn, :foo,
|
235
|
-
s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux))),
|
236
|
-
s(:resbody, s(:array), s(:call, nil, :quuz)))
|
237
|
-
else
|
238
|
-
s(:lasgn, :foo,
|
239
|
-
s(:rescue,
|
240
|
-
s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux)),
|
241
|
-
s(:resbody, s(:array), s(:call, nil, :quuz))))
|
242
|
-
end
|
243
218
|
_("foo = Bar.baz qux rescue quuz")
|
244
|
-
.must_be_parsed_as
|
219
|
+
.must_be_parsed_as s(:lasgn, :foo,
|
220
|
+
s(:rescue,
|
221
|
+
s(:call, s(:const, :Bar), :baz, s(:call, nil, :qux)),
|
222
|
+
s(:resbody, s(:array), s(:call, nil, :quuz))))
|
245
223
|
end
|
246
224
|
end
|
247
225
|
|
@@ -285,12 +263,23 @@ describe RipperRubyParser::Parser do
|
|
285
263
|
end
|
286
264
|
|
287
265
|
it "works with a rescue modifier" do
|
266
|
+
expected = if RUBY_VERSION < "2.7.0"
|
267
|
+
s(:rescue,
|
268
|
+
s(:masgn,
|
269
|
+
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
270
|
+
s(:to_ary, s(:call, nil, :baz))),
|
271
|
+
s(:resbody, s(:array), s(:call, nil, :qux)))
|
272
|
+
else
|
273
|
+
s(:masgn,
|
274
|
+
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
275
|
+
s(:to_ary,
|
276
|
+
s(:rescue,
|
277
|
+
s(:call, nil, :baz),
|
278
|
+
s(:resbody, s(:array), s(:call, nil, :qux)))))
|
279
|
+
end
|
280
|
+
|
288
281
|
_("foo, bar = baz rescue qux")
|
289
|
-
.must_be_parsed_as
|
290
|
-
s(:masgn,
|
291
|
-
s(:array, s(:lasgn, :foo), s(:lasgn, :bar)),
|
292
|
-
s(:to_ary, s(:call, nil, :baz))),
|
293
|
-
s(:resbody, s(:array), s(:call, nil, :qux)))
|
282
|
+
.must_be_parsed_as expected
|
294
283
|
end
|
295
284
|
|
296
285
|
it "works the same number of items on each side" do
|
@@ -455,6 +444,14 @@ describe RipperRubyParser::Parser do
|
|
455
444
|
s(:call, nil, :baz),
|
456
445
|
s(:call, nil, :qux))
|
457
446
|
end
|
447
|
+
|
448
|
+
it "handles safe-assigning to an attribute of the collection element" do
|
449
|
+
_("foo[bar]&.baz = qux")
|
450
|
+
.must_be_parsed_as s(:safe_attrasgn,
|
451
|
+
s(:call, s(:call, nil, :foo), :[], s(:call, nil, :bar)),
|
452
|
+
:baz=,
|
453
|
+
s(:call, nil, :qux))
|
454
|
+
end
|
458
455
|
end
|
459
456
|
|
460
457
|
describe "for operator assignment" do
|
@@ -656,6 +656,22 @@ describe RipperRubyParser::Parser do
|
|
656
656
|
s(:call, nil, :bar),
|
657
657
|
s(:call, nil, :baz)))
|
658
658
|
end
|
659
|
+
|
660
|
+
it "sets line numbers correctly for lambdas with empty bodies" do
|
661
|
+
_("->(foo) { }\nbar")
|
662
|
+
.must_be_parsed_as s(:block,
|
663
|
+
s(:iter, s(:lambda).line(1), s(:args, :foo).line(1)).line(1),
|
664
|
+
s(:call, nil, :bar).line(2)).line(1),
|
665
|
+
with_line_numbers: true
|
666
|
+
end
|
667
|
+
|
668
|
+
it "sets line numbers correctly for empty lambdas" do
|
669
|
+
_("->() { }\nfoo")
|
670
|
+
.must_be_parsed_as s(:block,
|
671
|
+
s(:iter, s(:lambda).line(1), s(:args).line(1)).line(1),
|
672
|
+
s(:call, nil, :foo).line(2)).line(1),
|
673
|
+
with_line_numbers: true
|
674
|
+
end
|
659
675
|
end
|
660
676
|
|
661
677
|
describe "for lambda keyword" do
|
@@ -262,6 +262,14 @@ describe RipperRubyParser::Parser do
|
|
262
262
|
_('"foo\\u{273b}bar"').must_be_parsed_as s(:str, "foo✻bar")
|
263
263
|
end
|
264
264
|
|
265
|
+
it "works with unicode escapes with braces with 5 hex chars" do
|
266
|
+
_('"foo\\u{101D1}bar"').must_be_parsed_as s(:str, "foo𐇑bar")
|
267
|
+
end
|
268
|
+
|
269
|
+
it "works with unicode escapes with braces with 6 hex chars" do
|
270
|
+
_('"foo\\u{10FFFF}bar"').must_be_parsed_as s(:str, "foo\u{10FFFF}bar")
|
271
|
+
end
|
272
|
+
|
265
273
|
it "converts to unicode if possible" do
|
266
274
|
_('"2\302\275"').must_be_parsed_as s(:str, "2½")
|
267
275
|
end
|
@@ -227,6 +227,12 @@ describe RipperRubyParser::Parser do
|
|
227
227
|
s(:call, nil, :foo),
|
228
228
|
s(:call, nil, :bar))
|
229
229
|
end
|
230
|
+
|
231
|
+
it "handles endless range literals" do
|
232
|
+
skip "This Ruby version does not support endless ranges" if RUBY_VERSION < "2.6.0"
|
233
|
+
_("1..")
|
234
|
+
.must_be_parsed_as s(:dot2, s(:lit, 1), nil)
|
235
|
+
end
|
230
236
|
end
|
231
237
|
|
232
238
|
describe "for the exclusive range operator" do
|
data/test/samples/assignment.rb
CHANGED
data/test/samples/strings.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripper_ruby_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matijs van Zuijlen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sexp_processor
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.14.
|
61
|
+
version: 3.14.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.14.
|
68
|
+
version: 3.14.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|