ripper_ruby_parser 0.0.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +7 -0
  2. data/{README.rdoc → README.md} +17 -17
  3. data/Rakefile +3 -1
  4. data/lib/ripper_ruby_parser/{commenting_sexp_builder.rb → commenting_ripper_parser.rb} +22 -6
  5. data/lib/ripper_ruby_parser/parser.rb +3 -18
  6. data/lib/ripper_ruby_parser/sexp_handlers/arrays.rb +2 -1
  7. data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +6 -10
  8. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +37 -60
  9. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +31 -25
  10. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +18 -8
  11. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +22 -18
  12. data/lib/ripper_ruby_parser/sexp_handlers/loops.rb +12 -23
  13. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +16 -8
  14. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +41 -15
  15. data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +40 -23
  16. data/lib/ripper_ruby_parser/sexp_processor.rb +38 -19
  17. data/lib/ripper_ruby_parser/version.rb +1 -1
  18. data/test/pt_testcase/pt_test.rb +15 -1
  19. data/test/test_helper.rb +6 -3
  20. data/test/unit/commenting_ripper_parser_test.rb +121 -0
  21. data/test/unit/parser_assignment_test.rb +23 -24
  22. data/test/unit/parser_blocks_test.rb +207 -35
  23. data/test/unit/parser_conditionals_test.rb +251 -9
  24. data/test/unit/parser_literals_test.rb +348 -8
  25. data/test/unit/parser_loops_test.rb +20 -21
  26. data/test/unit/parser_method_calls_test.rb +132 -8
  27. data/test/unit/parser_operators_test.rb +97 -7
  28. data/test/unit/parser_test.rb +631 -1231
  29. data/test/unit/sexp_processor_test.rb +26 -28
  30. metadata +28 -38
  31. data/test/unit/commenting_sexp_builder_test.rb +0 -113
@@ -55,6 +55,7 @@ describe RipperRubyParser::SexpProcessor do
55
55
  end
56
56
  end
57
57
 
58
+ if false
58
59
  describe "for an :args_add_block sexp" do
59
60
  it "transforms a one-argument sexp to an :arglist" do
60
61
  sexp = s(:args_add_block, s(s(:foo)), false)
@@ -68,10 +69,11 @@ describe RipperRubyParser::SexpProcessor do
68
69
  result.must_equal s(:arglist, s(:foo_p), s(:bar_p))
69
70
  end
70
71
  end
72
+ end
71
73
 
72
74
  describe "for a :command sexp" do
73
75
  it "transforms a sexp to a :call" do
74
- sexp = s(:command, s(:@ident, "foo", s(1, 0)), s(:foo))
76
+ sexp = s(:command, s(:@ident, "foo", s(1, 0)), s(:arglist, s(:foo)))
75
77
  result = processor.process sexp
76
78
  result.must_equal s(:call, nil, :foo, s(:foo_p))
77
79
  end
@@ -89,62 +91,59 @@ describe RipperRubyParser::SexpProcessor do
89
91
  it "transforms the sexp to a :call sexp" do
90
92
  sexp = s(:vcall, s(:@ident, "bar", s(1, 4)))
91
93
  result = processor.process sexp
92
- result.must_equal s(:call, nil, :bar, s(:arglist))
94
+ result.must_equal s(:call, nil, :bar)
93
95
  end
94
96
  end
95
97
 
96
98
  describe "for a :module sexp" do
