ripper_ruby_parser 1.0.0 → 1.1.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/README.md +3 -3
  4. data/Rakefile +4 -4
  5. data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +5 -7
  6. data/lib/ripper_ruby_parser/parser.rb +2 -3
  7. data/lib/ripper_ruby_parser/sexp_handlers/arguments.rb +2 -6
  8. data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +16 -17
  9. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +5 -5
  10. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +6 -7
  11. data/lib/ripper_ruby_parser/sexp_handlers/hashes.rb +4 -5
  12. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +7 -11
  13. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +35 -26
  14. data/lib/ripper_ruby_parser/sexp_handlers/loops.rb +19 -18
  15. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +15 -15
  16. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +9 -18
  17. data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +10 -10
  18. data/lib/ripper_ruby_parser/sexp_processor.rb +11 -14
  19. data/lib/ripper_ruby_parser/syntax_error.rb +1 -3
  20. data/lib/ripper_ruby_parser/version.rb +1 -1
  21. data/test/end_to_end/comparison_test.rb +0 -1
  22. data/test/end_to_end/lib_comparison_test.rb +0 -2
  23. data/test/end_to_end/line_numbering_test.rb +0 -1
  24. data/test/end_to_end/samples_comparison_test.rb +1 -1
  25. data/test/end_to_end/test_comparison_test.rb +0 -3
  26. data/test/pt_testcase/pt_test.rb +4 -4
  27. data/test/samples/inline.rb +704 -0
  28. data/test/test_helper.rb +39 -37
  29. data/test/unit/commenting_ripper_parser_test.rb +57 -59
  30. data/test/unit/parser_blocks_test.rb +19 -3
  31. data/test/unit/parser_conditionals_test.rb +0 -1
  32. data/test/unit/parser_literals_test.rb +25 -25
  33. data/test/unit/parser_method_calls_test.rb +19 -15
  34. data/test/unit/parser_test.rb +31 -24
  35. data/test/unit/sexp_processor_test.rb +1 -14
  36. metadata +67 -51
  37. data/lib/ripper_ruby_parser/sexp_ext.rb +0 -14
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
3
2
 
4
3
  describe RipperRubyParser::Parser do
@@ -294,7 +293,8 @@ describe RipperRubyParser::Parser do
294
293
  must_be_parsed_as s(:defs,
295
294
  s(:call, nil, :foo),
296
295
  :bar,
297
- s(:args))
296
+ s(:args),
297
+ s(:nil))
298
298
  end
299
299
 
300
300
  it "works with def with receiver and multiple statements" do
@@ -364,24 +364,24 @@ describe RipperRubyParser::Parser do
364
364
  s(:nil))
365
365
  end
366
366
 
367
- it "works with a argument with default value plus explicit block parameter" do
367
+ it "works with a default value plus explicit block parameter" do
368
368
  "def foo bar=1, &baz; end".
369
369
  must_be_parsed_as s(:defn,
370
370
  :foo,
371
371
  s(:args,
372
372
  s(:lasgn, :bar, s(:lit, 1)),
373
373
  :"&baz"),
374
- s(:nil))
374
+ s(:nil))
375
375
  end
376
376
 
377
- it "works with a argument with default value followed by a mandatory argument" do
377
+ it "works with a default value plus mandatory argument" do
378
378
  "def foo bar=1, baz; end".
379
379
  must_be_parsed_as s(:defn,
380
380
  :foo,
381
381
  s(:args,
382
382
  s(:lasgn, :bar, s(:lit, 1)),
383
383
  :baz),
384
- s(:nil))
384
+ s(:nil))
385
385
  end
386
386
 
387
387
  it "works with a splat plus explicit block parameter" do
@@ -392,24 +392,24 @@ describe RipperRubyParser::Parser do
392
392
  s(:nil))
393
393
  end
394
394
 
395
- it "works with an argument with default value plus splat" do
395
+ it "works with a default value plus splat" do
396
396
  "def foo bar=1, *baz; end".
397
397
  must_be_parsed_as s(:defn,
398
398
  :foo,
399
399
  s(:args,
400
400
  s(:lasgn, :bar, s(:lit, 1)),
401
401
  :"*baz"),
402
- s(:nil))
402
+ s(:nil))
403
403
  end
404
404
 
405
- it "works with an argument with default value plus splat plus final mandatory arguments" do
405
+ it "works with a default value, splat, plus final mandatory arguments" do
406
406
  "def foo bar=1, *baz, qux, quuz; end".
407
407
  must_be_parsed_as s(:defn,
408
408
  :foo,
409
409
  s(:args,
410
410
  s(:lasgn, :bar, s(:lit, 1)),
411
411
  :"*baz", :qux, :quuz),
412
- s(:nil))
412
+ s(:nil))
413
413
  end
414
414
 
415
415
  it "works when the method name is an operator" do
@@ -424,14 +424,14 @@ describe RipperRubyParser::Parser do
424
424
  "foo do; end".
425
425
  must_be_parsed_as s(:iter,
426
426
  s(:call, nil, :foo),
427
- s(:args))
427
+ 0)
428
428
  end
429
429
 
430
430
  it "works with next with no arguments" do
431
431
  "foo do; next; end".
432
432
  must_be_parsed_as s(:iter,
433
433
  s(:call, nil, :foo),
434
- s(:args),
434
+ 0,
435
435
  s(:next))
436
436
  end
437
437
 
@@ -439,7 +439,7 @@ describe RipperRubyParser::Parser do
439
439
  "foo do; next bar; end".
440
440
  must_be_parsed_as s(:iter,
441
441
  s(:call, nil, :foo),
442
- s(:args),
442
+ 0,
443
443
  s(:next, s(:call, nil, :bar)))
444
444
  end
445
445
 
@@ -447,7 +447,7 @@ describe RipperRubyParser::Parser do
447
447
  "foo do; next bar, baz; end".
448
448
  must_be_parsed_as s(:iter,
449
449
  s(:call, nil, :foo),
450
- s(:args),
450
+ 0,
451
451
  s(:next,
452
452
  s(:array,
453
453
  s(:call, nil, :bar),
@@ -458,7 +458,7 @@ describe RipperRubyParser::Parser do
458
458
  "foo do; break; end".
459
459
  must_be_parsed_as s(:iter,
460
460
  s(:call, nil, :foo),
461
- s(:args),
461
+ 0,
462
462
  s(:break))
463
463
  end
464
464
 
@@ -466,7 +466,7 @@ describe RipperRubyParser::Parser do
466
466
  "foo do; break bar; end".
467
467
  must_be_parsed_as s(:iter,
468
468
  s(:call, nil, :foo),
469
- s(:args),
469
+ 0,
470
470
  s(:break, s(:call, nil, :bar)))
471
471
  end
472
472
 
@@ -474,7 +474,7 @@ describe RipperRubyParser::Parser do
474
474
  "foo do; break bar, baz; end".
475
475
  must_be_parsed_as s(:iter,
476
476
  s(:call, nil, :foo),
477
- s(:args),
477
+ 0,
478
478
  s(:break,
479
479
  s(:array,
480
480
  s(:call, nil, :bar),
@@ -485,10 +485,17 @@ describe RipperRubyParser::Parser do
485
485
  "foo do; redo; end".
486
486
  must_be_parsed_as s(:iter,
487
487
  s(:call, nil, :foo),
488
- s(:args),
488
+ 0,
489
489
  s(:redo))
490
490
  end
491
491
 
492
+ it "works with zero arguments" do
493
+ "foo do ||; end".
494
+ must_be_parsed_as s(:iter,
495
+ s(:call, nil, :foo),
496
+ s(:args))
497
+ end
498
+
492
499
  it "works with one argument" do
493
500
  "foo do |bar|; end".
494
501
  must_be_parsed_as s(:iter,
@@ -516,7 +523,6 @@ describe RipperRubyParser::Parser do
516
523
  s(:call, nil, :foo),
517
524
  s(:args, :bar, :"*baz"))
518
525
  end
519
-
520
526
  end
521
527
 
522
528
  describe "for yield" do
@@ -590,7 +596,7 @@ describe RipperRubyParser::Parser do
590
596
  describe "for the END keyword" do
591
597
  it "converts to a :postexe iterator" do
592
598
  "END { foo }".
593
- must_be_parsed_as s(:iter, s(:postexe), s(:args), s(:call, nil, :foo))
599
+ must_be_parsed_as s(:iter, s(:postexe), 0, s(:call, nil, :foo))
594
600
  end
595
601
  end
596
602
 
@@ -1059,7 +1065,8 @@ describe RipperRubyParser::Parser do
1059
1065
  result.must_equal s(:defs,
1060
1066
  s(:call, nil, :foo),
1061
1067
  :bar,
1062
- s(:args))
1068
+ s(:args),
1069
+ s(:nil))
1063
1070
  result.comments.must_equal "# Foo\n"
1064
1071
  end
1065
1072
 
@@ -1251,15 +1258,15 @@ describe RipperRubyParser::Parser do
1251
1258
  result.line.must_equal 1
1252
1259
  end
1253
1260
 
1254
- it "assigns line numbers to nested sexps that don't generate their own line numbers" do
1261
+ it "assigns line numbers to nested sexps without their own line numbers" do
1255
1262
  result = parser.parse "foo(bar) do\nnext baz\nend\n"
1256
1263
  result.must_equal s(:iter,
1257
1264
  s(:call, nil, :foo, s(:call, nil, :bar)),
1258
- s(:args),
1265
+ 0,
1259
1266
  s(:next, s(:call, nil, :baz)))
1260
1267
  arglist = result[1][3]
1261
1268
  block = result[3]
1262
- nums = [ arglist.line, block.line ]
1269
+ nums = [arglist.line, block.line]
1263
1270
  nums.must_equal [1, 2]
1264
1271
  end
1265
1272
 
@@ -23,16 +23,6 @@ describe RipperRubyParser::SexpProcessor do
23
23
  end
24
24
 
25
25
  describe "#process" do
26
- it "can handle s(s()) constructs" do
27
- sexp = s(s())
28
- processor.process sexp
29
- end
30
-
31
- it "can handle line number information constructs" do
32
- sexp = s(1, 6)
33
- processor.process sexp
34
- end
35
-
36
26
  describe "for a :program sexp" do
37
27
  it "strips off the outer :program node" do
38
28
  sexp = s(:program, s(s(:foo)))
@@ -55,7 +45,6 @@ describe RipperRubyParser::SexpProcessor do
55
45
  end
56
46
  end
57
47
 
58
- if false
59
48
  describe "for an :args_add_block sexp" do
60
49
  it "transforms a one-argument sexp to an :arglist" do
61
50
  sexp = s(:args_add_block, s(s(:foo)), false)
@@ -69,7 +58,6 @@ describe RipperRubyParser::SexpProcessor do
69
58
  result.must_equal s(:arglist, s(:foo_p), s(:bar_p))
70
59
  end
71
60
  end
72
- end
73
61
 
74
62
  describe "for a :command sexp" do
75
63
  it "transforms a sexp to a :call" do
@@ -178,7 +166,6 @@ describe RipperRubyParser::SexpProcessor do
178
166
  s(:bodystmt, s(s(:void_stmt)), nil, nil, nil))
179
167
  result = processor.process sexp
180
168
  result.must_equal s(:defn, :foo, s(:args), s(:nil))
181
-
182
169
  end
183
170
  end
184
171
 
@@ -217,7 +204,7 @@ describe RipperRubyParser::SexpProcessor do
217
204
  s(:brace_block, nil, s(s(:bar))))
218
205
  result = processor.process sexp
219
206
  result.must_equal s(:iter,
220
- s(:call, s(:foo_p), :baz), s(:args),
207
+ s(:call, s(:foo_p), :baz), 0,
221
208
  s(:bar_p))
222
209
  end
223
210
 
metadata CHANGED
@@ -1,83 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripper_ruby_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matijs van Zuijlen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-07 00:00:00.000000000 Z
11
+ date: 2017-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sexp_processor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 4.4.1
19
+ version: 4.10.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 4.4.1
26
+ version: 4.10.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '5.2'
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
40
  version: '5.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '12.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '12.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: ruby_parser
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 3.3.0
61
+ version: 3.10.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 3.3.0
68
+ version: 3.10.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  description: |2
@@ -90,71 +104,72 @@ extensions: []
90
104
  extra_rdoc_files:
91
105
  - README.md
92
106
  files:
107
+ - CHANGELOG.md
108
+ - README.md
109
+ - Rakefile
93
110
  - lib/ripper_ruby_parser.rb
94
111
  - lib/ripper_ruby_parser/commenting_ripper_parser.rb
95
- - lib/ripper_ruby_parser/sexp_processor.rb
96
- - lib/ripper_ruby_parser/syntax_error.rb
97
- - lib/ripper_ruby_parser/sexp_ext.rb
112
+ - lib/ripper_ruby_parser/parser.rb
98
113
  - lib/ripper_ruby_parser/sexp_handlers.rb
99
- - lib/ripper_ruby_parser/sexp_handlers/operators.rb
100
- - lib/ripper_ruby_parser/sexp_handlers/literals.rb
101
- - lib/ripper_ruby_parser/sexp_handlers/assignment.rb
102
114
  - lib/ripper_ruby_parser/sexp_handlers/arguments.rb
103
- - lib/ripper_ruby_parser/sexp_handlers/blocks.rb
104
- - lib/ripper_ruby_parser/sexp_handlers/loops.rb
105
115
  - lib/ripper_ruby_parser/sexp_handlers/arrays.rb
106
- - lib/ripper_ruby_parser/sexp_handlers/methods.rb
116
+ - lib/ripper_ruby_parser/sexp_handlers/assignment.rb
117
+ - lib/ripper_ruby_parser/sexp_handlers/blocks.rb
118
+ - lib/ripper_ruby_parser/sexp_handlers/conditionals.rb
107
119
  - lib/ripper_ruby_parser/sexp_handlers/hashes.rb
108
120
  - lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb
109
- - lib/ripper_ruby_parser/sexp_handlers/conditionals.rb
121
+ - lib/ripper_ruby_parser/sexp_handlers/literals.rb
122
+ - lib/ripper_ruby_parser/sexp_handlers/loops.rb
110
123
  - lib/ripper_ruby_parser/sexp_handlers/method_calls.rb
124
+ - lib/ripper_ruby_parser/sexp_handlers/methods.rb
125
+ - lib/ripper_ruby_parser/sexp_handlers/operators.rb
126
+ - lib/ripper_ruby_parser/sexp_processor.rb
127
+ - lib/ripper_ruby_parser/syntax_error.rb
111
128
  - lib/ripper_ruby_parser/version.rb
112
- - lib/ripper_ruby_parser/parser.rb
129
+ - test/end_to_end/comments_test.rb
130
+ - test/end_to_end/comparison_test.rb
131
+ - test/end_to_end/error_conditions_test.rb
132
+ - test/end_to_end/lib_comparison_test.rb
133
+ - test/end_to_end/line_numbering_test.rb
134
+ - test/end_to_end/samples_comparison_test.rb
135
+ - test/end_to_end/test_comparison_test.rb
136
+ - test/pt_testcase/pt_test.rb
137
+ - test/samples/inline.rb
113
138
  - test/test_helper.rb
114
- - test/unit/sexp_processor_test.rb
139
+ - test/unit/commenting_ripper_parser_test.rb
115
140
  - test/unit/parser_assignment_test.rb
116
- - test/unit/parser_loops_test.rb
117
- - test/unit/parser_operators_test.rb
118
141
  - test/unit/parser_blocks_test.rb
119
- - test/unit/parser_method_calls_test.rb
120
- - test/unit/parser_literals_test.rb
121
- - test/unit/version_test.rb
122
- - test/unit/commenting_ripper_parser_test.rb
123
142
  - test/unit/parser_conditionals_test.rb
143
+ - test/unit/parser_literals_test.rb
144
+ - test/unit/parser_loops_test.rb
145
+ - test/unit/parser_method_calls_test.rb
146
+ - test/unit/parser_operators_test.rb
124
147
  - test/unit/parser_test.rb
125
- - test/pt_testcase/pt_test.rb
126
- - test/end_to_end/samples_comparison_test.rb
127
- - test/end_to_end/lib_comparison_test.rb
128
- - test/end_to_end/error_conditions_test.rb
129
- - test/end_to_end/line_numbering_test.rb
130
- - test/end_to_end/comparison_test.rb
131
- - test/end_to_end/test_comparison_test.rb
132
- - test/end_to_end/comments_test.rb
133
- - README.md
134
- - Rakefile
148
+ - test/unit/sexp_processor_test.rb
149
+ - test/unit/version_test.rb
135
150
  homepage: http://www.github.com/mvz/ripper_ruby_parser
136
151
  licenses:
137
152
  - MIT
138
153
  metadata: {}
139
154
  post_install_message:
140
155
  rdoc_options:
141
- - --main
156
+ - "--main"
142
157
  - README.md
143
158
  require_paths:
144
159
  - lib
145
160
  required_ruby_version: !ruby/object:Gem::Requirement
146
161
  requirements:
147
- - - '>='
162
+ - - ">="
148
163
  - !ruby/object:Gem::Version
149
- version: '0'
164
+ version: 2.0.0
150
165
  required_rubygems_version: !ruby/object:Gem::Requirement
151
166
  requirements:
152
- - - '>='
167
+ - - ">="
153
168
  - !ruby/object:Gem::Version
154
169
  version: '0'
155
170
  requirements: []
156
171
  rubyforge_project:
157
- rubygems_version: 2.0.14
172
+ rubygems_version: 2.6.13
158
173
  signing_key:
159
174
  specification_version: 4
160
175
  summary: Parse with Ripper, produce sexps that are compatible with RubyParser.
@@ -167,6 +182,7 @@ test_files:
167
182
  - test/end_to_end/samples_comparison_test.rb
168
183
  - test/end_to_end/test_comparison_test.rb
169
184
  - test/pt_testcase/pt_test.rb
185
+ - test/samples/inline.rb
170
186
  - test/test_helper.rb
171
187
  - test/unit/commenting_ripper_parser_test.rb
172
188
  - test/unit/parser_assignment_test.rb
@@ -1,14 +0,0 @@
1
- require 'sexp_processor'
2
-
3
- module RipperRubyParser
4
- # Extensions to Sexp
5
- module SexpExt
6
- def fix_empty_type
7
- unless sexp_type.is_a? Symbol
8
- unshift :__empty
9
- end
10
- end
11
- end
12
- end
13
-
14
- Sexp.send :include, RipperRubyParser::SexpExt