ripper_ruby_parser 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -13,19 +13,10 @@ module RipperRubyParser
13
13
  _, receiver, _, method, params, body = exp.shift 6
14
14
  params = convert_special_args(process(params))
15
15
 
16
- body = in_method do
17
- process(body)
18
- end
19
-
20
- if body.length == 1 && body.first.sexp_type == :block
21
- body = body.first
22
- body.shift
23
- end
24
-
25
16
  s(:defs,
26
17
  process(receiver),
27
18
  extract_node_symbol(method),
28
- params, *body)
19
+ params, *method_body(body))
29
20
  end
30
21
 
31
22
  def process_return exp
@@ -81,7 +72,7 @@ module RipperRubyParser
81
72
  end
82
73
 
83
74
  def make_method_name_literal exp
84
- process(exp).tap {|it| it[0] = :lit}
75
+ process(exp).tap { |it| it[0] = :lit }
85
76
  end
86
77
 
87
78
  def method_body exp
@@ -99,9 +90,9 @@ module RipperRubyParser
99
90
  end
100
91
 
101
92
  SPECIAL_ARG_MARKER = {
102
- :splat => "*",
103
- :blockarg => "&"
104
- }
93
+ splat: "*",
94
+ blockarg: "&"
95
+ }.freeze
105
96
 
106
97
  def convert_special_args args
107
98
  args.map! do |item|
@@ -109,10 +100,6 @@ module RipperRubyParser
109
100
  item
110
101
  else
111
102
  case item.sexp_type
112
- when *SPECIAL_ARG_MARKER.keys
113
- marker = SPECIAL_ARG_MARKER[item.sexp_type]
114
- name = extract_node_symbol item[1]
115
- :"#{marker}#{name}"
116
103
  when :lvar
117
104
  item[1]
118
105
  when :masgn
@@ -125,6 +112,10 @@ module RipperRubyParser
125
112
  else
126
113
  item
127
114
  end
115
+ when *SPECIAL_ARG_MARKER.keys
116
+ marker = SPECIAL_ARG_MARKER[item.sexp_type]
117
+ name = extract_node_symbol item[1]
118
+ :"#{marker}#{name}"
128
119
  else
129
120
  item
130
121
  end
@@ -6,15 +6,15 @@ module RipperRubyParser
6
6
  :"||" => :or,
7
7
  :and => :and,
8
8
  :or => :or
9
- }
9
+ }.freeze
10
10
 
11
11
  UNARY_OPERATOR_MAP = {
12
- :not => :!
13
- }
12
+ not: :!
13
+ }.freeze
14
14
 
15
15
  NEGATED_BINARY_OPERATOR_MAP = {
16
- :"!~" => :=~,
17
- }
16
+ :"!~" => :=~
17
+ }.freeze
18
18
 
19
19
  def process_binary exp
20
20
  _, left, op, right = exp.shift 4
@@ -30,7 +30,7 @@ module RipperRubyParser
30
30
  end
31
31
  end
32
32
 
33
- def make_boolean_operator(op, left, right)
33
+ def make_boolean_operator op, left, right
34
34
  if left.first == :paren
35
35
  s(op, process(left), process(right))
36
36
  else
@@ -38,7 +38,7 @@ module RipperRubyParser
38
38
  end
39
39
  end
40
40
 
41
- def make_regexp_match_operator(op, left, right)
41
+ def make_regexp_match_operator op, left, right
42
42
  if left.sexp_type == :regexp_literal
43
43
  s(:match2, process(left), process(right))
44
44
  elsif right.sexp_type == :regexp_literal
@@ -52,7 +52,7 @@ module RipperRubyParser
52
52
  _, op, arg = exp.shift 3
53
53
  arg = process(arg)
54
54
  op = UNARY_OPERATOR_MAP[op] || op
55
- if is_literal?(arg) && op != :!
55
+ if literal?(arg) && op != :!
56
56
  s(:lit, arg[1].send(op))
57
57
  else
58
58
  s(:call, arg, op)
@@ -63,7 +63,7 @@ module RipperRubyParser
63
63
  _, left, right = exp.shift 3
64
64
  left = process(left)
65
65
  right = process(right)
66
- if is_literal?(left) && is_literal?(right)
66
+ if literal?(left) && literal?(right)
67
67
  s(:lit, Range.new(left[1], right[1]))
68
68
  else
69
69
  s(:dot2, left, right)
@@ -74,7 +74,7 @@ module RipperRubyParser
74
74
  _, left, right = exp.shift 3
75
75
  left = process(left)
76
76
  right = process(right)
77
- if is_literal?(left) && is_literal?(right)
77
+ if literal?(left) && literal?(right)
78
78
  s(:lit, Range.new(left[1], right[1], true))
79
79
  else
80
80
  s(:dot3, left, right)
@@ -1,6 +1,5 @@
1
1
  require 'sexp_processor'
2
2
  require 'ripper_ruby_parser/sexp_handlers'
3
- require 'ripper_ruby_parser/sexp_ext'
4
3
 
5
4
  module RipperRubyParser
6
5
  # Processes the sexp created by Ripper to what RubyParser would produce.