97
- it "does not create a nested :block sexp for an empty definition" do
99
+ it "does not create body eleents for an empty definition" do
98
100
  sexp = s(:module,
99
101
  s(:const_ref, s(:@const, "Foo", s(1, 13))),
100
102
  s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
101
103
  result = processor.process sexp
102
- result.must_equal s(:module, :Foo, s(:scope))
104
+ result.must_equal s(:module, :Foo)
103
105
  end
104
106
 
105
- it "does not create a nested :block sexp for a definition with one statement" do
107
+ it "creates a single body element for a definition with one statement" do
106
108
  sexp = s(:module,
107
109
  s(:const_ref, s(:@const, "Foo", s(1, 13))),
108
110
  s(:bodystmt, s(s(:foo)), nil, nil, nil))
109
111
  result = processor.process sexp
110
- result.must_equal s(:module, :Foo, s(:scope, s(:foo_p)))
112
+ result.must_equal s(:module, :Foo, s(:foo_p))
111
113
  end
112
114
 
113
- it "creates a nested :block sexp for a definition with more than one statement" do
115
+ it "creates multiple body elements for a definition with more than one statement" do
114
116
  sexp = s(:module,
115
117
  s(:const_ref, s(:@const, "Foo", s(1, 13))),
116
118
  s(:bodystmt, s(s(:foo), s(:bar)), nil, nil, nil))
117
119
  result = processor.process sexp
118
- result.must_equal s(:module, :Foo,
119
- s(:scope, s(:block, s(:foo_p), s(:bar_p))))
120
+ result.must_equal s(:module, :Foo, s(:foo_p), s(:bar_p))
120
121
  end
121
122
  end
122
123
 
123
124
  describe "for a :class sexp" do
124
- it "does not create a nested :block sexp for an empty definition" do
125
+ it "does not create body eleents for an empty definition" do
125
126
  sexp = s(:class,
126
127
  s(:const_ref, s(:@const, "Foo", s(1, 13))), nil,
127
128
  s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
128
129
  result = processor.process sexp
129
- result.must_equal s(:class, :Foo, nil, s(:scope))
130
+ result.must_equal s(:class, :Foo, nil)
130
131
  end
131
132
 
132
- it "does not create a nested :block sexp for a definition with one statement" do
133
+ it "creates a single body element for a definition with one statement" do
133
134
  sexp = s(:class,
134
135
  s(:const_ref, s(:@const, "Foo", s(1, 13))), nil,
135
136
  s(:bodystmt, s(s(:foo)), nil, nil, nil))
136
137
  result = processor.process sexp
137
- result.must_equal s(:class, :Foo, nil, s(:scope, s(:foo_p)))
138
+ result.must_equal s(:class, :Foo, nil, s(:foo_p))
138
139
  end
139
140
 
140
- it "creates a nested :block sexp for a definition with more than one statement" do
141
+ it "creates multiple body elements for a definition with more than one statement" do
141
142
  sexp = s(:class,
142
143
  s(:const_ref, s(:@const, "Foo", s(1, 13))), nil,
143
144
  s(:bodystmt, s(s(:foo), s(:bar)), nil, nil, nil))
144
145
  result = processor.process sexp
145
- result.must_equal s(:class,
146
- :Foo, nil,
147
- s(:scope, s(:block, s(:foo_p), s(:bar_p))))
146
+ result.must_equal s(:class, :Foo, nil, s(:foo_p), s(:bar_p))
148
147
  end
149
148
 
150
149
  it "passes on the given ancestor" do
@@ -153,7 +152,7 @@ describe RipperRubyParser::SexpProcessor do
153
152
  s(:var_ref, s(:@const, "Bar", s(1, 12))),
154
153
  s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
155
154
  result = processor.process sexp
156
- result.must_equal s(:class, :Foo, s(:const, :Bar), s(:scope))
155
+ result.must_equal s(:class, :Foo, s(:const, :Bar))
157
156
  end
158
157
  end
159
158
 
@@ -161,13 +160,13 @@ describe RipperRubyParser::SexpProcessor do
161
160
  it "creates a :scope sexp with nested :block" do
162
161
  sexp = s(:bodystmt, s(s(:foo), s(:bar)), nil, nil, nil)
163
162
  result = processor.process sexp
164
- result.must_equal s(:scope, s(:block, s(:foo_p), s(:bar_p)))
163
+ result.must_equal s(s(:block, s(:foo_p), s(:bar_p)))
165
164
  end
166
165
 
167
166
  it "removes nested :void_stmt sexps" do
168
167
  sexp = s(:bodystmt, s(s(:void_stmt), s(:foo)), nil, nil, nil)
169
168
  result = processor.process sexp
170
- result.must_equal s(:scope, s(:block, s(:foo_p)))
169
+ result.must_equal s(s(:foo_p))
171
170
  end
172
171
  end
173
172
 
@@ -178,8 +177,7 @@ describe RipperRubyParser::SexpProcessor do
178
177
  s(:params, nil, nil, nil, nil, nil),
179
178
  s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
180
179
  result = processor.process sexp
181
- result.must_equal s(:defn,
182
- :foo, s(:args), s(:scope, s(:block, s(:nil))))
180
+ result.must_equal s(:defn, :foo, s(:args), s(:nil))
183
181
 
184
182
  end
185
183
  end
@@ -205,10 +203,10 @@ describe RipperRubyParser::SexpProcessor do
205
203
  end
206
204
 
207
205
  describe "for a :binary sexp" do
208
- it "creates a :call sexp with an :arglist" do
206
+ it "creates a :call sexp" do
209
207
  sexp = s(:binary, s(:bar), :==, s(:foo))
210
208
  result = processor.process sexp
211
- result.must_equal s(:call, s(:bar_p), :==, s(:arglist, s(:foo_p)))
209
+ result.must_equal s(:call, s(:bar_p), :==, s(:foo_p))
212
210
  end
213
211
  end
214
212
 
@@ -219,12 +217,12 @@ describe RipperRubyParser::SexpProcessor do
219
217
  s(:brace_block, nil, s(s(:bar))))
220
218
  result = processor.process sexp
221
219
  result.must_equal s(:iter,
222
- s(:call, s(:foo_p), :baz, s(:arglist)), nil,
220
+ s(:call, s(:foo_p), :baz), s(:args),
223
221
  s(:bar_p))
224
222
  end
225
223
 
226
224
  describe "with a block parameter" do
227
- it "creates an :iter sexp with a :lasgn sexp for the block parameter" do
225
+ it "creates an :iter sexp with an :args sexp for the block parameter" do
228
226
  sexp = s(:method_add_block,
229
227
  s(:call, s(:foo), :".", s(:@ident, "baz", s(1, 2))),
230
228
  s(:brace_block,
@@ -234,8 +232,8 @@ describe RipperRubyParser::SexpProcessor do
234
232
  s(s(:bar))))
235
233
  result = processor.process sexp
236
234
  result.must_equal s(:iter,
237
- s(:call, s(:foo_p), :baz, s(:arglist)),
238
- s(:lasgn, :i),
235
+ s(:call, s(:foo_p), :baz),
236
+ s(:args, :i),
239
237
  s(:bar_p))
240
238
  end
241
239
  end
metadata CHANGED
@@ -1,105 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripper_ruby_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matijs van Zuijlen
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-06-22 00:00:00.000000000 Z
11
+ date: 2014-02-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: sexp_processor
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: '3.0'
19
+ version: 4.4.1
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: '3.0'
26
+ version: 4.4.1
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: minitest
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: 3.0.1
33
+ version: '5.2'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: 3.0.1
40
+ version: '5.2'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
53
- version: 0.9.2
47
+ version: '10.0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
61
- version: 0.9.2
54
+ version: '10.0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: ruby_parser
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
69
- version: 2.3.1
61
+ version: 3.3.0
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
77
- version: 2.3.1
68
+ version: 3.3.0
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: simplecov
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
- description:
83
+ description: |2
84
+ RipperRubyParser is a parser for Ruby based on Ripper that aims to be a
85
+ drop-in replacement for RubyParser.
95
86
  email:
96
87
  - matijs@matijs.net
97
88
  executables: []
98
89
  extensions: []
99
90
  extra_rdoc_files:
100
- - README.rdoc
91
+ - README.md
101
92
  files:
102
93
  - lib/ripper_ruby_parser.rb
94
+ - lib/ripper_ruby_parser/commenting_ripper_parser.rb
103
95
  - lib/ripper_ruby_parser/sexp_processor.rb
104
96
  - lib/ripper_ruby_parser/syntax_error.rb
105
97
  - lib/ripper_ruby_parser/sexp_ext.rb
@@ -117,7 +109,6 @@ files:
117
109
  - lib/ripper_ruby_parser/sexp_handlers/conditionals.rb
118
110
  - lib/ripper_ruby_parser/sexp_handlers/method_calls.rb
119
111
  - lib/ripper_ruby_parser/version.rb
120
- - lib/ripper_ruby_parser/commenting_sexp_builder.rb
121
112
  - lib/ripper_ruby_parser/parser.rb
122
113
  - test/test_helper.rb
123
114
  - test/unit/sexp_processor_test.rb
@@ -128,7 +119,7 @@ files:
128
119
  - test/unit/parser_method_calls_test.rb
129
120
  - test/unit/parser_literals_test.rb
130
121
  - test/unit/version_test.rb
131
- - test/unit/commenting_sexp_builder_test.rb
122
+ - test/unit/commenting_ripper_parser_test.rb
132
123
  - test/unit/parser_conditionals_test.rb
133
124
  - test/unit/parser_test.rb
134
125
  - test/pt_testcase/pt_test.rb
@@ -139,33 +130,33 @@ files:
139
130
  - test/end_to_end/comparison_test.rb
140
131
  - test/end_to_end/test_comparison_test.rb
141
132
  - test/end_to_end/comments_test.rb
142
- - README.rdoc
133
+ - README.md
143
134
  - Rakefile
144
135
  homepage: http://www.github.com/mvz/ripper_ruby_parser
145
- licenses: []
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
146
139
  post_install_message:
147
140
  rdoc_options:
148
141
  - --main
149
- - README.rdoc
142
+ - README.md
150
143
  require_paths:
151
144
  - lib
152
145
  required_ruby_version: !ruby/object:Gem::Requirement
153
- none: false
154
146
  requirements:
155
- - - ! '>='
147
+ - - '>='
156
148
  - !ruby/object:Gem::Version
157
149
  version: '0'
158
150
  required_rubygems_version: !ruby/object:Gem::Requirement
159
- none: false
160
151
  requirements:
161
- - - ! '>='
152
+ - - '>='
162
153
  - !ruby/object:Gem::Version
163
154
  version: '0'
164
155
  requirements: []
165
156
  rubyforge_project:
166
- rubygems_version: 1.8.23
157
+ rubygems_version: 2.0.14
167
158
  signing_key:
168
- specification_version: 3
159
+ specification_version: 4
169
160
  summary: Parse with Ripper, produce sexps that are compatible with RubyParser.
170
161
  test_files:
171
162
  - test/end_to_end/comments_test.rb
@@ -177,7 +168,7 @@ test_files:
177
168
  - test/end_to_end/test_comparison_test.rb
178
169
  - test/pt_testcase/pt_test.rb
179
170
  - test/test_helper.rb
180
- - test/unit/commenting_sexp_builder_test.rb
171
+ - test/unit/commenting_ripper_parser_test.rb
181
172
  - test/unit/parser_assignment_test.rb
182
173
  - test/unit/parser_blocks_test.rb
183
174
  - test/unit/parser_conditionals_test.rb
@@ -188,4 +179,3 @@ test_files:
188
179
  - test/unit/parser_test.rb
189
180
  - test/unit/sexp_processor_test.rb
190
181
  - test/unit/version_test.rb
191
- has_rdoc:
@@ -1,113 +0,0 @@
1
- require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
2
-
3
- describe RipperRubyParser::CommentingSexpBuilder do
4
- def parse_with_builder str
5
- builder = RipperRubyParser::CommentingSexpBuilder.new str
6
- builder.parse
7
- end
8
-
9
- describe "handling comments" do
10
- it "produces a comment node surrounding a commented def" do
11
- result = parse_with_builder "# Foo\ndef foo; end"
12
- result.must_equal [:program,
13
- [[:comment,
14
- "# Foo\n",
15
- [:def,
16
- [:@ident, "foo", [2, 4]],
17
- [:params, nil, nil, nil, nil, nil],
18
- [:bodystmt, [[:void_stmt]], nil, nil, nil]]]]]
19
- end
20
-
21
- it "produces a blank comment node surrounding a def that has no comment" do
22
- result = parse_with_builder "def foo; end"
23
- result.must_equal [:program,
24
- [[:comment,
25
- "",
26
- [:def,
27
- [:@ident, "foo", [1, 4]],
28
- [:params, nil, nil, nil, nil, nil],
29
- [:bodystmt, [[:void_stmt]], nil, nil, nil]]]]]
30
- end
31
-
32
- it "produces a comment node surrounding a commented class" do
33
- result = parse_with_builder "# Foo\nclass Foo; end"
34
- result.must_equal [:program,
35
- [[:comment,
36
- "# Foo\n",
37
- [:class,
38
- [:const_ref, [:@const, "Foo", [2, 6]]],
39
- nil,
40
- [:bodystmt, [[:void_stmt]], nil, nil, nil]]]]]
41
- end
42
-
43
- it "produce a blank comment node surrounding a class that has no comment" do
44
- result = parse_with_builder "class Foo; end"
45
- result.must_equal [:program,
46
- [[:comment,
47
- "",
48
- [:class,
49
- [:const_ref, [:@const, "Foo", [1, 6]]],
50
- nil,
51
- [:bodystmt, [[:void_stmt]], nil, nil, nil]]]]]
52
- end
53
-
54
- it "produces a comment node surrounding a commented module" do
55
- result = parse_with_builder "# Foo\nmodule Foo; end"
56
- result.must_equal [:program,
57
- [[:comment,
58
- "# Foo\n",
59
- [:module,
60
- [:const_ref, [:@const, "Foo", [2, 7]]],
61
- [:bodystmt, [[:void_stmt]], nil, nil, nil]]]]]
62
- end
63
-
64
- it "produces a blank comment node surrounding a module that has no comment" do
65
- result = parse_with_builder "module Foo; end"
66
- result.must_equal [:program,
67
- [[:comment,
68
- "",
69
- [:module,
70
- [:const_ref, [:@const, "Foo", [1, 7]]],
71
- [:bodystmt, [[:void_stmt]], nil, nil, nil]]]]]
72
- end
73
-
74
- it "is not confused by a symbol containing a keyword" do
75
- result = parse_with_builder ":class; def foo; end"
76
- result.must_equal [:program,
77
- [[:symbol_literal, [:symbol, [:@kw, "class", [1, 1]]]],
78
- [:comment,
79
- "",
80
- [:def,
81
- [:@ident, "foo", [1, 12]],
82
- [:params, nil, nil, nil, nil, nil],
83
- [:bodystmt, [[:void_stmt]], nil, nil, nil]]]]]
84
- end
85
-
86
- it "is not confused by a dynamic symbol" do
87
- result = parse_with_builder ":'foo'; def bar; end"
88
- result.must_equal [:program,
89
- [[:dyna_symbol, [[:@tstring_content, "foo", [1, 2]]]],
90
- [:comment,
91
- "",
92
- [:def,
93
- [:@ident, "bar", [1, 12]],
94
- [:params, nil, nil, nil, nil, nil],
95
- [:bodystmt, [[:void_stmt]], nil, nil, nil]]]]]
96
- end
97
-
98
- it "is not confused by a dynamic symbol containing a class definition" do
99
- result = parse_with_builder ":\"foo\#{class Bar;end}\""
100
- result.must_equal [:program,
101
- [[:dyna_symbol,
102
- [[:@tstring_content, "foo", [1, 2]],
103
- [:string_embexpr,
104
- [[:comment,
105
- "",
106
- [:class,
107
- [:const_ref, [:@const, "Bar", [1, 13]]],
108
- nil,
109
- [:bodystmt, [[:void_stmt]], nil, nil, nil]]]]]]]]]
110
- end
111
- end
112
- end
113
-