ripper_ruby_parser 1.6.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +86 -0
  3. data/README.md +8 -25
  4. data/lib/ripper_ruby_parser.rb +2 -2
  5. data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +54 -23
  6. data/lib/ripper_ruby_parser/parser.rb +3 -3
  7. data/lib/ripper_ruby_parser/sexp_handlers.rb +11 -9
  8. data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +10 -11
  9. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +48 -63
  10. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
  11. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +35 -2
  12. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +15 -242
  13. data/lib/ripper_ruby_parser/sexp_handlers/loops.rb +4 -2
  14. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +1 -1
  15. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +24 -24
  16. data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +266 -0
  17. data/lib/ripper_ruby_parser/sexp_processor.rb +47 -78
  18. data/lib/ripper_ruby_parser/unescape.rb +79 -50
  19. data/lib/ripper_ruby_parser/version.rb +1 -1
  20. metadata +115 -78
  21. data/Rakefile +0 -33
  22. data/test/end_to_end/comments_test.rb +0 -59
  23. data/test/end_to_end/comparison_test.rb +0 -104
  24. data/test/end_to_end/lib_comparison_test.rb +0 -29
  25. data/test/end_to_end/line_numbering_test.rb +0 -64
  26. data/test/end_to_end/samples_comparison_test.rb +0 -13
  27. data/test/end_to_end/test_comparison_test.rb +0 -32
  28. data/test/pt_testcase/pt_test.rb +0 -44
  29. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -190
  30. data/test/ripper_ruby_parser/parser_test.rb +0 -469
  31. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -649
  32. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -661
  33. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
  34. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -1117
  35. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
  36. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -267
  37. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -427
  38. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -399
  39. data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -303
  40. data/test/ripper_ruby_parser/version_test.rb +0 -7
  41. data/test/samples/assignment.rb +0 -17
  42. data/test/samples/comments.rb +0 -13
  43. data/test/samples/conditionals.rb +0 -23
  44. data/test/samples/loops.rb +0 -36
  45. data/test/samples/misc.rb +0 -278
  46. data/test/samples/number.rb +0 -7
  47. data/test/samples/operators.rb +0 -18
  48. data/test/samples/strings.rb +0 -140
  49. data/test/test_helper.rb +0 -79
@@ -7,61 +7,66 @@ 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]{4} | # 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 break
22
+ . # other single character
23
23
  )/x.freeze
24
24
 
25
25
  SINGLE_LETTER_ESCAPES = {
26
- 'a' => "\a",
27
- 'b' => "\b",
28
- 'e' => "\e",
29
- 'f' => "\f",
30
- 'n' => "\n",
31
- 'r' => "\r",
32
- 's' => "\s",
33
- 't' => "\t",
34
- 'v' => "\v"
26
+ "a" => "\a",
27
+ "b" => "\b",
28
+ "e" => "\e",
29
+ "f" => "\f",
30
+ "n" => "\n",
31
+ "r" => "\r",
32
+ "s" => "\s",
33
+ "t" => "\t",
34
+ "v" => "\v"
35
35
  }.freeze
36
36
 
37
37
  SINGLE_LETTER_ESCAPES_REGEXP =
38
38
  Regexp.new("^[#{SINGLE_LETTER_ESCAPES.keys.join}]$")
39
39
 
40
40
  def simple_unescape(string)
41
- string.gsub(/\\(
42
- ' | # single quote
43
- \\ # backslash
44
- )/x) do
45
- Regexp.last_match[1]
46
- end
41
+ string.gsub(/
42
+ \\ # a backslash
43
+ ( # followed by a
44
+ ' | # single quote or
45
+ \\ # backslash
46
+ )/x) do
47
+ Regexp.last_match[1]
48
+ end
47
49
  end
48
50
 
49
51
  def simple_unescape_wordlist_word(string)
50
- string.gsub(/\\(
51
- ' | # single quote
52
- \\ | # backslash
53
- [ ] | # space
54
- \n # newline
55
- )/x) do
56
- Regexp.last_match[1]
57
- end
52
+ string.gsub(/
53
+ \\ # a backslash
54
+ ( # followed by a
55
+ ' | # single quote or
56
+ \\ | # backslash or
57
+ [ ] | # space or
58
+ \n # newline
59
+ )
60
+ /x) do
61
+ Regexp.last_match[1]
62
+ end
58
63
  end
59
64
 
60
65
  def unescape(string)
61
66
  string.gsub(ESCAPE_SEQUENCE_REGEXP) do
62
67
  bare = Regexp.last_match[1]
63
68
  if bare == "\n"
64
- ''
69
+ ""
65
70
  else
66
71
  unescaped_value(bare)
67
72
  end
@@ -88,9 +93,9 @@ module RipperRubyParser
88
93
  bare = Regexp.last_match[1]
89
94
  case bare
90
95
  when "\n"
91
- ''
96
+ ""
92
97
  else
93
- '\\\\'
98
+ "\\\\"
94
99
  end
95
100
  end
96
101
  end
@@ -102,24 +107,48 @@ module RipperRubyParser
102
107
  when SINGLE_LETTER_ESCAPES_REGEXP
103
108
  SINGLE_LETTER_ESCAPES[bare]
104
109
  when /^x/
105
- hex_to_char(bare[1..-1])
106
- when /^u\{/
107
- hex_to_unicode_char(bare[2..-2])
110
+ unescape_hex_char bare
108
111
  when /^u/
109
- hex_to_unicode_char(bare[1..4]) + bare[5..-1]
110
- when /^(c|C-).$/
111
- control(bare[-1].ord).chr
112
- when /^M-.$/
113
- meta(bare[-1].ord).chr
114
- when /^(M-\\C-|C-\\M-|M-\\c|c\\M-).$/
115
- 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
116
115
  when /^[0-7]+/
117
- bare.to_i(8).chr
116
+ unescape_octal bare
118
117
  else
119
118
  bare
120
119
  end
121
120
  end
122
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
+
123
152
  def hex_to_unicode_char(str)
124
153
  str.to_i(16).chr(Encoding::UTF_8)
125
154
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RipperRubyParser
4
- VERSION = '1.6.0'
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.6.0
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: 2019-04-12 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
@@ -30,59 +30,149 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.2'
33
+ version: '5.6'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.2'
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
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '12.0'
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
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
48
90
  type: :development
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
- version: '12.0'
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.13.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.13.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
@@ -106,43 +195,19 @@ files:
106
195
  - lib/ripper_ruby_parser/sexp_handlers/method_calls.rb
107
196
  - lib/ripper_ruby_parser/sexp_handlers/methods.rb
108
197
  - lib/ripper_ruby_parser/sexp_handlers/operators.rb
198
+ - lib/ripper_ruby_parser/sexp_handlers/string_literals.rb
109
199
  - lib/ripper_ruby_parser/sexp_processor.rb
110
200
  - lib/ripper_ruby_parser/syntax_error.rb
111
201
  - lib/ripper_ruby_parser/unescape.rb
112
202
  - lib/ripper_ruby_parser/version.rb
113
- - test/end_to_end/comments_test.rb
114
- - test/end_to_end/comparison_test.rb
115
- - test/end_to_end/lib_comparison_test.rb
116
- - test/end_to_end/line_numbering_test.rb
117
- - test/end_to_end/samples_comparison_test.rb
118
- - test/end_to_end/test_comparison_test.rb
119
- - test/pt_testcase/pt_test.rb
120
- - test/ripper_ruby_parser/commenting_ripper_parser_test.rb
121
- - test/ripper_ruby_parser/parser_test.rb
122
- - test/ripper_ruby_parser/sexp_handlers/assignment_test.rb
123
- - test/ripper_ruby_parser/sexp_handlers/blocks_test.rb
124
- - test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb
125
- - test/ripper_ruby_parser/sexp_handlers/literals_test.rb
126
- - test/ripper_ruby_parser/sexp_handlers/loops_test.rb
127
- - test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb
128
- - test/ripper_ruby_parser/sexp_handlers/methods_test.rb
129
- - test/ripper_ruby_parser/sexp_handlers/operators_test.rb
130
- - test/ripper_ruby_parser/sexp_processor_test.rb
131
- - test/ripper_ruby_parser/version_test.rb
132
- - test/samples/assignment.rb
133
- - test/samples/comments.rb
134
- - test/samples/conditionals.rb
135
- - test/samples/loops.rb
136
- - test/samples/misc.rb
137
- - test/samples/number.rb
138
- - test/samples/operators.rb
139
- - test/samples/strings.rb
140
- - test/test_helper.rb
141
203
  homepage: http://www.github.com/mvz/ripper_ruby_parser
142
204
  licenses:
143
205
  - MIT
144
- metadata: {}
145
- 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:
146
211
  rdoc_options:
147
212
  - "--main"
148
213
  - README.md
@@ -152,43 +217,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
217
  requirements:
153
218
  - - ">="
154
219
  - !ruby/object:Gem::Version
155
- version: 2.3.0
220
+ version: 2.5.0
156
221
  required_rubygems_version: !ruby/object:Gem::Requirement
157
222
  requirements:
158
223
  - - ">="
159
224
  - !ruby/object:Gem::Version
160
225
  version: '0'
161
226
  requirements: []
162
- rubygems_version: 3.0.3
163
- signing_key:
227
+ rubygems_version: 3.2.15
228
+ signing_key:
164
229
  specification_version: 4
165
230
  summary: Parse with Ripper, produce sexps that are compatible with RubyParser.
166
- test_files:
167
- - test/end_to_end/comments_test.rb
168
- - test/end_to_end/comparison_test.rb
169
- - test/end_to_end/lib_comparison_test.rb
170
- - test/end_to_end/line_numbering_test.rb
171
- - test/end_to_end/samples_comparison_test.rb
172
- - test/end_to_end/test_comparison_test.rb
173
- - test/pt_testcase/pt_test.rb
174
- - test/ripper_ruby_parser/commenting_ripper_parser_test.rb
175
- - test/ripper_ruby_parser/parser_test.rb
176
- - test/ripper_ruby_parser/sexp_handlers/assignment_test.rb
177
- - test/ripper_ruby_parser/sexp_handlers/blocks_test.rb
178
- - test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb
179
- - test/ripper_ruby_parser/sexp_handlers/literals_test.rb
180
- - test/ripper_ruby_parser/sexp_handlers/loops_test.rb
181
- - test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb
182
- - test/ripper_ruby_parser/sexp_handlers/methods_test.rb
183
- - test/ripper_ruby_parser/sexp_handlers/operators_test.rb
184
- - test/ripper_ruby_parser/sexp_processor_test.rb
185
- - test/ripper_ruby_parser/version_test.rb
186
- - test/samples/assignment.rb
187
- - test/samples/comments.rb
188
- - test/samples/conditionals.rb
189
- - test/samples/loops.rb
190
- - test/samples/misc.rb
191
- - test/samples/number.rb
192
- - test/samples/operators.rb
193
- - test/samples/strings.rb
194
- - test/test_helper.rb
231
+ test_files: []