ripper_ruby_parser 1.7.2 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -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/blocks.rb +33 -54
  6. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
  7. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +34 -1
  8. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +1 -1
  9. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +12 -15
  10. data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +21 -15
  11. data/lib/ripper_ruby_parser/sexp_processor.rb +4 -17
  12. data/lib/ripper_ruby_parser/unescape.rb +36 -12
  13. data/lib/ripper_ruby_parser/version.rb +1 -1
  14. metadata +110 -78
  15. data/Rakefile +0 -33
  16. data/test/end_to_end/comments_test.rb +0 -59
  17. data/test/end_to_end/comparison_test.rb +0 -104
  18. data/test/end_to_end/lib_comparison_test.rb +0 -18
  19. data/test/end_to_end/line_numbering_test.rb +0 -31
  20. data/test/end_to_end/samples_comparison_test.rb +0 -13
  21. data/test/end_to_end/test_comparison_test.rb +0 -18
  22. data/test/pt_testcase/pt_test.rb +0 -44
  23. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -200
  24. data/test/ripper_ruby_parser/parser_test.rb +0 -576
  25. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -597
  26. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -717
  27. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
  28. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -165
  29. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
  30. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -237
  31. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -429
  32. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -405
  33. data/test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb +0 -973
  34. data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -327
  35. data/test/ripper_ruby_parser/version_test.rb +0 -7
  36. data/test/samples/assignment.rb +0 -22
  37. data/test/samples/comments.rb +0 -13
  38. data/test/samples/conditionals.rb +0 -23
  39. data/test/samples/lambdas.rb +0 -5
  40. data/test/samples/loops.rb +0 -36
  41. data/test/samples/misc.rb +0 -285
  42. data/test/samples/number.rb +0 -9
  43. data/test/samples/operators.rb +0 -18
  44. data/test/samples/strings.rb +0 -147
  45. data/test/test_helper.rb +0 -111
@@ -135,8 +135,25 @@ module RipperRubyParser
135
135
 
136
136
  list = merge_raw_string_literals list
137
137
  list = map_process_list list
138
+ parts = unpack_dstr list
139
+ merge_initial_string_literals(parts)
140
+ end
141
+
142
+ def merge_raw_string_literals(list)
143
+ chunks = list.chunk { |it| it.sexp_type == :@tstring_content }
144
+ chunks.flat_map do |is_simple, items|
145
+ if is_simple && items.count > 1
146
+ head = items.first
147
+ contents = items.map { |it| it[1] }.join
148
+ [s(:@tstring_content, contents, head[2], head[3])]
149
+ else
150
+ items
151
+ end
152
+ end
153
+ end
138
154
 
139
- parts = list.flat_map do |item|
155
+ def unpack_dstr(list)
156
+ list.flat_map do |item|
140
157
  type, val, *rest = item
141
158
  if type == :dstr
142
159
  if val.empty?
@@ -148,7 +165,9 @@ module RipperRubyParser
148
165
  [item]
149
166
  end
150
167
  end
168
+ end
151
169
 
170
+ def merge_initial_string_literals(parts)
152
171
  string = ""
153
172
  while parts.first&.sexp_type == :str
154
173
  str = parts.shift
@@ -159,19 +178,6 @@ module RipperRubyParser
159
178
  return line, string, parts
160
179
  end
161
180
 
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
181
  def character_flags_to_numerical(flags)
176
182
  numflags = 0
177
183
 
@@ -196,7 +202,7 @@ module RipperRubyParser
196
202
  end
197
203
 
198
204
  def handle_symbol_content(node)
199
- if node.sexp_type == :'@kw'
205
+ if node.sexp_type == :@kw
200
206
  symbol, position = extract_node_symbol_with_position(node)
201
207
  with_position(position, s(:lit, symbol))
202
208
  else
@@ -11,8 +11,7 @@ module RipperRubyParser
11
11
  class SexpProcessor < ::SexpProcessor
