ripper_ruby_parser 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -14,8 +14,13 @@ namespace :test do
14
14
  t.warning = true
15
15
  end
16
16
 
17
- task :run => [:unit, :end_to_end]
17
+ Rake::TestTask.new(:pt_testcase) do |t|
18
+ t.libs = ['lib']
19
+ t.test_files = FileList['test/pt_testcase/*_test.rb']
20
+ t.warning = true
21
+ end
18
22
 
23
+ task :run => [:unit, :end_to_end]
19
24
  end
20
25
 
21
26
  desc 'Alias to test:run'
@@ -1,3 +1,7 @@
1
+ if RUBY_VERSION < "1.9.3"
2
+ raise LoadError, "Only ruby version 1.9.3 and up are supported"
3
+ end
4
+
1
5
  require 'ripper_ruby_parser/version'
2
6
  require 'ripper_ruby_parser/parser'
3
7
 
@@ -7,6 +7,13 @@ module RipperRubyParser
7
7
  lvalue = process(lvalue)
8
8
  value = process(value)
9
9
 
10
+ case value.sexp_type
11
+ when :splat
12
+ value = s(:svalue, value)
13
+ when :fake_array
14
+ value = s(:svalue, s(:array, *value.sexp_body))
15
+ end
16
+
10
17
  with_line_number(lvalue.line,
11
18
  create_regular_assignment_sub_type(lvalue, value))
12
19
  end
@@ -25,7 +32,12 @@ module RipperRubyParser
25
32
 
26
33
  right = process(right)
27
34
 
28
- unless [:array, :splat].include? right.sexp_type
35
+ case right.sexp_type
36
+ when :fake_array
37
+ right[0] = :array
38
+ when :array, :splat
39
+ # Do nothing
40
+ else
29
41
  right = s(:to_ary, right)
30
42
  end
31
43
 
@@ -36,15 +48,17 @@ module RipperRubyParser
36
48
  _, inner, last = exp.shift 3
37
49
  inner.map! {|item| process(item)}
38
50
  inner.push process(last) unless last.nil?
39
- s(:array, *inner)
51
+ s(:fake_array, *inner)
40
52
  end
41
53
 
42
54
  def process_mrhs_add_star exp
43
55
  exp = generic_add_star exp
44
- unless exp.first.is_a? Symbol
45
- exp = exp.first
56
+
57
+ if exp.first.is_a? Symbol
58
+ exp
59
+ else
60
+ exp.first
46
61
  end
47
- exp
48
62
  end
49
63
 
50
64
  def process_mlhs_add_star exp
@@ -6,11 +6,8 @@ module RipperRubyParser
6
6
  block = process(block)
7
7
  args = block[1]
8
8
  stmt = block[2].first
9
- if stmt.nil?
10
- s(:iter, process(call), args)
11
- else
12
- s(:iter, process(call), args, stmt)
13
- end
9
+ call = process(call)
10
+ make_iter call, args, stmt
14
11
  end
15
12
 
16
13
  def process_brace_block exp
@@ -46,15 +43,8 @@ module RipperRubyParser
46
43
  _, args, _ = exp.shift 3
47
44
 
48
45
  names = process(args)
49
- names.shift
50
46
 
51
- if names.length == 1 and names.first.sexp_type == :lvar
52
- s(:lasgn, names.first[1])
53
- elsif names.length == 1 and names.first.sexp_type == :masgn
54
- names.first
55
- else
56
- s(:masgn, s(:array, *names.map { |name| arg_name_to_lasgn(name) }))
57
- end
47
+ args_to_assignment names
58
48
  end
59
49
 
60
50
  def process_begin exp
@@ -155,6 +145,13 @@ module RipperRubyParser
155
145
  end
156
146
  end
157
147
 
148
+ def process_lambda exp
149
+ _, args, statements = exp.shift 3
150
+ make_iter(s(:call, nil, :lambda, s(:arglist)),
151
+ args_to_assignment(process(args)),
152
+ *handle_potentially_typeless_sexp(statements))
153
+ end
154
+
158
155
  private