@@ -36,7 +35,6 @@ module RipperRubyParser
36
35
 
37
36
  def process exp
38
37
  return nil if exp.nil?
39
- exp.fix_empty_type
40
38
 
41
39
  result = super
42
40
  trickle_up_line_numbers result
@@ -112,12 +110,12 @@ module RipperRubyParser
112
110
 
113
111
  def process_paren exp
114
112
  _, body = exp.shift 2
115
- if body.size == 0
113
+ if body.empty?
116
114
  s()
117
115
  elsif body.first.is_a? Symbol
118
116
  process body
119
117
  else
120
- body.map! {|it| convert_void_stmt_to_nil process it }
118
+ body.map! { |it| convert_void_stmt_to_nil process it }
121
119
  safe_wrap_in_block body
122
120
  end
123
121
  end
@@ -136,16 +134,16 @@ module RipperRubyParser
136
134
 
137
135
  def process_END exp
138
136
  _, body = exp.shift 2
139
- s(:iter, s(:postexe), s(:args), *map_body(body))
137
+ s(:iter, s(:postexe), 0, *map_body(body))
140
138
  end
141
139
 
142
140
  # number literals
143
141
  def process_at_int exp
144
- make_literal(exp) {|val| Integer(val) }
142
+ make_literal(exp) { |val| Integer(val) }
145
143
  end
146
144
 
147
145
  def process_at_float exp
148
- make_literal(exp) {|val| val.to_f }
146
+ make_literal(exp, &:to_f)
149
147
  end
150
148
 
151
149
  # character literals
@@ -155,7 +153,7 @@ module RipperRubyParser
155
153
  end
156
154
 
157
155
  def process_at_label exp
158
- make_literal(exp) {|val| val.chop.to_sym }
156
+ make_literal(exp) { |val| val.chop.to_sym }
159
157
  end
160
158
 
161
159
  # symbol-like sexps
@@ -213,9 +211,7 @@ module RipperRubyParser
213
211
  def const_ref_to_const_with_line_number const_ref
214
212
  const = process(const_ref)
215
213
  line = const.line
216
- if const.sexp_type == :const
217
- const = const[1]
218
- end
214
+ const = const[1] if const.sexp_type == :const
219
215
  return const, line
220
216
  end
221
217
 
@@ -230,9 +226,10 @@ module RipperRubyParser
230
226
  body
231
227
  end
232
228
 
233
- def make_identifier(type, exp)
234
- with_position_from_node_symbol(exp) {|ident|
235
- s(type, ident) }
229
+ def make_identifier type, exp
230
+ with_position_from_node_symbol(exp) do |ident|
231
+ s(type, ident)
232
+ end
236
233
  end
237
234
 
238
235
  def make_literal exp
@@ -1,5 +1,3 @@
1
1
  module RipperRubyParser
2
- class SyntaxError < RuntimeError
3
-
4
- end
2
+ class SyntaxError < RuntimeError; end
5
3
  end
@@ -1,3 +1,3 @@
1
1
  module RipperRubyParser
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'.freeze
3
3
  end
@@ -146,4 +146,3 @@ describe "Using RipperRubyParser and RubyParser" do
146
146
  end
147
147
  end
148
148
  end
149
-
@@ -25,5 +25,3 @@ describe "Using RipperRubyParser and RubyParser" do
25
25
  end
26
26
  end
27
27
  end
28
-
29
-
@@ -60,4 +60,3 @@ describe "Using RipperRubyParser and RubyParser" do
60
60
  end
61
61
  end
62
62
  end
63
-
@@ -10,7 +10,7 @@ describe "Using RipperRubyParser and RubyParser" do
10
10
  RubyParser.new
11
11
  end
12
12
 
13
- Dir.glob("samples/**/*.rb").each do |file|
13
+ Dir.glob(File.expand_path("../samples/*.rb", File.dirname(__FILE__))).each do |file|
14
14
  describe "for #{file}" do
15
15
  let :program do
16
16
  File.read file
@@ -28,6 +28,3 @@ describe "Using RipperRubyParser and RubyParser" do
28
28
  end
29
29
  end
30
30
  end
31
-
32
-
33
-
@@ -1,16 +1,16 @@
1
1
  require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
2
2
  require 'pt_testcase'
3
3
 
4
- class RipperRubyParser::Parser
4
+ class TestParser < RipperRubyParser::Parser
5
5
  def process input
6
6
  parse input
7
7
  end
8
8
  end
9
9
 
10
- SKIPPED_TESTS = ["dstr_heredoc_windoze_sucks"]
10
+ SKIPPED_TESTS = ["dstr_heredoc_windoze_sucks"].freeze
11
11
 
12
12
  class RubyParserTestCase < ParseTreeTestCase
13
- def self.previous key
13
+ def self.previous _key
14
14
  "Ruby"
15
15
  end
16
16
 
@@ -39,6 +39,6 @@ class TestRuby19Parser < RubyParserTestCase
39
39
  def setup
40
40
  super
41
41
 
42
- self.processor = RipperRubyParser::Parser.new
42
+ self.processor = TestParser.new
43
43
  end
44
44
  end