12
12
  include Unescape
13
13
 
14
- attr_reader :filename
15
- attr_reader :extra_compatible
14
+ attr_reader :filename, :extra_compatible
16
15
 
17
16
  def initialize(filename: nil, extra_compatible: nil)
18
17
  super()
@@ -68,15 +67,7 @@ module RipperRubyParser
68
67
  statements = map_unwrap_begin_list map_process_list statements
69
68
  line = statements.first.line
70
69
  statements = reject_void_stmt statements
71
- case statements.count
72
- when 0
73
- s(:void_stmt).line(line)
74
- when 1
75
- statements.first
76
- else
77
- first = statements.shift
78
- s(:block, *unwrap_block(first), *statements)
79
- end
70
+ wrap_in_block(statements, line)
80
71
  end
81
72
 
82
73
  def process_var_ref(exp)
@@ -125,11 +116,7 @@ module RipperRubyParser
125
116
  def process_paren(exp)
126
117
  _, body = exp.shift 2
127
118
  result = process body
128
- if result.sexp_type == :void_stmt
129
- s(:nil)
130
- else
131
- result
132
- end
119
+ convert_void_stmt_to_nil_symbol result
133
120
  end
134
121
 
135
122
  def process_comment(exp)
@@ -234,7 +221,7 @@ module RipperRubyParser
234
221
  def class_or_module_body(exp)
235
222
  body = process(exp)
236
223
 
237
- return body if body.empty?
224
+ return [] if body.sexp_type == :void_stmt
238
225
 
239
226
  unwrap_block body
240
227
  end
@@ -95,7 +95,7 @@ module RipperRubyParser
95
95
  when "\n"
96
96
  ""
97
97
  else
98
- '\\\\'
98
+ "\\\\"
99
99
  end
100
100
  end
101
101
  end
@@ -107,24 +107,48 @@ module RipperRubyParser
107
107
  when SINGLE_LETTER_ESCAPES_REGEXP
108
108
  SINGLE_LETTER_ESCAPES[bare]
109
109
  when /^x/
110
- hex_to_char(bare[1..-1])
111
- when /^u\{/
112
- hex_to_unicode_char(bare[2..-2])
110
+ unescape_hex_char bare
113
111
  when /^u/
114
- hex_to_unicode_char(bare[1..4])
115
- when /^(c|C-).$/
116
- control(bare[-1].ord).chr
117
- when /^M-.$/
118
- meta(bare[-1].ord).chr
119
- when /^(M-\\C-|C-\\M-|M-\\c|c\\M-).$/
120
- meta(control(bare[-1].ord)).chr
112
+ unescape_unicode_char bare
113
+ when /^(c|C-|M-|M-\\C-|C-\\M-|M-\\c|c\\M-).$/
114
+ unescape_meta_control bare
121
115
  when /^[0-7]+/
122
- bare.to_i(8).chr
116
+ unescape_octal bare
123
117
  else
124
118
  bare
125
119
  end
126
120
  end
127
121
 
122
+ def unescape_hex_char(bare)
123
+ hex_to_char(bare[1..-1])
124
+ end
125
+
126
+ def unescape_unicode_char(bare)
127
+ hex_chars = if bare.start_with? "u{"
128
+ bare[2..-2]
129
+ else
130
+ bare[1..4]
131
+ end
132
+ hex_to_unicode_char(hex_chars)
133
+ end
134
+
135
+ def unescape_meta_control(bare)
136
+ base_value = bare[-1].ord
137
+ value = case bare
138
+ when /^(c|C-).$/
139
+ control(base_value)
140
+ when /^M-.$/
141
+ meta(base_value)
142
+ when /^(M-\\C-|C-\\M-|M-\\c|c\\M-).$/
143
+ meta(control(base_value))
144
+ end
145
+ value.chr
146
+ end
147
+
148
+ def unescape_octal(bare)
149
+ bare.to_i(8).chr
150
+ end
151
+
128
152
  def hex_to_unicode_char(str)
129
153
  str.to_i(16).chr(Encoding::UTF_8)
130
154
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RipperRubyParser
4
- VERSION = "1.7.2"
4
+ VERSION = "1.8.0"
5
5
  end
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.2
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matijs van Zuijlen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-28 00:00:00.000000000 Z
11
+ date: 2021-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sexp_processor
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.14.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.14.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,37 +66,113 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake-manifest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.15.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.15.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.12.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.12.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-performance
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.11.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.11.0
55
125
  - !ruby/object:Gem::Dependency
56
126
  name: ruby_parser
57
127
  requirement: !ruby/object:Gem::Requirement
58
128
  requirements:
59
129
  - - "~>"
60
130
  - !ruby/object:Gem::Version
61
- version: 3.14.1
131
+ version: 3.16.0
62
132
  type: :development
63
133
  prerelease: false
64
134
  version_requirements: !ruby/object:Gem::Requirement
65
135
  requirements:
66
136
  - - "~>"
67
137
  - !ruby/object:Gem::Version
68
- version: 3.14.1
138
+ version: 3.16.0
69
139
  - !ruby/object:Gem::Dependency
70
- name: simplecov
140
+ name: sexp_processor
71
141
  requirement: !ruby/object:Gem::Requirement
72
142
  requirements:
73
143
  - - ">="
74
144
  - !ruby/object:Gem::Version
75
- version: '0'
145
+ version: 4.13.0
146
+ - - "<"
147
+ - !ruby/object:Gem::Version
148
+ version: '4.16'
76
149
  type: :development
77
150
  prerelease: false
78
151
  version_requirements: !ruby/object:Gem::Requirement
79
152
  requirements:
80
153
  - - ">="
81
154
  - !ruby/object:Gem::Version
82
- version: '0'
83
- description: |2
84
- RipperRubyParser is a parser for Ruby based on Ripper that aims to be a
85
- drop-in replacement for RubyParser.
155
+ version: 4.13.0
156
+ - - "<"
157
+ - !ruby/object:Gem::Version
158
+ version: '4.16'
159
+ - !ruby/object:Gem::Dependency
160
+ name: simplecov
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: 0.21.0
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: 0.21.0
173
+ description: |
174
+ RipperRubyParser is a parser for Ruby based on Ripper that aims to be a
175
+ drop-in replacement for RubyParser.
86
176
  email:
87
177
  - matijs@matijs.net
88
178
  executables: []
@@ -92,7 +182,6 @@ extra_rdoc_files:
92
182
  files:
93
183
  - CHANGELOG.md
94
184
  - README.md
95
- - Rakefile
96
185
  - lib/ripper_ruby_parser.rb
97
186
  - lib/ripper_ruby_parser/commenting_ripper_parser.rb
98
187
  - lib/ripper_ruby_parser/parser.rb
@@ -111,41 +200,14 @@ files:
111
200
  - lib/ripper_ruby_parser/syntax_error.rb
112
201
  - lib/ripper_ruby_parser/unescape.rb
113
202
  - lib/ripper_ruby_parser/version.rb
114
- - test/end_to_end/comments_test.rb
115
- - test/end_to_end/comparison_test.rb
116
- - test/end_to_end/lib_comparison_test.rb
117
- - test/end_to_end/line_numbering_test.rb
118
- - test/end_to_end/samples_comparison_test.rb
119
- - test/end_to_end/test_comparison_test.rb
120
- - test/pt_testcase/pt_test.rb
121
- - test/ripper_ruby_parser/commenting_ripper_parser_test.rb
122
- - test/ripper_ruby_parser/parser_test.rb
123
- - test/ripper_ruby_parser/sexp_handlers/assignment_test.rb
124
- - test/ripper_ruby_parser/sexp_handlers/blocks_test.rb
125
- - test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb
126
- - test/ripper_ruby_parser/sexp_handlers/literals_test.rb
127
- - test/ripper_ruby_parser/sexp_handlers/loops_test.rb
128
- - test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb
129
- - test/ripper_ruby_parser/sexp_handlers/methods_test.rb
130
- - test/ripper_ruby_parser/sexp_handlers/operators_test.rb
131
- - test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb
132
- - test/ripper_ruby_parser/sexp_processor_test.rb
133
- - test/ripper_ruby_parser/version_test.rb
134
- - test/samples/assignment.rb
135
- - test/samples/comments.rb
136
- - test/samples/conditionals.rb
137
- - test/samples/lambdas.rb
138
- - test/samples/loops.rb
139
- - test/samples/misc.rb
140
- - test/samples/number.rb
141
- - test/samples/operators.rb
142
- - test/samples/strings.rb
143
- - test/test_helper.rb
144
203
  homepage: http://www.github.com/mvz/ripper_ruby_parser
145
204
  licenses:
146
205
  - MIT
147
- metadata: {}
148
- post_install_message:
206
+ metadata:
207
+ homepage_uri: http://www.github.com/mvz/ripper_ruby_parser
208
+ source_code_uri: https://github.com/mvz/ripper_ruby_parser
209
+ changelog_uri: https://github.com/mvz/ripper_ruby_parser/blob/master/CHANGELOG.md
210
+ post_install_message:
149
211
  rdoc_options:
150
212
  - "--main"
151
213
  - README.md
@@ -155,45 +217,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
217
  requirements:
156
218
  - - ">="
157
219
  - !ruby/object:Gem::Version
158
- version: 2.4.0
220
+ version: 2.5.0
159
221
  required_rubygems_version: !ruby/object:Gem::Requirement
160
222
  requirements:
161
223
  - - ">="
162
224
  - !ruby/object:Gem::Version
163
225
  version: '0'
164
226
  requirements: []
165
- rubygems_version: 3.1.2
166
- signing_key:
227
+ rubygems_version: 3.2.15
228
+ signing_key:
167
229
  specification_version: 4
168
230
  summary: Parse with Ripper, produce sexps that are compatible with RubyParser.
169
- test_files:
170
- - test/end_to_end/comments_test.rb
171
- - test/end_to_end/comparison_test.rb
172
- - test/end_to_end/lib_comparison_test.rb
173
- - test/end_to_end/line_numbering_test.rb
174
- - test/end_to_end/samples_comparison_test.rb
175
- - test/end_to_end/test_comparison_test.rb
176
- - test/pt_testcase/pt_test.rb
177
- - test/ripper_ruby_parser/commenting_ripper_parser_test.rb
178
- - test/ripper_ruby_parser/parser_test.rb
179
- - test/ripper_ruby_parser/sexp_handlers/assignment_test.rb
180
- - test/ripper_ruby_parser/sexp_handlers/blocks_test.rb
181
- - test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb
182
- - test/ripper_ruby_parser/sexp_handlers/literals_test.rb
183
- - test/ripper_ruby_parser/sexp_handlers/loops_test.rb
184
- - test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb
185
- - test/ripper_ruby_parser/sexp_handlers/methods_test.rb
186
- - test/ripper_ruby_parser/sexp_handlers/operators_test.rb
187
- - test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb
188
- - test/ripper_ruby_parser/sexp_processor_test.rb
189
- - test/ripper_ruby_parser/version_test.rb
190
- - test/samples/assignment.rb
191
- - test/samples/comments.rb
192
- - test/samples/conditionals.rb
193
- - test/samples/lambdas.rb
194
- - test/samples/loops.rb
195
- - test/samples/misc.rb
196
- - test/samples/number.rb
197
- - test/samples/operators.rb
198
- - test/samples/strings.rb
199
- - test/test_helper.rb
231
+ test_files: []