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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +86 -0
- data/README.md +8 -25
- data/lib/ripper_ruby_parser.rb +2 -2
- data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +54 -23
- data/lib/ripper_ruby_parser/parser.rb +3 -3
- data/lib/ripper_ruby_parser/sexp_handlers.rb +11 -9
- data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +10 -11
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +48 -63
- data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
- data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +35 -2
- data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +15 -242
- data/lib/ripper_ruby_parser/sexp_handlers/loops.rb +4 -2
- data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +1 -1
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +24 -24
- data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +266 -0
- data/lib/ripper_ruby_parser/sexp_processor.rb +47 -78
- data/lib/ripper_ruby_parser/unescape.rb +79 -50
- data/lib/ripper_ruby_parser/version.rb +1 -1
- metadata +115 -78
- 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 -29
- data/test/end_to_end/line_numbering_test.rb +0 -64
- data/test/end_to_end/samples_comparison_test.rb +0 -13
- data/test/end_to_end/test_comparison_test.rb +0 -32
- data/test/pt_testcase/pt_test.rb +0 -44
- data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -190
- data/test/ripper_ruby_parser/parser_test.rb +0 -469
- data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -649
- data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -661
- data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
- data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -1117
- data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
- data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -267
- data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -427
- data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -399
- data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -303
- data/test/ripper_ruby_parser/version_test.rb +0 -7
- data/test/samples/assignment.rb +0 -17
- data/test/samples/comments.rb +0 -13
- data/test/samples/conditionals.rb +0 -23
- data/test/samples/loops.rb +0 -36
- data/test/samples/misc.rb +0 -278
- data/test/samples/number.rb +0 -7
- data/test/samples/operators.rb +0 -18
- data/test/samples/strings.rb +0 -140
- data/test/test_helper.rb +0 -79
data/test/samples/number.rb
DELETED
data/test/samples/operators.rb
DELETED
data/test/samples/strings.rb
DELETED
@@ -1,140 +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
|
-
|
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
|
-
# Line continuation
|
53
|
-
"foo\
|
54
|
-
bar"
|
55
|
-
|
56
|
-
'foo2\
|
57
|
-
bar'
|
58
|
-
|
59
|
-
/foo3\
|
60
|
-
bar/
|
61
|
-
|
62
|
-
<<EOS
|
63
|
-
foo4\
|
64
|
-
bar
|
65
|
-
EOS
|
66
|
-
|
67
|
-
<<'EOS'
|
68
|
-
foo4\
|
69
|
-
bar
|
70
|
-
EOS
|
71
|
-
|
72
|
-
<<EOS
|
73
|
-
#{bar}
|
74
|
-
baz \
|
75
|
-
qux
|
76
|
-
EOS
|
77
|
-
|
78
|
-
<<-EOS
|
79
|
-
#{bar}
|
80
|
-
baz \
|
81
|
-
qux
|
82
|
-
EOS
|
83
|
-
|
84
|
-
%Q[foo5\
|
85
|
-
bar]
|
86
|
-
|
87
|
-
%W[fooa\
|
88
|
-
bar baz]
|
89
|
-
|
90
|
-
%I[foob\
|
91
|
-
bar baz]
|
92
|
-
|
93
|
-
%q[fooc\
|
94
|
-
bar]
|
95
|
-
|
96
|
-
%w[food\
|
97
|
-
bar baz]
|
98
|
-
|
99
|
-
%i[fooe\
|
100
|
-
bar baz]
|
101
|
-
|
102
|
-
%r[foof\
|
103
|
-
bar baz]
|
104
|
-
|
105
|
-
# Escaped line continuation
|
106
|
-
"foo6\\
|
107
|
-
bar"
|
108
|
-
'foo7\\
|
109
|
-
bar'
|
110
|
-
/foo8\\
|
111
|
-
bar/
|
112
|
-
<<EOS
|
113
|
-
foo9\\
|
114
|
-
bar
|
115
|
-
EOS
|
116
|
-
%Q[foo10\\
|
117
|
-
bar]
|
118
|
-
%W[foog\\
|
119
|
-
bar baz]
|
120
|
-
%I[fooh\\
|
121
|
-
bar baz]
|
122
|
-
%q[fooi\\
|
123
|
-
bar]
|
124
|
-
%w[fooj\\
|
125
|
-
bar baz]
|
126
|
-
%i[fook\\
|
127
|
-
bar baz]
|
128
|
-
%r[fool\\
|
129
|
-
bar baz]
|
130
|
-
|
131
|
-
eval(<<FOO, __FILE__, __LINE__)
|
132
|
-
bar
|
133
|
-
baz
|
134
|
-
FOO
|
135
|
-
|
136
|
-
# Interpolation
|
137
|
-
"foo#{bar}"
|
138
|
-
"foo#{"bar#{baz}"}"
|
139
|
-
"foo#{"bar#{"baz#{qux}"}"}"
|
140
|
-
"foo#{"bar#{baz}"}foo#{"bar#{baz}"}"
|
data/test/test_helper.rb
DELETED
@@ -1,79 +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 formatted(exp)
|
17
|
-
exp.to_s.gsub(/\), /, "),\n")
|
18
|
-
end
|
19
|
-
|
20
|
-
def fix_lines(exp)
|
21
|
-
return s(:lit, :__LINE__) if exp.sexp_type == :lit && exp.line == exp[1]
|
22
|
-
|
23
|
-
inner = exp.map do |sub_exp|
|
24
|
-
if sub_exp.is_a? Sexp
|
25
|
-
fix_lines sub_exp
|
26
|
-
else
|
27
|
-
sub_exp
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
s(*inner)
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_comments(exp)
|
35
|
-
inner = exp.map do |sub_exp|
|
36
|
-
if sub_exp.is_a? Sexp
|
37
|
-
to_comments sub_exp
|
38
|
-
else
|
39
|
-
sub_exp
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
comments = exp.comments.to_s.gsub(/\n\s*\n/, "\n")
|
44
|
-
if comments.empty?
|
45
|
-
s(*inner)
|
46
|
-
else
|
47
|
-
s(:comment, comments, s(*inner))
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def assert_parsed_as(sexp, code, extra_compatible: false)
|
52
|
-
parser = RipperRubyParser::Parser.new
|
53
|
-
parser.extra_compatible = extra_compatible
|
54
|
-
result = parser.parse code
|
55
|
-
if sexp.nil?
|
56
|
-
assert_nil result
|
57
|
-
else
|
58
|
-
assert_equal sexp, result
|
59
|
-
assert_equal sexp.to_s, result.to_s
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def assert_parsed_as_before(code)
|
64
|
-
oldparser = RubyParser.for_current_ruby
|
65
|
-
newparser = RipperRubyParser::Parser.new
|
66
|
-
newparser.extra_compatible = true
|
67
|
-
expected = oldparser.parse code.dup
|
68
|
-
result = newparser.parse code
|
69
|
-
expected = to_comments fix_lines expected
|
70
|
-
result = to_comments fix_lines result
|
71
|
-
assert_equal formatted(expected), formatted(result)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
module Expectations
|
76
|
-
infect_an_assertion :assert_parsed_as, :must_be_parsed_as
|
77
|
-
infect_an_assertion :assert_parsed_as_before, :must_be_parsed_as_before, :unary
|
78
|
-
end
|
79
|
-
end
|