ripper_ruby_parser 1.7.2 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/README.md +4 -4
  4. data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +24 -12
  5. data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +2 -2
  6. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +47 -53
  7. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
  8. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +34 -1
  9. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +1 -1
  10. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +9 -5
  11. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +17 -15
  12. data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +3 -3
  13. data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +24 -28
  14. data/lib/ripper_ruby_parser/sexp_processor.rb +5 -18
  15. data/lib/ripper_ruby_parser/unescape.rb +63 -22
  16. data/lib/ripper_ruby_parser/version.rb +1 -1
  17. metadata +140 -79
  18. data/Rakefile +0 -33
  19. data/test/end_to_end/comments_test.rb +0 -59
  20. data/test/end_to_end/comparison_test.rb +0 -104
  21. data/test/end_to_end/lib_comparison_test.rb +0 -18
  22. data/test/end_to_end/line_numbering_test.rb +0 -31
  23. data/test/end_to_end/samples_comparison_test.rb +0 -13
  24. data/test/end_to_end/test_comparison_test.rb +0 -18
  25. data/test/pt_testcase/pt_test.rb +0 -44
  26. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -200
  27. data/test/ripper_ruby_parser/parser_test.rb +0 -576
  28. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -597
  29. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -717
  30. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
  31. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -165
  32. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
  33. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -237
  34. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -429
  35. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -405
  36. data/test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb +0 -973
  37. data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -327
  38. data/test/ripper_ruby_parser/version_test.rb +0 -7
  39. data/test/samples/assignment.rb +0 -22
  40. data/test/samples/comments.rb +0 -13
  41. data/test/samples/conditionals.rb +0 -23
  42. data/test/samples/lambdas.rb +0 -5
  43. data/test/samples/loops.rb +0 -36
  44. data/test/samples/misc.rb +0 -285
  45. data/test/samples/number.rb +0 -9
  46. data/test/samples/operators.rb +0 -18
  47. data/test/samples/strings.rb +0 -147
  48. data/test/test_helper.rb +0 -111
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d4b6b4c9b802cf538662716b22a68c98d26af9dd0fba04aa72c53515d869738
4
- data.tar.gz: e34339faf0080e288368618bd0688525e253300c25883fc74b8f86adfd572f9b
3
+ metadata.gz: a110a987032924880be79cfbb79948e14f90868e8105055a0833284a6f939731
4
+ data.tar.gz: f38c7fa39cb0f1f6fc78cbe72956c77fe15fe74fe99507a3bd59d057618aed0a
5
5
  SHA512:
6
- metadata.gz: 1262aa2a0cb8b14e99650b8e49f1f1cf4ba672c59ed662b46204c0fcbd1d83580681d3b16440047b29dbc542a8c3dc2bd794071d32e09290a51a4fa4c6180476
7
- data.tar.gz: aedb6d0c231afd60183a0cf1152f34c5cc14ec088a22360d63ae4d3aacb50d2e8bc07548e8617611086ed1eddfa1ebb4c6d9aeb12f2093ad6d677e86e2ee363f
6
+ metadata.gz: 7bf9631eb8941e2ed07ec265519ce8860f9d417cb224b2bbd1bbb8b32277374d76936be126c7893f73bcbcaa1414a25d4ca2280c9e0e701462cdbf5d34c3c77f
7
+ data.tar.gz: e517b02e7854fc644763932d8935dd5b145e2c7c4546874b419932a1d0f0d53b523cba356949f5b941e1fe6405c5b308cade8c42ba3d02078a8e7abe5df176a6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ Notable changes to this project will be documented in this file.
4
+
5
+ This project adheres to [Semantic Versioning 2.0.0][1].
6
+
7
+ This document is formatted based on [Keep A CHANGELOG][2].
8
+
9
+ ## 1.10.0 / 2022-03-13
10
+
11
+ * Handle shadow arguments ([#161])
12
+ * Drop support for Ruby 2.5 ([#165])
13
+ * Support running on Ruby 3.1([#180])
14
+
15
+ ## 1.9.0 / 2021-08-10
16
+
17
+ * Fix escape sequence handling in non-interpolating strings and word lists
18
+ ([#152])
19
+ * Handle strings with mixed valid and invalid utf8 ([#153])
20
+ * Handle argument forwarding, updating the RubyParser compatibility target to
21
+ 3.17.0 ([#154])
22
+ * Fix encoding for non-interpolating strings as well ([#155])
23
+
24
+ ## 1.8.0 / 2021-05-18
25
+
26
+ ### Changes
27
+
28
+ * Drop support for Ruby 2.4 ([2cf6b4050] and [#145])
29
+ * Update RubyParser compatibility target to 3.15.0 ([#105])
30
+ * Fix handling of dedented heredoc ([#106])
31
+ * Add support for running on Ruby 3.0 ([#123])
32
+ * Various code improvements and other internal changes
33
+
3
34
  ## 1.7.2 / 2020-02-28
4
35
 
5
36
  ### Bug fixes
@@ -201,6 +232,17 @@
201
232
  * Initial release
202
233
 
203
234
  <!-- Pull request links -->
235
+ [#180]: https://github.com/mvz/ripper_ruby_parser/pull/180
236
+ [#165]: https://github.com/mvz/ripper_ruby_parser/pull/165
237
+ [#161]: https://github.com/mvz/ripper_ruby_parser/pull/161
238
+ [#155]: https://github.com/mvz/ripper_ruby_parser/pull/155
239
+ [#154]: https://github.com/mvz/ripper_ruby_parser/pull/154
240
+ [#153]: https://github.com/mvz/ripper_ruby_parser/pull/153
241
+ [#152]: https://github.com/mvz/ripper_ruby_parser/pull/152
242
+ [#145]: https://github.com/mvz/ripper_ruby_parser/pull/145
243
+ [#123]: https://github.com/mvz/ripper_ruby_parser/pull/123
244
+ [#106]: https://github.com/mvz/ripper_ruby_parser/pull/106
245
+ [#105]: https://github.com/mvz/ripper_ruby_parser/pull/105
204
246
  [#101]: https://github.com/mvz/ripper_ruby_parser/pull/101
205
247
  [#100]: https://github.com/mvz/ripper_ruby_parser/pull/100
206
248
  [#99]: https://github.com/mvz/ripper_ruby_parser/pull/99
@@ -231,3 +273,11 @@
231
273
  [#67]: https://github.com/mvz/ripper_ruby_parser/pull/67
232
274
  [#66]: https://github.com/mvz/ripper_ruby_parser/pull/66
233
275
  [#65]: https://github.com/mvz/ripper_ruby_parser/pull/65
276
+
277
+ <!-- Git sha links -->
278
+ [2cf6b4050]: https://github.com/mvz/ripper_ruby_parser/commit/2cf6b40501576003b916196e23222276b51aa53c
279
+
280
+ <!-- Other links -->
281
+
282
+ [1]: https://semver.org/spec/v2.0.0.html
283
+ [2]: https://keepachangelog.com/en/1.0.0/
data/README.md CHANGED
@@ -10,8 +10,8 @@ Parse with Ripper, produce sexps that are compatible with RubyParser.
10
10
 
11
11
  * Drop-in replacement for RubyParser
12
12
  * Should handle 1.9 and later syntax gracefully
13
- * Requires Ruby 2.4 or higher
14
- * Compatible with RubyParser 3.14.0
13
+ * Requires Ruby 2.6 or higher
14
+ * Compatible with RubyParser 3.18.0
15
15
 
16
16
  ## Known incompatibilities
17
17
 
@@ -44,7 +44,7 @@ parser.parse "foo[bar] += baz qux"
44
44
 
45
45
  ## Requirements
46
46
 
47
- * Ruby 2.4 or higher
47
+ * Ruby 2.5 or higher
48
48
  * `sexp_processor`
49
49
 
50
50
  ## Hacking and contributing
@@ -64,7 +64,7 @@ If you want to send pull requests or patches, please:
64
64
 
65
65
  (The MIT License)
66
66
 
67
- Copyright (c) 2012, 2014-2019 Matijs van Zuijlen
67
+ Copyright (c) 2012, 2014-2022 Matijs van Zuijlen
68
68
 
69
69
  Permission is hereby granted, free of charge, to any person obtaining
70
70
  a copy of this software and associated documentation files (the
@@ -27,6 +27,8 @@ module RipperRubyParser
27
27
  Sexp.from_array(result)
28
28
  end
29
29
 
30
+ private
31
+
30
32
  def on_backtick(delimiter)
31
33
  @delimiter_stack.push delimiter
32
34
  super
@@ -101,6 +103,18 @@ module RipperRubyParser
101
103
  @delimiter_stack.push delimiter
102
104
  end
103
105
 
106
+ def on_heredoc_dedent(val, width)
107
+ next_dedent = true
108
+ val.map! do |e|
109
+ if e.is_a?(Array) && e[0] == :@tstring_content
110
+ e = dedent_element(e, width) if next_dedent
111
+ next_dedent = e[1].end_with? "\n"
112
+ end
113
+ e
114
+ end
115
+ val
116
+ end
117
+
104
118
  def on_heredoc_end(_delimiter)
105
119
  @delimiter_stack.pop
106
120
  end
@@ -293,28 +307,26 @@ module RipperRubyParser
293
307
  commentize(:END, super)
294
308
  end
295
309
 
296
- def on_parse_error(*args)
297
- raise SyntaxError, *args
310
+ def on_parse_error(message)
311
+ raise SyntaxError, message
298
312
  end
299
313
 
300
- def on_class_name_error(*args)
301
- raise SyntaxError, *args
314
+ def on_class_name_error(message, *)
315
+ raise SyntaxError, message
302
316
  end
303
317
 
304
- def on_alias_error(*args)
305
- raise SyntaxError, *args
318
+ def on_alias_error(message, *)
319
+ raise SyntaxError, message
306
320
  end
307
321
 
308
- def on_assign_error(*args)
309
- raise SyntaxError, *args
322
+ def on_assign_error(message, *)
323
+ raise SyntaxError, message
310
324
  end
311
325
 
312
- def on_param_error(*args)
313
- raise SyntaxError, *args
326
+ def on_param_error(message, *)
327
+ raise SyntaxError, message
314
328
  end
315
329
 
316
- private
317
-
318
330
  def commentize(_name, exp)
319
331
  (_, _kw, loc), comment = @comment_stack.pop
320
332
  @comment = ""
@@ -118,8 +118,8 @@ module RipperRubyParser
118
118
  end
119
119
 
120
120
  OPERATOR_ASSIGNMENT_MAP = {
121
- '||': :op_asgn_or,
122
- '&&': :op_asgn_and
121
+ "||": :op_asgn_or,
122
+ "&&": :op_asgn_and
123
123
  }.freeze
124
124
 
125
125
  def create_operator_assignment_sub_type(lvalue, value, operator)
@@ -14,16 +14,20 @@ module RipperRubyParser
14
14
  make_iter call, args, safe_unwrap_void_stmt(stmt)
15
15
  end
16
16
 
17
+ # NOTE: Argument forwarding is handled differently in Ruby 3.0 and 3.1
18
+ # 3.0: s(:params, nil, nil, s(:args_forward), nil, nil, nil, nil)
19
+ # 3.1: s(:params, nil, nil, nil, nil, nil, s(:args_forward), :&)
17
20
  def process_params(exp)
18
21
  _, normal, defaults, splat, rest, kwargs, doublesplat, block = exp.shift 8
19
22
 
20
- args = handle_normal_arguments normal
21
- args += handle_default_arguments defaults
22
- args += handle_splat splat
23
- args += handle_normal_arguments rest
24
- args += handle_kwargs kwargs
25
- args += handle_double_splat doublesplat
26
- args += handle_block_argument block
23
+ args =
24
+ handle_normal_arguments(normal) +
25
+ handle_default_arguments(defaults) +
26
+ handle_splat(splat) +
27
+ handle_normal_arguments(rest) +
28
+ handle_kwargs(kwargs) +
29
+ handle_double_splat(doublesplat) +
30
+ handle_block_argument(block)
27
31
 
28
32
  s(:args, *args)
29
33
  end
@@ -39,17 +43,22 @@ module RipperRubyParser
39
43
  end
40
44
 
41
45
  def process_block_var(exp)
42
- _, args, = exp.shift 3
46
+ _, args, shadowargs = exp.shift 3
43
47
 
44
48
  names = process(args)
45
49
 
50
+ if shadowargs
51
+ shadowargs = map_process_list(shadowargs).map { |item| item[1] }
52
+ names << s(:shadow, *shadowargs)
53
+ end
54
+
46
55
  convert_arguments names
47
56
  end
48
57
 
49
58
  def process_begin(exp)
50
59
  _, body, pos = exp.shift 3
51
60
 
52
- body = convert_empty_to_nil_symbol process(body)
61
+ body = convert_void_stmt_to_nil_symbol process(body)
53
62
  with_position pos, s(:begin, body)
54
63
  end
55
64
 
@@ -58,19 +67,7 @@ module RipperRubyParser
58
67
  rescue_block = map_process_list_compact block.sexp_body
59
68
  rescue_block << nil if rescue_block.empty?
60
69
 
61
- capture = if eclass.nil?
62
- s(:array)
63
- elsif eclass.first.is_a? Symbol
64
- eclass = process(eclass)
65
- body = eclass.sexp_body
66
- if eclass.sexp_type == :mrhs
67
- body.first
68
- else
69
- s(:array, *body)
70
- end
71
- else
72
- s(:array, process(eclass.first))
73
- end
70
+ capture = handle_rescue_class_list eclass
74
71
 
75
72
  capture << create_assignment_sub_type(process(evar), s(:gvar, :$!)) if evar
76
73
 
@@ -80,23 +77,22 @@ module RipperRubyParser
80
77
  def process_bodystmt(exp)
81
78
  _, main, rescue_block, else_block, ensure_block = exp.shift 5
82
79
 
83
- body = s()
80
+ body_list = []
84
81
 
85
- main_list = map_unwrap_begin_list map_process_list main.sexp_body
86
- line = main_list.first.line
87
- main = wrap_in_block reject_void_stmt main_list
88
- body << main if main
82
+ main_block = process(main)
83
+ line = main_block.line
84
+ body_list << main_block if main_block.sexp_type != :void_stmt
89
85
 
90
- body.push(*process(rescue_block)) if rescue_block
91
- body << process(else_block) if else_block
92
- body = s(s(:rescue, *body)) if rescue_block
86
+ body_list.push(*process(rescue_block)) if rescue_block
87
+ body_list << process(else_block) if else_block
88
+ body_list = [s(:rescue, *body_list)] if rescue_block
93
89
 
94
90
  if ensure_block
95
- body << process(ensure_block)
96
- body = s(s(:ensure, *body))
91
+ body_list << process(ensure_block)
92
+ body_list = [s(:ensure, *body_list)]
97
93
  end
98
94
 
99
- wrap_in_block(body) || s().line(line)
95
+ wrap_in_block(body_list, line)
100
96
  end
101
97
 
102
98
  def process_rescue_mod(exp)
@@ -189,26 +185,35 @@ module RipperRubyParser
189
185
  def handle_double_splat(doublesplat)
190
186
  return [] unless doublesplat
191
187
 
192
- # Anonymous kwrest arguments are parsed into an Integer in Ruby 2.4
193
- if RUBY_VERSION < "2.5.0" && doublesplat.is_a?(Integer)
194
- [s(:dsplat, s(:lvar, :""))]
188
+ contents = process(doublesplat)
189
+ case contents.sexp_type
190
+ when :forward_args # Argument forwarding in Ruby 3.1
191
+ [contents]
195
192
  else
196
- [s(:dsplat, process(doublesplat))]
193
+ [s(:dsplat, contents)]
197
194
  end
198
195
  end
199
196
 
200
197
  def handle_block_argument(block)
201
198
  return [] unless block
199
+ return [] if block == :& # Part of argument forwarding in Ruby 3.1; ignore
202
200
 
203
201
  [process(block)]
204
202
  end
205
203
 
206
- def convert_empty_to_nil_symbol(block)
207
- case block.length
208
- when 0
209
- s(:nil)
204
+ def handle_rescue_class_list(eclass)
205
+ if eclass.nil?
206
+ s(:array)
207
+ elsif eclass.first.is_a? Symbol
208
+ eclass = process(eclass)
209
+ body = eclass.sexp_body
210
+ if eclass.sexp_type == :mrhs
211
+ body.first
212
+ else
213
+ s(:array, *body)
214
+ end
210
215
  else
211
- block
216
+ s(:array, process(eclass.first))
212
217
  end
213
218
  end
214
219
 
@@ -221,17 +226,6 @@ module RipperRubyParser
221
226
  s(:iter, call, args, stmt)
222
227
  end
223
228
  end
224
-
225
- def wrap_in_block(statements)
226
- case statements.length
227
- when 0
228
- nil
229
- when 1
230
- statements.first
231
- else
232
- s(:block, *statements)
233
- end
234
- end
235
229
  end
236
230
  end
237
231
  end
@@ -47,33 +47,20 @@ module RipperRubyParser
47
47
 
48
48
  def process_case(exp)
49
49
  _, expr, clauses = exp.shift 3
50
- s(:case, process(expr), *process(clauses))
50
+ s(:case, process(expr), *process(clauses).sexp_body)
51
51
  end
52
52
 
53
53
  def process_when(exp)
54
54
  _, values, truepart, falsepart = exp.shift 4
55
55
 
56
- falsepart = process(falsepart)
57
- falsepart = unwrap_nil falsepart if falsepart
58
-
59
- if falsepart.nil?
60
- falsepart = [nil]
61
- elsif falsepart.first.is_a? Symbol
62
- falsepart = s(falsepart)
63
- end
56
+ falsepart ||= s(:void_stmt)
64
57
 
58
+ falsepart = unwrap_case_body process(falsepart)
65
59
  values = process(values).sexp_body
60
+ truepart = unwrap_block process(truepart)
66
61
 
67
- truepart = map_process_list_compact truepart.sexp_body
68
- truepart = if truepart.empty?
69
- [nil]
70
- else
71
- unwrap_block(truepart.shift) + truepart
72
- end
73
-
74
- s(s(:when,
75
- s(:array, *values),
76
- *truepart),
62
+ s(:case_body,
63
+ s(:when, s(:array, *values), *truepart),
77
64
  *falsepart)
78
65
  end
79
66
 
@@ -109,6 +96,17 @@ module RipperRubyParser
109
96
  s(:if, cond, truepart, falsepart)
110
97
  end
111
98
  end
99
+
100
+ def unwrap_case_body(exp)
101
+ case exp.sexp_type
102
+ when :case_body
103
+ exp.sexp_body
104
+ when :void_stmt
105
+ [nil]
106
+ else
107
+ [exp]
108
+ end
109
+ end
112
110
  end
113
111
  end
114
112
  end
@@ -81,13 +81,46 @@ module RipperRubyParser
81
81
  end
82
82
 
83
83
  def unwrap_block(exp)
84
- if exp.sexp_type == :block
84
+ case exp.sexp_type
85
+ when :block
85
86
  exp.sexp_body
87
+ when :void_stmt
88
+ [nil]
86
89
  else
87
90
  [exp]
88
91
  end
89
92
  end
90
93
 
94
+ def wrap_in_block(statements, line)
95
+ case statements.length
96
+ when 0
97
+ s(:void_stmt).line(line)
98
+ when 1
99
+ statements.first
100
+ else
101
+ first = statements.shift
102
+ s(:block, *unwrap_block(first), *statements)
103
+ end
104
+ end
105
+
106
+ def convert_void_stmt_to_nil_symbol(block)
107
+ case block.sexp_type
108
+ when :void_stmt
109
+ s(:nil)
110
+ else
111
+ block
112
+ end
113
+ end
114
+
115
+ def convert_empty_to_nil_symbol(block)
116
+ case block.length
117
+ when 0
118
+ s(:nil)
119
+ else
120
+ block
121
+ end
122
+ end
123
+
91
124
  def handle_return_argument_list(arglist)
92
125
  args = process(arglist).sexp_body
93
126
 
@@ -7,7 +7,7 @@ module RipperRubyParser
7
7
  # character literals
8
8
  def process_at_CHAR(exp)
9
9
  _, val, pos = exp.shift 3
10
- with_position(pos, s(:str, unescape(val[1..-1])))
10
+ with_position(pos, s(:str, fix_encoding(unescape(val[1..]))))
11
11
  end
12
12
 
13
13
  def process_array(exp)
@@ -17,7 +17,7 @@ module RipperRubyParser
17
17
 
18
18
  def process_arg_paren(exp)
19
19
  _, args = exp.shift 2
20
- return s() if args.nil?
20
+ return s(:arglist) if args.nil?
21
21
 
22
22
  process(args)
23
23
  end
@@ -26,7 +26,11 @@ module RipperRubyParser
26
26
  _, call, parens = exp.shift 3
27
27
  call = process(call)
28
28
  parens = process(parens)
29
- call.push(*parens.sexp_body)
29
+ if parens.sexp_type == :forward_args
30
+ call.push(parens)
31
+ else
32
+ call.push(*parens.sexp_body)
33
+ end
30
34
  end
31
35
 
32
36
  # Handle implied hashes, such as at the end of argument lists.
@@ -36,9 +40,9 @@ module RipperRubyParser
36
40
  end
37
41
 
38
42
  CALL_OP_MAP = {
39
- '.': :call,
40
- '::': :call,
41
- '&.': :safe_call
43
+ ".": :call,
44
+ "::": :call,
45
+ "&.": :safe_call
42
46
  }.freeze
43
47
 
44
48
  def process_call(exp)
@@ -72,6 +72,11 @@ module RipperRubyParser
72
72
  s(:alias, process(left), process(right))
73
73
  end
74
74
 
75
+ def process_args_forward(exp)
76
+ _ = exp.shift
77
+ s(:forward_args)
78
+ end
79
+
75
80
  private
76
81
 
77
82
  def in_method
@@ -83,8 +88,8 @@ module RipperRubyParser
83
88
 
84
89
  def method_body(exp)
85
90
  block = process exp
86
- case block.length
87
- when 0
91
+ case block.sexp_type
92
+ when :void_stmt
88
93
  [s(:nil).line(block.line)]
89
94
  else
90
95
  unwrap_block block
@@ -99,23 +104,20 @@ module RipperRubyParser
99
104
 
100
105
  def convert_arguments(args)
101
106
  args.line ||= args.sexp_body.first&.line
102
- args.map! { |item| convert_argument item }
107
+ args.sexp_body = args.sexp_body.map { |item| convert_argument item }
108
+ args
103
109
  end
104
110
 
105
111
  def convert_argument(item)
106
- if item.is_a? Symbol
107
- item
112
+ case item.sexp_type
113
+ when :lvar
114
+ item.last
115
+ when *SPECIAL_ARG_MARKER.keys
116
+ convert_marked_argument(item)
117
+ when :masgn
118
+ convert_masgn_argument(item)
108
119
  else
109
- case item.sexp_type
110
- when :lvar
111
- item.last
112
- when *SPECIAL_ARG_MARKER.keys
113
- convert_marked_argument(item)
114
- when :masgn
115
- convert_masgn_argument(item)
116
- else
117
- item
118
- end
120
+ item
119
121
  end
120
122
  end
121
123
 
@@ -5,8 +5,8 @@ module RipperRubyParser
5
5
  # Sexp handlers for operators
6
6
  module Operators
7
7
  BINARY_OPERATOR_MAP = {
8
- '&&': :and,
9
- '||': :or,
8
+ "&&": :and,
9
+ "||": :or,
10
10
  and: :and,
11
11
  or: :or
12
12
  }.freeze
@@ -16,7 +16,7 @@ module RipperRubyParser
16
16
  }.freeze
17
17
 
18
18
  NEGATED_BINARY_OPERATOR_MAP = {
19
- '!~': :=~
19
+ "!~": :=~
20
20
  }.freeze
21
21
 
22
22
  SHIFT_OPERATORS = [:<<, :>>].freeze
@@ -123,8 +123,7 @@ module RipperRubyParser
123
123
 
124
124
  def process_at_tstring_content(exp)
125
125
  _, content, pos, delim = exp.shift 4
126
- string = handle_string_unescaping(content, delim)
127
- string = handle_string_encoding(string, delim)
126
+ string = fix_encoding handle_string_unescaping(content, delim)
128
127
  with_position(pos, s(:str, string))
129
128
  end
130
129
 
@@ -135,8 +134,25 @@ module RipperRubyParser
135
134
 
136
135
  list = merge_raw_string_literals list
137
136
  list = map_process_list list
137
+ parts = unpack_dstr list
138
+ merge_initial_string_literals(parts)
139
+ end
138
140
 
139
- parts = list.flat_map do |item|
141
+ def merge_raw_string_literals(list)
142
+ chunks = list.chunk { |it| it.sexp_type == :@tstring_content }
143
+ chunks.flat_map do |is_simple, items|
144
+ if is_simple && items.count > 1
145
+ head = items.first
146
+ contents = items.map { |it| it[1] }.join
147
+ [s(:@tstring_content, contents, head[2], head[3])]
148
+ else
149
+ items
150
+ end
151
+ end
152
+ end
153
+
154
+ def unpack_dstr(list)
155
+ list.flat_map do |item|
140
156
  type, val, *rest = item
141
157
  if type == :dstr
142
158
  if val.empty?
@@ -148,7 +164,9 @@ module RipperRubyParser
148
164
  [item]
149
165
  end
150
166
  end
167
+ end
151
168
 
169
+ def merge_initial_string_literals(parts)
152
170
  string = ""
153
171
  while parts.first&.sexp_type == :str
154
172
  str = parts.shift
@@ -159,19 +177,6 @@ module RipperRubyParser
159
177
  return line, string, parts
160
178
  end
161
179
 
162
- def merge_raw_string_literals(list)
163
- chunks = list.chunk { |it| it.sexp_type == :@tstring_content }
164
- chunks.flat_map do |is_simple, items|
165
- if is_simple && items.count > 1
166
- head = items.first
167
- contents = items.map { |it| it[1] }.join
168
- [s(:@tstring_content, contents, head[2], head[3])]
169
- else
170
- items
171
- end
172
- end
173
- end
174
-
175
180
  def character_flags_to_numerical(flags)
176
181
  numflags = 0
177
182
 
@@ -196,7 +201,7 @@ module RipperRubyParser
196
201
  end
197
202
 
198
203
  def handle_symbol_content(node)
199
- if node.sexp_type == :'@kw'
204
+ if node.sexp_type == :@kw
200
205
  symbol, position = extract_node_symbol_with_position(node)
201
206
  with_position(position, s(:lit, symbol))
202
207
  else
@@ -237,24 +242,15 @@ module RipperRubyParser
237
242
  when INTERPOLATING_WORD_LIST
238
243
  unescape_wordlist_word(content)
239
244
  when *NON_INTERPOLATING_STRINGS
240
- simple_unescape(content)
245
+ simple_unescape(content, delim)
241
246
  when *REGEXP_LITERALS
242
247
  unescape_regexp(content)
243
248
  when NON_INTERPOLATING_WORD_LIST
244
- simple_unescape_wordlist_word(content)
249
+ simple_unescape_wordlist_word(content, delim)
245
250
  else
246
251
  content
247
252
  end
248
253
  end
249
-
250
- def handle_string_encoding(string, delim)
251
- case delim
252
- when INTERPOLATING_HEREDOC, INTERPOLATING_WORD_LIST, *INTERPOLATING_STRINGS
253
- fix_encoding string
254
- else
255
- string
256
- end
257
- end
258
254
  end
259
255
  end
260
256
  end