ripper_ruby_parser 1.7.2 → 1.10.0
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 +50 -0
- data/README.md +4 -4
- data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +24 -12
- data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +2 -2
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +47 -53
- data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
- data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +34 -1
- data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +1 -1
- data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +9 -5
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +17 -15
- data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +3 -3
- data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +24 -28
- data/lib/ripper_ruby_parser/sexp_processor.rb +5 -18
- data/lib/ripper_ruby_parser/unescape.rb +63 -22
- data/lib/ripper_ruby_parser/version.rb +1 -1
- metadata +140 -79
- data/Rakefile +0 -33
- data/test/end_to_end/comments_test.rb +0 -59
- data/test/end_to_end/comparison_test.rb +0 -104
- data/test/end_to_end/lib_comparison_test.rb +0 -18
- data/test/end_to_end/line_numbering_test.rb +0 -31
- data/test/end_to_end/samples_comparison_test.rb +0 -13
- data/test/end_to_end/test_comparison_test.rb +0 -18
- data/test/pt_testcase/pt_test.rb +0 -44
- data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -200
- data/test/ripper_ruby_parser/parser_test.rb +0 -576
- data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -597
- data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -717
- data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
- data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -165
- data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
- data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -237
- data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -429
- data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -405
- data/test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb +0 -973
- data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -327
- data/test/ripper_ruby_parser/version_test.rb +0 -7
- data/test/samples/assignment.rb +0 -22
- data/test/samples/comments.rb +0 -13
- data/test/samples/conditionals.rb +0 -23
- data/test/samples/lambdas.rb +0 -5
- data/test/samples/loops.rb +0 -36
- data/test/samples/misc.rb +0 -285
- data/test/samples/number.rb +0 -9
- data/test/samples/operators.rb +0 -18
- data/test/samples/strings.rb +0 -147
- data/test/test_helper.rb +0 -111
data/test/samples/misc.rb
DELETED
@@ -1,285 +0,0 @@
|
|
1
|
-
# Miscellaneous samples
|
2
|
-
|
3
|
-
BEGIN {
|
4
|
-
begin
|
5
|
-
foo
|
6
|
-
end
|
7
|
-
}
|
8
|
-
|
9
|
-
BEGIN {}
|
10
|
-
|
11
|
-
END {
|
12
|
-
begin
|
13
|
-
bar
|
14
|
-
end
|
15
|
-
}
|
16
|
-
|
17
|
-
END {}
|
18
|
-
|
19
|
-
# regular expressions with different encoding flags
|
20
|
-
regular = /foo/
|
21
|
-
noenc = /foo/n
|
22
|
-
utf8 = /foo/u
|
23
|
-
euc = /foo/e
|
24
|
-
sjis = /foo/s
|
25
|
-
|
26
|
-
bar = 'bar'
|
27
|
-
regular = /foo#{bar}/
|
28
|
-
noenc = /foo#{bar}/n
|
29
|
-
utf8 = /foo#{bar}/u
|
30
|
-
euc = /foo#{bar}/e
|
31
|
-
sjis = /foo#{bar}/s
|
32
|
-
|
33
|
-
# Use of __ENCODING__
|
34
|
-
enc = __ENCODING__
|
35
|
-
|
36
|
-
class Foo
|
37
|
-
# calling #[] on self
|
38
|
-
# https://github.com/seattlerb/ruby_parser/issues/250
|
39
|
-
def bar
|
40
|
-
self[:foo]
|
41
|
-
end
|
42
|
-
|
43
|
-
# required keyword arguments and no parentheses
|
44
|
-
# https://github.com/seattlerb/ruby_parser/pull/254
|
45
|
-
def foo a:, b:
|
46
|
-
puts "A: #{a}, B: #{b}"
|
47
|
-
end
|
48
|
-
|
49
|
-
# Combinations of begin..end and diverse operators
|
50
|
-
def qux
|
51
|
-
begin end
|
52
|
-
begin; foo; end
|
53
|
-
begin; foo; bar; end
|
54
|
-
- begin; foo; end
|
55
|
-
begin; bar; end + foo
|
56
|
-
foo + begin; bar; end
|
57
|
-
begin; foo; end ? bar : baz
|
58
|
-
foo ? begin; bar; end : baz
|
59
|
-
foo ? bar : begin; baz; end
|
60
|
-
begin; bar; end and foo
|
61
|
-
foo and begin; bar; end
|
62
|
-
begin; foo; end if bar
|
63
|
-
begin; foo; end unless bar
|
64
|
-
begin; foo; end.bar
|
65
|
-
foo ||= begin; bar; end
|
66
|
-
foo += begin; bar; end
|
67
|
-
foo[qux] ||= begin; bar; end
|
68
|
-
foo = begin; bar; end
|
69
|
-
foo = begin; if bar; baz; end; end
|
70
|
-
baz = begin; foo; ensure; bar; end
|
71
|
-
foo = *begin; bar; end
|
72
|
-
foo = bar, *begin; baz; end
|
73
|
-
foo, bar = *begin; baz; end
|
74
|
-
foo if begin bar end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Nested do and begin blocks
|
78
|
-
def quuz
|
79
|
-
foo do
|
80
|
-
bar
|
81
|
-
|
82
|
-
begin
|
83
|
-
baz
|
84
|
-
rescue
|
85
|
-
qux
|
86
|
-
end
|
87
|
-
|
88
|
-
quuz
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Nested begin/rescue blocks
|
93
|
-
def quuz
|
94
|
-
begin
|
95
|
-
bar
|
96
|
-
rescue
|
97
|
-
begin
|
98
|
-
baz
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
begin
|
103
|
-
bar
|
104
|
-
rescue
|
105
|
-
begin
|
106
|
-
baz
|
107
|
-
rescue
|
108
|
-
qux
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
begin
|
113
|
-
bar
|
114
|
-
rescue
|
115
|
-
begin
|
116
|
-
baz
|
117
|
-
end
|
118
|
-
begin
|
119
|
-
qux
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# Begin/end blocks and case statements
|
125
|
-
def quuz
|
126
|
-
case foo
|
127
|
-
when bar
|
128
|
-
begin
|
129
|
-
baz
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
case foo
|
134
|
-
when bar
|
135
|
-
begin
|
136
|
-
baz
|
137
|
-
qux
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
case foo
|
142
|
-
when bar
|
143
|
-
begin
|
144
|
-
baz
|
145
|
-
qux
|
146
|
-
end
|
147
|
-
quuz
|
148
|
-
end
|
149
|
-
|
150
|
-
case foo
|
151
|
-
when bar
|
152
|
-
else
|
153
|
-
begin
|
154
|
-
baz
|
155
|
-
qux
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
case foo
|
160
|
-
when bar
|
161
|
-
else
|
162
|
-
begin
|
163
|
-
baz
|
164
|
-
qux
|
165
|
-
end
|
166
|
-
quuz
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
# Using splat and double-splat args
|
171
|
-
def barbaz(*foo, **bar)
|
172
|
-
puts [foo, bar]
|
173
|
-
foo.each do |baz, **qux|
|
174
|
-
puts [foo, bar, baz, qux]
|
175
|
-
end
|
176
|
-
puts [foo, bar]
|
177
|
-
end
|
178
|
-
|
179
|
-
def barbaz_block(*foo, **bar, &block)
|
180
|
-
puts [foo, bar]
|
181
|
-
end
|
182
|
-
|
183
|
-
def self.barbaz(*foo, **bar)
|
184
|
-
puts [foo, bar]
|
185
|
-
foo.each do |baz, **qux|
|
186
|
-
puts [foo, bar, baz, qux]
|
187
|
-
end
|
188
|
-
puts [foo, bar]
|
189
|
-
end
|
190
|
-
|
191
|
-
def foobarbaz(**)
|
192
|
-
end
|
193
|
-
|
194
|
-
# rescue
|
195
|
-
def barfoo
|
196
|
-
foo
|
197
|
-
rescue *bar
|
198
|
-
baz
|
199
|
-
rescue *quuz, Bar
|
200
|
-
zyxxy
|
201
|
-
rescue *qux => err
|
202
|
-
puts err
|
203
|
-
end
|
204
|
-
|
205
|
-
# begin/rescue with multiple assignment
|
206
|
-
foo, bar = begin
|
207
|
-
baz
|
208
|
-
rescue qux
|
209
|
-
quuz
|
210
|
-
end
|
211
|
-
|
212
|
-
# alias
|
213
|
-
alias foo bar
|
214
|
-
alias :foo bar
|
215
|
-
alias :foo :bar
|
216
|
-
alias foo :bar
|
217
|
-
alias :+ -
|
218
|
-
alias next bar
|
219
|
-
|
220
|
-
# rescue with assignment
|
221
|
-
foo = bar rescue baz
|
222
|
-
foo = bar baz rescue qux
|
223
|
-
foo = bar(baz) rescue qux
|
224
|
-
foo, bar = baz qux rescue quuz
|
225
|
-
@foo = bar baz rescue qux
|
226
|
-
@@foo = bar baz rescue qux
|
227
|
-
FOO = bar baz rescue qux
|
228
|
-
$foo = bar baz rescue qux
|
229
|
-
foo = Foo.bar(baz) rescue qux
|
230
|
-
foo = Foo.bar baz rescue qux
|
231
|
-
|
232
|
-
# Assignment to class variables inside method argument
|
233
|
-
# definitions.
|
234
|
-
def foo(bar = (@@baz = qux))
|
235
|
-
end
|
236
|
-
|
237
|
-
def self.foo(bar = (@@baz = qux))
|
238
|
-
end
|
239
|
-
|
240
|
-
def (bar = (@@baz = qux)).foo
|
241
|
-
end
|
242
|
-
|
243
|
-
# Assignment to global variables inside method argument
|
244
|
-
# definitions.
|
245
|
-
def foo(bar = ($baz = qux))
|
246
|
-
end
|
247
|
-
|
248
|
-
# Argument destructuring
|
249
|
-
def foo((bar, baz))
|
250
|
-
end
|
251
|
-
|
252
|
-
def foo((bar, baz), (qux, quuz))
|
253
|
-
end
|
254
|
-
|
255
|
-
def foo((bar, *qux))
|
256
|
-
end
|
257
|
-
|
258
|
-
def foo((bar, (baz, qux)))
|
259
|
-
end
|
260
|
-
|
261
|
-
def foo((bar, (baz, *qux)))
|
262
|
-
end
|
263
|
-
|
264
|
-
def self.foo((bar, baz))
|
265
|
-
end
|
266
|
-
|
267
|
-
def self.foo((bar, baz), (qux, quuz))
|
268
|
-
end
|
269
|
-
|
270
|
-
def self.foo((bar, *qux))
|
271
|
-
end
|
272
|
-
|
273
|
-
def self.foo((bar, (baz, qux)))
|
274
|
-
end
|
275
|
-
|
276
|
-
def self.foo((bar, (baz, *qux)))
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
# Special symbols
|
281
|
-
[:`, :|, :*, :&, :%, :'^', :-@, :+@, :'~@']
|
282
|
-
|
283
|
-
# Blocks
|
284
|
-
foo do |bar, | end
|
285
|
-
foo do |bar, **| end
|
data/test/samples/number.rb
DELETED
data/test/samples/operators.rb
DELETED
data/test/samples/strings.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
# Samples of strings demonstrating handling of escape sequences, encoding and
|
2
|
-
# line continuations.
|
3
|
-
|
4
|
-
# Escape sequences
|
5
|
-
%W(foo\nbar baz)
|
6
|
-
%w(foo\nbar baz)
|
7
|
-
|
8
|
-
"foo\u273bbar"
|
9
|
-
"foo\a\b\e\f\r\s\t\vbar\nbaz"
|
10
|
-
"\0"
|
11
|
-
"foo#{bar}\0"
|
12
|
-
"foo#{bar}baz\0"
|
13
|
-
"2\302\275"
|
14
|
-
"#{foo}2\302\275"
|
15
|
-
%W(2\302\275)
|
16
|
-
/2\302\275/
|
17
|
-
"foo\u{101D1}bar"
|
18
|
-
|
19
|
-
# Encoding
|
20
|
-
"日本語"
|
21
|
-
/日本語/
|
22
|
-
"\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # => "日本語"
|
23
|
-
"\xAB\xE6\x97\xA5" # Invalid in UTF8
|
24
|
-
|
25
|
-
<<EOS
|
26
|
-
日本語
|
27
|
-
EOS
|
28
|
-
|
29
|
-
<<EOS
|
30
|
-
\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E
|
31
|
-
EOS
|
32
|
-
|
33
|
-
# Quotes around heredoc names
|
34
|
-
<<'FOO'
|
35
|
-
\n
|
36
|
-
FOO
|
37
|
-
|
38
|
-
<<"FOO"
|
39
|
-
\n
|
40
|
-
FOO
|
41
|
-
|
42
|
-
# Escape sequences in heredocs, in particular carriage returns
|
43
|
-
#
|
44
|
-
<<FOO
|
45
|
-
foo\rbar\tbaz\r
|
46
|
-
FOO
|
47
|
-
|
48
|
-
<<'FOO'
|
49
|
-
foo\rbar\tbaz\r
|
50
|
-
FOO
|
51
|
-
|
52
|
-
# Dedented heredocs
|
53
|
-
foo = <<~BAR
|
54
|
-
baz
|
55
|
-
#{qux}
|
56
|
-
quuz
|
57
|
-
BAR
|
58
|
-
|
59
|
-
# Line continuation
|
60
|
-
"foo\
|
61
|
-
bar"
|
62
|
-
|
63
|
-
'foo2\
|
64
|
-
bar'
|
65
|
-
|
66
|
-
/foo3\
|
67
|
-
bar/
|
68
|
-
|
69
|
-
<<EOS
|
70
|
-
foo4\
|
71
|
-
bar
|
72
|
-
EOS
|
73
|
-
|
74
|
-
<<'EOS'
|
75
|
-
foo4\
|
76
|
-
bar
|
77
|
-
EOS
|
78
|
-
|
79
|
-
<<EOS
|
80
|
-
#{bar}
|
81
|
-
baz \
|
82
|
-
qux
|
83
|
-
EOS
|
84
|
-
|
85
|
-
<<-EOS
|
86
|
-
#{bar}
|
87
|
-
baz \
|
88
|
-
qux
|
89
|
-
EOS
|
90
|
-
|
91
|
-
%Q[foo5\
|
92
|
-
bar]
|
93
|
-
|
94
|
-
%W[fooa\
|
95
|
-
bar baz]
|
96
|
-
|
97
|
-
%I[foob\
|
98
|
-
bar baz]
|
99
|
-
|
100
|
-
%q[fooc\
|
101
|
-
bar]
|
102
|
-
|
103
|
-
%w[food\
|
104
|
-
bar baz]
|
105
|
-
|
106
|
-
%i[fooe\
|
107
|
-
bar baz]
|
108
|
-
|
109
|
-
%r[foof\
|
110
|
-
bar baz]
|
111
|
-
|
112
|
-
# Escaped line continuation
|
113
|
-
"foo6\\
|
114
|
-
bar"
|
115
|
-
'foo7\\
|
116
|
-
bar'
|
117
|
-
/foo8\\
|
118
|
-
bar/
|
119
|
-
<<EOS
|
120
|
-
foo9\\
|
121
|
-
bar
|
122
|
-
EOS
|
123
|
-
%Q[foo10\\
|
124
|
-
bar]
|
125
|
-
%W[foog\\
|
126
|
-
bar baz]
|
127
|
-
%I[fooh\\
|
128
|
-
bar baz]
|
129
|
-
%q[fooi\\
|
130
|
-
bar]
|
131
|
-
%w[fooj\\
|
132
|
-
bar baz]
|
133
|
-
%i[fook\\
|
134
|
-
bar baz]
|
135
|
-
%r[fool\\
|
136
|
-
bar baz]
|
137
|
-
|
138
|
-
eval(<<FOO, __FILE__, __LINE__)
|
139
|
-
bar
|
140
|
-
baz
|
141
|
-
FOO
|
142
|
-
|
143
|
-
# Interpolation
|
144
|
-
"foo#{bar}"
|
145
|
-
"foo#{"bar#{baz}"}"
|
146
|
-
"foo#{"bar#{"baz#{qux}"}"}"
|
147
|
-
"foo#{"bar#{baz}"}foo#{"bar#{baz}"}"
|
data/test/test_helper.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "simplecov"
|
4
|
-
SimpleCov.start do
|
5
|
-
add_filter "/test/"
|
6
|
-
end
|
7
|
-
|
8
|
-
require "minitest/autorun"
|
9
|
-
|
10
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
11
|
-
|
12
|
-
require "ripper_ruby_parser"
|
13
|
-
|
14
|
-
module MiniTest
|
15
|
-
class Spec
|
16
|
-
def inspect_with_line_numbers(exp)
|
17
|
-
parts = exp.map do |sub_exp|
|
18
|
-
if sub_exp.is_a? Sexp
|
19
|
-
inspect_with_line_numbers(sub_exp)
|
20
|
-
else
|
21
|
-
sub_exp.inspect
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
plain = "s(#{parts.join(', ')})"
|
26
|
-
if exp.line
|
27
|
-
"#{plain}.line(#{exp.line})"
|
28
|
-
else
|
29
|
-
plain
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def formatted(exp, with_line_numbers: false)
|
34
|
-
inspection = if with_line_numbers
|
35
|
-
inspect_with_line_numbers(exp)
|
36
|
-
else
|
37
|
-
exp.inspect
|
38
|
-
end
|
39
|
-
inspection.gsub(/\), /, "),\n")
|
40
|
-
end
|
41
|
-
|
42
|
-
def fix_lines(exp)
|
43
|
-
if exp.sexp_type == :lit && exp.line == exp[1]
|
44
|
-
return s(:lit, :__LINE__).line(exp.line)
|
45
|
-
end
|
46
|
-
|
47
|
-
exp.sexp_body = exp.sexp_body.map do |sub_exp|
|
48
|
-
if sub_exp.is_a? Sexp
|
49
|
-
fix_lines sub_exp
|
50
|
-
else
|
51
|
-
sub_exp
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
exp
|
56
|
-
end
|
57
|
-
|
58
|
-
def to_comments(exp)
|
59
|
-
comments = exp.comments.to_s.gsub(/\n\s*\n/, "\n")
|
60
|
-
|
61
|
-
exp.sexp_body = exp.sexp_body.map do |sub_exp|
|
62
|
-
if sub_exp.is_a? Sexp
|
63
|
-
to_comments sub_exp
|
64
|
-
else
|
65
|
-
sub_exp
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
if comments.empty?
|
70
|
-
exp
|
71
|
-
else
|
72
|
-
s(:comment, comments, exp)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def assert_parsed_as(sexp, code, with_line_numbers: false)
|
77
|
-
parser = RipperRubyParser::Parser.new
|
78
|
-
result = parser.parse code
|
79
|
-
if sexp.nil?
|
80
|
-
assert_nil result
|
81
|
-
else
|
82
|
-
assert_equal sexp, result
|
83
|
-
assert_equal(formatted(sexp, with_line_numbers: with_line_numbers),
|
84
|
-
formatted(result, with_line_numbers: with_line_numbers))
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def assert_parsed_as_before(code, with_line_numbers: false)
|
89
|
-
oldparser = RubyParser.for_current_ruby
|
90
|
-
newparser = RipperRubyParser::Parser.new
|
91
|
-
newparser.extra_compatible = true
|
92
|
-
expected = oldparser.parse code.dup
|
93
|
-
result = newparser.parse code
|
94
|
-
expected = to_comments fix_lines expected
|
95
|
-
result = to_comments fix_lines result
|
96
|
-
assert_equal expected, result
|
97
|
-
assert_equal(formatted(expected, with_line_numbers: with_line_numbers),
|
98
|
-
formatted(result, with_line_numbers: with_line_numbers))
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
Expectation.class_eval do
|
103
|
-
def must_be_parsed_as(sexp, with_line_numbers: false)
|
104
|
-
ctx.assert_parsed_as(sexp, target, with_line_numbers: with_line_numbers)
|
105
|
-
end
|
106
|
-
|
107
|
-
def must_be_parsed_as_before(with_line_numbers: false)
|
108
|
-
ctx.assert_parsed_as_before(target, with_line_numbers: with_line_numbers)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|