159
156
 
160
157
  def handle_generic_block exp
@@ -179,6 +176,8 @@ module RipperRubyParser
179
176
  case name.sexp_type
180
177
  when :lvar
181
178
  s(:lasgn, name[1])
179
+ when :blockarg
180
+ s(:lasgn, :"&#{name[1][1]}")
182
181
  when :splat
183
182
  if name[1].nil?
184
183
  s(:splat)
@@ -190,6 +189,24 @@ module RipperRubyParser
190
189
  end
191
190
  end
192
191
 
192
+ def make_iter call, args, stmt
193
+ if stmt.nil?
194
+ s(:iter, call, args)
195
+ else
196
+ s(:iter, call, args, stmt)
197
+ end
198
+ end
199
+
200
+ def args_to_assignment names
201
+ names.shift
202
+ if names.length == 1 and names.first.sexp_type == :lvar
203
+ s(:lasgn, names.first[1])
204
+ elsif names.length == 1 and names.first.sexp_type == :masgn
205
+ names.first
206
+ else
207
+ s(:masgn, s(:array, *names.map { |name| arg_name_to_lasgn(name) }))
208
+ end
209
+ end
193
210
  end
194
211
  end
195
212
  end
@@ -1,3 +1,3 @@
1
1
  module RipperRubyParser
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -0,0 +1,30 @@
1
+ require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
2
+ require 'pt_testcase'
3
+
4
+ class RipperRubyParser::Parser
5
+ def process input
6
+ parse input
7
+ end
8
+ end
9
+
10
+ class RubyParserTestCase < ParseTreeTestCase
11
+ def self.previous key
12
+ "Ruby"
13
+ end
14
+
15
+ def self.generate_test klass, node, data, input_name, output_name
16
+ return if Array === data['Ruby']
17
+
18
+ output_name = "ParseTree"
19
+
20
+ super
21
+ end
22
+ end
23
+
24
+ class TestRuby19Parser < RubyParserTestCase
25
+ def setup
26
+ super
27
+
28
+ self.processor = RipperRubyParser::Parser.new
29
+ end
30
+ end
@@ -16,6 +16,47 @@ describe RipperRubyParser::Parser do
16
16
  s(:colon3, :Foo),
17
17
  s(:call, nil, :bar, s(:arglist)))
18
18
  end
19
+
20
+ describe "with a right-hand splat" do
21
+ specify do
22
+ "foo = *bar".
23
+ must_be_parsed_as s(:lasgn, :foo,
24
+ s(:svalue,
25
+ s(:splat,
26
+ s(:call, nil, :bar, s(:arglist)))))
27
+ end
28
+
29
+ specify do
30
+ "foo = bar, *baz".
31
+ must_be_parsed_as s(:lasgn, :foo,
32
+ s(:svalue,
33
+ s(:array,
34
+ s(:call, nil, :bar, s(:arglist)),
35
+ s(:splat,
36
+ s(:call, nil, :baz, s(:arglist))))))
37
+ end
38
+ end
39
+
40
+ describe "with several items on the right hand side" do
41
+ specify do
42
+ "foo = bar, baz".
43
+ must_be_parsed_as s(:lasgn, :foo,
44
+ s(:svalue,
45
+ s(:array,
46
+ s(:call, nil, :bar, s(:arglist)),
47
+ s(:call, nil, :baz, s(:arglist)))))
48
+ end
49
+ end
50
+
51
+ describe "with an array literal on the right hand side" do
52
+ specify do
53
+ "foo = [bar, baz]".
54
+ must_be_parsed_as s(:lasgn, :foo,
55
+ s(:array,
56
+ s(:call, nil, :bar, s(:arglist)),
57
+ s(:call, nil, :baz, s(:arglist))))
58
+ end
59
+ end
19
60
  end
20
61
 
21
62
  describe "for multiple assignment" do
@@ -30,6 +30,16 @@ describe RipperRubyParser::Parser do
30
30
  s(:masgn, s(:array, s(:lasgn, :bar), s(:splat))))
31
31
  end
32
32
 
33
+ specify do
34
+ "foo do |bar, &baz| end".
35
+ must_be_parsed_as s(:iter,
36
+ s(:call, nil, :foo, s(:arglist)),
37
+ s(:masgn,
38
+ s(:array,
39
+ s(:lasgn, :bar),
40
+ s(:lasgn, :"&baz"))))
41
+ end
42
+
33
43
  it "behaves differently from RubyParser with a trailing comma in the block parameters" do
34
44
  "foo do |bar, | end".
35
45
  must_be_parsed_as s(:iter,
@@ -80,5 +90,15 @@ describe RipperRubyParser::Parser do
80
90
  s(:call, nil, :baz, s(:arglist))))
81
91
  end
82
92
  end
93
+
94
+ describe "for stabby lambda" do
95
+ it "works in the simple case" do
96
+ "->(foo) { bar }".
97
+ must_be_parsed_as s(:iter,
98
+ s(:call, nil, :lambda, s(:arglist)),
99
+ s(:lasgn, :foo),
100
+ s(:call, nil, :bar, s(:arglist)))
101
+ end
102
+ end
83
103
  end
84
104
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripper_ruby_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-04 00:00:00.000000000 Z
12
+ date: 2012-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sexp_processor
16
- requirement: &21062800 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *21062800
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: minitest
27
- requirement: &21062280 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 2.11.2
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *21062280
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.11.2
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rake
38
- requirement: &21061800 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 0.9.2
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *21061800
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: ruby_parser
49
- requirement: &21061320 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: 2.3.1
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *21061320
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.3.1
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: simplecov
60
- requirement: &21060940 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,7 +85,12 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *21060940
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  description:
70
95
  email:
71
96
  - matijs@matijs.net
@@ -75,44 +100,45 @@ extra_rdoc_files:
75
100
  - README.rdoc
76
101
  files:
77
102
  - lib/ripper_ruby_parser.rb
103
+ - lib/ripper_ruby_parser/sexp_processor.rb
104
+ - lib/ripper_ruby_parser/syntax_error.rb
78
105
  - lib/ripper_ruby_parser/sexp_ext.rb
79
- - lib/ripper_ruby_parser/commenting_sexp_builder.rb
106
+ - lib/ripper_ruby_parser/sexp_handlers.rb
80
107
  - lib/ripper_ruby_parser/sexp_handlers/operators.rb
81
- - lib/ripper_ruby_parser/sexp_handlers/methods.rb
82
- - lib/ripper_ruby_parser/sexp_handlers/arrays.rb
83
- - lib/ripper_ruby_parser/sexp_handlers/method_calls.rb
84
- - lib/ripper_ruby_parser/sexp_handlers/loops.rb
85
- - lib/ripper_ruby_parser/sexp_handlers/conditionals.rb
86
- - lib/ripper_ruby_parser/sexp_handlers/blocks.rb
87
108
  - lib/ripper_ruby_parser/sexp_handlers/literals.rb
88
109
  - lib/ripper_ruby_parser/sexp_handlers/assignment.rb
89
110
  - lib/ripper_ruby_parser/sexp_handlers/arguments.rb
111
+ - lib/ripper_ruby_parser/sexp_handlers/blocks.rb
112
+ - lib/ripper_ruby_parser/sexp_handlers/loops.rb
113
+ - lib/ripper_ruby_parser/sexp_handlers/arrays.rb
114
+ - lib/ripper_ruby_parser/sexp_handlers/methods.rb
90
115
  - lib/ripper_ruby_parser/sexp_handlers/hashes.rb
91
116
  - lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb
92
- - lib/ripper_ruby_parser/parser.rb
117
+ - lib/ripper_ruby_parser/sexp_handlers/conditionals.rb
118
+ - lib/ripper_ruby_parser/sexp_handlers/method_calls.rb
93
119
  - lib/ripper_ruby_parser/version.rb
94
- - lib/ripper_ruby_parser/sexp_handlers.rb
95
- - lib/ripper_ruby_parser/syntax_error.rb
96
- - lib/ripper_ruby_parser/sexp_processor.rb
120
+ - lib/ripper_ruby_parser/commenting_sexp_builder.rb
121
+ - lib/ripper_ruby_parser/parser.rb
97
122
  - test/test_helper.rb
98
- - test/end_to_end/lib_comparison_test.rb
99
- - test/end_to_end/samples_comparison_test.rb
100
- - test/end_to_end/comparison_test.rb
101
- - test/end_to_end/comments_test.rb
102
- - test/end_to_end/test_comparison_test.rb
103
- - test/end_to_end/line_numbering_test.rb
104
- - test/end_to_end/error_conditions_test.rb
105
- - test/unit/parser_literals_test.rb
106
- - test/unit/parser_test.rb
107
- - test/unit/parser_blocks_test.rb
108
123
  - test/unit/sexp_processor_test.rb
109
- - test/unit/parser_operators_test.rb
110
- - test/unit/parser_conditionals_test.rb
111
- - test/unit/version_test.rb
112
124
  - test/unit/parser_assignment_test.rb
113
- - test/unit/parser_method_calls_test.rb
114
125
  - test/unit/parser_loops_test.rb
126
+ - test/unit/parser_operators_test.rb
127
+ - test/unit/parser_blocks_test.rb
128
+ - test/unit/parser_method_calls_test.rb
129
+ - test/unit/parser_literals_test.rb
130
+ - test/unit/version_test.rb
115
131
  - test/unit/commenting_sexp_builder_test.rb
132
+ - test/unit/parser_conditionals_test.rb
133
+ - test/unit/parser_test.rb
134
+ - test/pt_testcase/pt_test.rb
135
+ - test/end_to_end/samples_comparison_test.rb
136
+ - test/end_to_end/lib_comparison_test.rb
137
+ - test/end_to_end/error_conditions_test.rb
138
+ - test/end_to_end/line_numbering_test.rb
139
+ - test/end_to_end/comparison_test.rb
140
+ - test/end_to_end/test_comparison_test.rb
141
+ - test/end_to_end/comments_test.rb
116
142
  - README.rdoc
117
143
  - Rakefile
118
144
  homepage: http://www.github.com/mvz/ripper_ruby_parser
@@ -126,9 +152,9 @@ require_paths:
126
152
  required_ruby_version: !ruby/object:Gem::Requirement
127
153
  none: false
128
154
  requirements:
129
- - - ~>
155
+ - - ! '>='
130
156
  - !ruby/object:Gem::Version
131
- version: 1.9.3
157
+ version: '0'
132
158
  required_rubygems_version: !ruby/object:Gem::Requirement
133
159
  none: false
134
160
  requirements:
@@ -137,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
163
  version: '0'
138
164
  requirements: []
139
165
  rubyforge_project:
140
- rubygems_version: 1.8.11
166
+ rubygems_version: 1.8.23
141
167
  signing_key:
142
168
  specification_version: 3
143
169
  summary: Parse with Ripper, produce sexps that are compatible with RubyParser.
@@ -149,6 +175,7 @@ test_files:
149
175
  - test/end_to_end/line_numbering_test.rb
150
176
  - test/end_to_end/samples_comparison_test.rb
151
177
  - test/end_to_end/test_comparison_test.rb
178
+ - test/pt_testcase/pt_test.rb
152
179
  - test/test_helper.rb
153
180
  - test/unit/commenting_sexp_builder_test.rb
154
181
  - test/unit/parser_assignment_test.rb
@@ -161,3 +188,4 @@ test_files:
161
188
  - test/unit/parser_test.rb
162
189
  - test/unit/sexp_processor_test.rb
163
190
  - test/unit/version_test.rb
191
+ has_rdoc: