ripper_ruby_parser 1.7.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16ae34997256487e8611f1c1128bfa3f0ededad4befbdcba5cae435e957e4382
4
- data.tar.gz: 9751a46aeaa42e05bc52587fa0fee46b64e0b45204b9cbf651f7492d7e6bde90
3
+ metadata.gz: 943fa1c037a2a2a257d13aed73d33194756f57d0d582207062331f60b5629cd3
4
+ data.tar.gz: 94fffed38a9e3354a8f9a903add44e26d5bbc8ea599afb72141fbb877f4e2e22
5
5
  SHA512:
6
- metadata.gz: c31670a8b6d911f7679096feb5d1b01e2c67a7aec7694eb7f4ac932c2f335f24e5996074bd0857614e8f508c093f639d644f3ab4555de97c68f1ea601f4fd586
7
- data.tar.gz: 2668135d139b2c4c5cb3da3f036bc7653896239a48846bbae4fe18056bb751f21e00618c8b2d7b90f3de3e504f4dfb959e442f3f302b253bcf777a0232329950
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.3 or higher
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, _, (_, field) = lvalue
154
- s(:attrasgn, obj, :"#{field}=", value)
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
- make_iter(s(:lambda),
139
- args,
140
- safe_unwrap_void_stmt(process(statements)))
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
@@ -41,7 +41,7 @@ module RipperRubyParser
41
41
  end
42
42
 
43
43
  def integer_literal?(exp)
44
- exp.sexp_type == :lit && exp[1].is_a?(Integer)
44
+ exp && exp.sexp_type == :lit && exp[1].is_a?(Integer)
45
45
  end
46
46
 
47
47
  def reject_void_stmt(body)
@@ -98,6 +98,7 @@ module RipperRubyParser
98
98
  }.freeze
99
99
 
100
100
  def convert_arguments(args)
101
+ args.line ||= args.sexp_body.first&.line
101
102
  args.map! do |item|
102
103
  if item.is_a? Symbol
103
104
  item
@@ -79,10 +79,12 @@ module RipperRubyParser
79
79
 
80
80
  def process_stmts(exp)
81
81
  _, *statements = shift_all(exp)
82
- statements = map_process_list_compact 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} | # 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}} | # 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
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 = {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RipperRubyParser
4
- VERSION = "1.7.0"
4
+ VERSION = "1.7.1"
5
5
  end
@@ -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
- expected = if RUBY_VERSION < "2.4.0"
187
- s(:rescue,
188
- s(:lasgn, :foo,
189
- s(:call, nil, :bar, s(:call, nil, :baz))),
190
- s(:resbody, s(:array), s(:call, nil, :qux)))
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 expected
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
- expected = if RUBY_VERSION < "2.4.0"
218
- s(:rescue,
219
- s(:lasgn, :foo,
220
- s(:call, nil, :bar, s(:call, nil, :baz))),
221
- s(:resbody, s(:array), s(:call, nil, :qux)))
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 expected
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 s(:rescue,
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
@@ -15,3 +15,8 @@ foo, (bar, baz) = qux
15
15
  foo, ((bar, baz)) = qux
16
16
  foo, (((bar, baz))) = qux
17
17
  foo, (bar, (baz, qux)) = quuz
18
+
19
+ # Safe attribute assignment
20
+ foo&.bar = baz
21
+ foo[bar]&.baz = qux
22
+ foo[bar, baz]&.qux = quuz
@@ -14,6 +14,7 @@
14
14
  "#{foo}2\302\275"
15
15
  %W(2\302\275)
16
16
  /2\302\275/
17
+ "foo\u{101D1}bar"
17
18
 
18
19
 
19
20
  # Encoding
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.0
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-01 00:00:00.000000000 Z
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.0
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.0
68
+ version: 3.14.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement