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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/README.md +3 -3
- data/Rakefile +4 -4
- data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +5 -7
- data/lib/ripper_ruby_parser/parser.rb +2 -3
- data/lib/ripper_ruby_parser/sexp_handlers/arguments.rb +2 -6
- data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +16 -17
- data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +5 -5
- data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +6 -7
- data/lib/ripper_ruby_parser/sexp_handlers/hashes.rb +4 -5
- data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +7 -11
- data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +35 -26
- data/lib/ripper_ruby_parser/sexp_handlers/loops.rb +19 -18
- data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +15 -15
- data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +9 -18
- data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +10 -10
- data/lib/ripper_ruby_parser/sexp_processor.rb +11 -14
- data/lib/ripper_ruby_parser/syntax_error.rb +1 -3
- data/lib/ripper_ruby_parser/version.rb +1 -1
- data/test/end_to_end/comparison_test.rb +0 -1
- data/test/end_to_end/lib_comparison_test.rb +0 -2
- data/test/end_to_end/line_numbering_test.rb +0 -1
- data/test/end_to_end/samples_comparison_test.rb +1 -1
- data/test/end_to_end/test_comparison_test.rb +0 -3
- data/test/pt_testcase/pt_test.rb +4 -4
- data/test/samples/inline.rb +704 -0
- data/test/test_helper.rb +39 -37
- data/test/unit/commenting_ripper_parser_test.rb +57 -59
- data/test/unit/parser_blocks_test.rb +19 -3
- data/test/unit/parser_conditionals_test.rb +0 -1
- data/test/unit/parser_literals_test.rb +25 -25
- data/test/unit/parser_method_calls_test.rb +19 -15
- data/test/unit/parser_test.rb +31 -24
- data/test/unit/sexp_processor_test.rb +1 -14
- metadata +67 -51
- data/lib/ripper_ruby_parser/sexp_ext.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6208b988b475f510fcd23c57a01d13e63fd65c7c
|
4
|
+
data.tar.gz: 4f304bdc21ab91d786939d6f0ca944e5ab26b9ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a2bce59fdea7e315b2e75eb4420e1eab669883981d95550cda0697509b888744c9b06fffb02b6eddb13fec5a3e009ab683091fc2eabdf49d76d8c844b61a324
|
7
|
+
data.tar.gz: 63992855bcb74ba262ea1bfa156960f41a8d948322926ceac6cf0d41fbd200a0b3cecb1fb8d4f07ba87766c8f0b7ce3aec54876216819404dcc1946fba5f2830
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Change log
|
2
|
+
|
3
|
+
## 1.1.0 / 2017-10-02
|
4
|
+
|
5
|
+
* Compatible with RubyParser 3.10.x
|
6
|
+
* Add support for Ruby 2.2, 2.3 and 2.4
|
7
|
+
* Drop support for Ruby 1.9.3
|
8
|
+
|
9
|
+
## 1.0.0 / 2014-02-07
|
10
|
+
|
11
|
+
* First major release
|
12
|
+
* Compatible with RubyParser 3.3.x
|
13
|
+
|
14
|
+
## 0.0.8 / 2012-06-22
|
15
|
+
|
16
|
+
## 0.0.7 / 2012-06-08
|
17
|
+
|
18
|
+
## 0.0.6 / 2012-04-04
|
19
|
+
|
20
|
+
## 0.0.5 / 2012-04-02
|
21
|
+
|
22
|
+
## 0.0.4 / 2012-03-31
|
23
|
+
|
24
|
+
## 0.0.3 / 2012-03-21
|
25
|
+
|
26
|
+
## 0.0.2 / 2012-03-19
|
27
|
+
|
28
|
+
## 0.0.1 / 2012-03-11
|
29
|
+
|
30
|
+
* Initial release
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Parse with Ripper, produce sexps that are compatible with RubyParser.
|
|
12
12
|
|
13
13
|
* Drop-in replacement for RubyParser.
|
14
14
|
* Should handle 1.9 and later syntax gracefully.
|
15
|
-
* Needs MRI
|
15
|
+
* Needs MRI 2.0 or higher
|
16
16
|
|
17
17
|
## Install
|
18
18
|
|
@@ -29,7 +29,7 @@ Parse with Ripper, produce sexps that are compatible with RubyParser.
|
|
29
29
|
|
30
30
|
## Requirements
|
31
31
|
|
32
|
-
* Ruby
|
32
|
+
* Ruby 2.0 or higher
|
33
33
|
* sexp_processor
|
34
34
|
|
35
35
|
## Hacking and contributing
|
@@ -49,7 +49,7 @@ If you want to send pull requests or patches, please:
|
|
49
49
|
|
50
50
|
(The MIT License)
|
51
51
|
|
52
|
-
Copyright (c) 2012, 2014 Matijs van Zuijlen
|
52
|
+
Copyright (c) 2012, 2014-2017 Matijs van Zuijlen
|
53
53
|
|
54
54
|
Permission is hereby granted, free of charge, to any person obtaining
|
55
55
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -3,7 +3,6 @@ require "bundler/gem_tasks"
|
|
3
3
|
require 'rake/testtask'
|
4
4
|
|
5
5
|
namespace :test do
|
6
|
-
|
7
6
|
Rake::TestTask.new(:unit) do |t|
|
8
7
|
t.libs = ['lib']
|
9
8
|
t.test_files = FileList['test/unit/*_test.rb']
|
@@ -22,10 +21,11 @@ namespace :test do
|
|
22
21
|
t.warning = true
|
23
22
|
end
|
24
23
|
|
25
|
-
|
24
|
+
desc "Run all three test suites"
|
25
|
+
task run: [:unit, :end_to_end, :pt_testcase]
|
26
26
|
end
|
27
27
|
|
28
28
|
desc 'Alias to test:run'
|
29
|
-
task :
|
29
|
+
task test: 'test:run'
|
30
30
|
|
31
|
-
task :
|
31
|
+
task default: :test
|
@@ -77,23 +77,23 @@ module RipperRubyParser
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def on_parse_error *args
|
80
|
-
raise SyntaxError
|
80
|
+
raise SyntaxError, *args
|
81
81
|
end
|
82
82
|
|
83
83
|
def on_class_name_error *args
|
84
|
-
raise SyntaxError
|
84
|
+
raise SyntaxError, *args
|
85
85
|
end
|
86
86
|
|
87
87
|
def on_alias_error *args
|
88
|
-
raise SyntaxError
|
88
|
+
raise SyntaxError, *args
|
89
89
|
end
|
90
90
|
|
91
91
|
def on_assign_error *args
|
92
|
-
raise SyntaxError
|
92
|
+
raise SyntaxError, *args
|
93
93
|
end
|
94
94
|
|
95
95
|
def on_param_error *args
|
96
|
-
raise SyntaxError
|
96
|
+
raise SyntaxError, *args
|
97
97
|
end
|
98
98
|
|
99
99
|
private
|
@@ -108,8 +108,6 @@ module RipperRubyParser
|
|
108
108
|
[:comment, comment || "", exp]
|
109
109
|
end
|
110
110
|
|
111
|
-
private
|
112
|
-
|
113
111
|
def suppress_warnings
|
114
112
|
old_verbose = $VERBOSE
|
115
113
|
$VERBOSE = nil
|
@@ -7,12 +7,12 @@ module RipperRubyParser
|
|
7
7
|
class Parser
|
8
8
|
attr_accessor :extra_compatible
|
9
9
|
|
10
|
-
def initialize processor=SexpProcessor.new
|
10
|
+
def initialize processor = SexpProcessor.new
|
11
11
|
@processor = processor
|
12
12
|
@extra_compatible = false
|
13
13
|
end
|
14
14
|
|
15
|
-
def parse source, filename='(string)', lineno=1
|
15
|
+
def parse source, filename = '(string)', lineno = 1
|
16
16
|
parser = CommentingRipperParser.new(source, filename, lineno)
|
17
17
|
exp = parser.parse
|
18
18
|
|
@@ -28,4 +28,3 @@ module RipperRubyParser
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
@@ -4,9 +4,7 @@ module RipperRubyParser
|
|
4
4
|
def process_args_add_block exp
|
5
5
|
_, regular, block = exp.shift 3
|
6
6
|
args = handle_potentially_typeless_sexp(regular)
|
7
|
-
if block
|
8
|
-
args << s(:block_pass, process(block))
|
9
|
-
end
|
7
|
+
args << s(:block_pass, process(block)) if block
|
10
8
|
s(:arglist, *args)
|
11
9
|
end
|
12
10
|
|
@@ -17,9 +15,7 @@ module RipperRubyParser
|
|
17
15
|
def process_arg_paren exp
|
18
16
|
_, args = exp.shift 2
|
19
17
|
args = s() if args.nil?
|
20
|
-
unless args.first.is_a? Symbol
|
21
|
-
args.unshift :arglist
|
22
|
-
end
|
18
|
+
args.unshift :arglist unless args.first.is_a? Symbol
|
23
19
|
process(args)
|
24
20
|
end
|
25
21
|
|
@@ -35,7 +35,7 @@ module RipperRubyParser
|
|
35
35
|
when :fake_array
|
36
36
|
right[0] = :array
|
37
37
|
when :splat
|
38
|
-
# Do nothing
|
38
|
+
nil # Do nothing
|
39
39
|
else
|
40
40
|
right = s(:to_ary, right)
|
41
41
|
end
|
@@ -45,7 +45,7 @@ module RipperRubyParser
|
|
45
45
|
|
46
46
|
def process_mrhs_new_from_args exp
|
47
47
|
_, inner, last = exp.shift 3
|
48
|
-
inner.map! {|item| process(item)}
|
48
|
+
inner.map! { |item| process(item) }
|
49
49
|
inner.push process(last) unless last.nil?
|
50
50
|
s(:fake_array, *inner)
|
51
51
|
end
|
@@ -79,7 +79,7 @@ module RipperRubyParser
|
|
79
79
|
|
80
80
|
lvalue = process(lvalue)
|
81
81
|
value = process(value)
|
82
|
-
operator = operator[1].
|
82
|
+
operator = operator[1].delete('=').to_sym
|
83
83
|
|
84
84
|
create_operator_assignment_sub_type lvalue, value, operator
|
85
85
|
end
|
@@ -100,17 +100,17 @@ module RipperRubyParser
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
def create_valueless_assignment_sub_type
|
103
|
+
def create_valueless_assignment_sub_type item
|
104
104
|
item = with_line_number(item.line,
|
105
105
|
create_regular_assignment_sub_type(item, nil))
|
106
106
|
item.pop
|
107
|
-
|
107
|
+
item
|
108
108
|
end
|
109
109
|
|
110
110
|
OPERATOR_ASSIGNMENT_MAP = {
|
111
111
|
:"||" => :op_asgn_or,
|
112
112
|
:"&&" => :op_asgn_and
|
113
|
-
}
|
113
|
+
}.freeze
|
114
114
|
|
115
115
|
def create_operator_assignment_sub_type lvalue, value, operator
|
116
116
|
case lvalue.sexp_type
|
@@ -146,16 +146,16 @@ module RipperRubyParser
|
|
146
146
|
end
|
147
147
|
|
148
148
|
ASSIGNMENT_SUB_TYPE_MAP = {
|
149
|
-
:
|
150
|
-
:
|
151
|
-
:
|
152
|
-
:
|
153
|
-
:
|
154
|
-
}
|
149
|
+
ivar: :iasgn,
|
150
|
+
const: :cdecl,
|
151
|
+
lvar: :lasgn,
|
152
|
+
cvar: :cvdecl,
|
153
|
+
gvar: :gasgn
|
154
|
+
}.freeze
|
155
155
|
|
156
156
|
ASSIGNMENT_IN_METHOD_SUB_TYPE_MAP = {
|
157
|
-
:
|
158
|
-
}
|
157
|
+
cvar: :cvasgn
|
158
|
+
}.freeze
|
159
159
|
|
160
160
|
def create_assignment_sub_type lvalue, value
|
161
161
|
s(map_assignment_lvalue_type(lvalue.sexp_type), lvalue[1], value)
|
@@ -163,10 +163,9 @@ module RipperRubyParser
|
|
163
163
|
|
164
164
|
def map_assignment_lvalue_type type
|
165
165
|
@in_method_body && ASSIGNMENT_IN_METHOD_SUB_TYPE_MAP[type] ||
|
166
|
-
|
167
|
-
|
166
|
+
ASSIGNMENT_SUB_TYPE_MAP[type] ||
|
167
|
+
type
|
168
168
|
end
|
169
169
|
end
|
170
170
|
end
|
171
171
|
end
|
172
|
-
|
@@ -36,7 +36,7 @@ module RipperRubyParser
|
|
36
36
|
end
|
37
37
|
|
38
38
|
args << process(splat) unless splat.nil? || splat == 0
|
39
|
-
[*rest].each {|arg| args << process(arg)}
|
39
|
+
[*rest].each { |arg| args << process(arg) }
|
40
40
|
args << process(block) unless block.nil?
|
41
41
|
|
42
42
|
s(:args, *args)
|
@@ -148,8 +148,9 @@ module RipperRubyParser
|
|
148
148
|
|
149
149
|
def process_lambda exp
|
150
150
|
_, args, statements = exp.shift 3
|
151
|
+
old_type = args.sexp_type
|
151
152
|
args = convert_special_args(process(args))
|
152
|
-
args = 0 if args == s(:args)
|
153
|
+
args = 0 if args == s(:args) && old_type == :params
|
153
154
|
make_iter(s(:call, nil, :lambda),
|
154
155
|
args,
|
155
156
|
*handle_potentially_typeless_sexp(statements))
|
@@ -160,12 +161,11 @@ module RipperRubyParser
|
|
160
161
|
def handle_generic_block exp
|
161
162
|
_, args, stmts = exp.shift 3
|
162
163
|
args = process(args)
|
163
|
-
args = 0 if args == s(:args)
|
164
164
|
# FIXME: Symbol :block is irrelevant.
|
165
165
|
s(:block, args, s(wrap_in_block(map_body(stmts))))
|
166
166
|
end
|
167
167
|
|
168
|
-
def strip_typeless_sexp
|
168
|
+
def strip_typeless_sexp block
|
169
169
|
case block.length
|
170
170
|
when 0
|
171
171
|
s(:nil)
|
@@ -177,7 +177,7 @@ module RipperRubyParser
|
|
177
177
|
end
|
178
178
|
|
179
179
|
def make_iter call, args, stmt
|
180
|
-
args
|
180
|
+
args ||= 0
|
181
181
|
if stmt.nil?
|
182
182
|
s(:iter, call, args)
|
183
183
|
else
|
@@ -71,19 +71,18 @@ module RipperRubyParser
|
|
71
71
|
|
72
72
|
private
|
73
73
|
|
74
|
-
def handle_condition
|
74
|
+
def handle_condition cond
|
75
75
|
cond = process(cond)
|
76
76
|
if (cond.sexp_type == :lit) && cond[1].is_a?(Regexp)
|
77
|
-
|
77
|
+
s(:match, cond)
|
78
78
|
elsif cond.sexp_type == :dot2
|
79
|
-
|
79
|
+
s(:flip2, *cond[1..-1])
|
80
80
|
elsif cond.sexp_type == :dot3
|
81
|
-
|
81
|
+
s(:flip3, *cond[1..-1])
|
82
|
+
else
|
83
|
+
cond
|
82
84
|
end
|
83
|
-
return cond
|
84
85
|
end
|
85
|
-
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
@@ -25,14 +25,13 @@ module RipperRubyParser
|
|
25
25
|
|
26
26
|
def make_hash_items elems
|
27
27
|
result = s()
|
28
|
-
elems.each
|
29
|
-
process(sub_exp).each
|
28
|
+
elems.each do |sub_exp|
|
29
|
+
process(sub_exp).each do |elm|
|
30
30
|
result << elm
|
31
|
-
|
32
|
-
|
31
|
+
end
|
32
|
+
end
|
33
33
|
result
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
@@ -11,22 +11,20 @@ module RipperRubyParser
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def handle_argument_list exp
|
15
15
|
if exp.nil?
|
16
|
-
s(
|
16
|
+
s()
|
17
17
|
elsif exp.first.is_a? Symbol
|
18
|
-
process(exp)
|
18
|
+
process(exp).tap(&:shift)
|
19
19
|
else
|
20
20
|
exp.map! { |sub_exp| process(sub_exp) }
|
21
|
-
exp.unshift type
|
22
|
-
exp
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
24
|
def extract_node_symbol_with_position exp
|
27
25
|
return nil if exp.nil?
|
28
26
|
return exp if exp.is_a? Symbol
|
29
|
-
|
27
|
+
|
30
28
|
_, ident, pos = exp.shift 3
|
31
29
|
return ident.to_sym, pos
|
32
30
|
end
|
@@ -37,7 +35,7 @@ module RipperRubyParser
|
|
37
35
|
ident.to_sym
|
38
36
|
end
|
39
37
|
|
40
|
-
def with_position pos, exp=nil
|
38
|
+
def with_position pos, exp = nil
|
41
39
|
(line, _) = pos
|
42
40
|
exp = yield if exp.nil?
|
43
41
|
with_line_number line, exp
|
@@ -57,13 +55,11 @@ module RipperRubyParser
|
|
57
55
|
_, args, splatarg = exp.shift 3
|
58
56
|
items = handle_potentially_typeless_sexp args
|
59
57
|
items << s(:splat, process(splatarg))
|
60
|
-
until exp.empty?
|
61
|
-
items << process(exp.shift)
|
62
|
-
end
|
58
|
+
items << process(exp.shift) until exp.empty?
|
63
59
|
items
|
64
60
|
end
|
65
61
|
|
66
|
-
def
|
62
|
+
def literal? exp
|
67
63
|
exp.sexp_type == :lit
|
68
64
|
end
|
69
65
|
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
module RipperRubyParser
|
3
2
|
module SexpHandlers
|
4
3
|
module Literals
|
@@ -76,10 +75,10 @@ module RipperRubyParser
|
|
76
75
|
else
|
77
76
|
rest << numflags if numflags > 0
|
78
77
|
sexp_type = if flags =~ /o/
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
:dregx_once
|
79
|
+
else
|
80
|
+
:dregx
|
81
|
+
end
|
83
82
|
s(sexp_type, string, *rest)
|
84
83
|
end
|
85
84
|
end
|
@@ -91,7 +90,7 @@ module RipperRubyParser
|
|
91
90
|
|
92
91
|
def process_symbol exp
|
93
92
|
_, node = exp.shift 2
|
94
|
-
with_position_from_node_symbol(node) {|sym| s(:lit, sym) }
|
93
|
+
with_position_from_node_symbol(node) { |sym| s(:lit, sym) }
|
95
94
|
end
|
96
95
|
|
97
96
|
def process_dyna_symbol exp
|
@@ -113,24 +112,35 @@ module RipperRubyParser
|
|
113
112
|
private
|
114
113
|
|
115
114
|
def extract_string_parts exp
|
116
|
-
|
117
|
-
rest = []
|
115
|
+
parts = internal_process_string_parts(exp)
|
118
116
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
while not(rest.empty?) and rest.first.sexp_type == :str
|
125
|
-
str = rest.shift
|
117
|
+
string = ""
|
118
|
+
while !parts.empty? && parts.first.sexp_type == :str
|
119
|
+
str = parts.shift
|
126
120
|
string += str[1]
|
127
121
|
end
|
128
122
|
|
129
|
-
rest =
|
123
|
+
rest = parts.map { |se| se.sexp_type == :dstr ? se.last : se }
|
130
124
|
|
131
125
|
return string, rest
|
132
126
|
end
|
133
127
|
|
128
|
+
def internal_process_string_parts exp
|
129
|
+
rest = []
|
130
|
+
|
131
|
+
until exp.empty?
|
132
|
+
part = exp.shift
|
133
|
+
result = if part.is_a? String
|
134
|
+
# FIXME: Extract escaping into separate method
|
135
|
+
s(:str, part.inspect[1..-2])
|
136
|
+
else
|
137
|
+
process(part)
|
138
|
+
end
|
139
|
+
rest << result
|
140
|
+
end
|
141
|
+
rest
|
142
|
+
end
|
143
|
+
|
134
144
|
def extract_unescaped_string_parts exp
|
135
145
|
string, rest = extract_string_parts exp
|
136
146
|
|
@@ -154,8 +164,8 @@ module RipperRubyParser
|
|
154
164
|
"r" => "\r",
|
155
165
|
"s" => "\s",
|
156
166
|
"t" => "\t",
|
157
|
-
"v" => "\v"
|
158
|
-
}
|
167
|
+
"v" => "\v"
|
168
|
+
}.freeze
|
159
169
|
|
160
170
|
SINGLE_LETTER_ESCAPES_REGEXP =
|
161
171
|
Regexp.new("^[#{SINGLE_LETTER_ESCAPES.keys.join}]$")
|
@@ -174,7 +184,7 @@ module RipperRubyParser
|
|
174
184
|
M-. | # meta
|
175
185
|
. # single-character
|
176
186
|
)/x) do
|
177
|
-
bare =
|
187
|
+
bare = Regexp.last_match[1]
|
178
188
|
case bare
|
179
189
|
when SINGLE_LETTER_ESCAPES_REGEXP
|
180
190
|
SINGLE_LETTER_ESCAPES[bare]
|
@@ -182,12 +192,12 @@ module RipperRubyParser
|
|
182
192
|
bare[1..-1].to_i(16).chr
|
183
193
|
when /^u/
|
184
194
|
bare[1..-1].to_i(16).chr(Encoding::UTF_8)
|
185
|
-
when /^(
|
186
|
-
(
|
187
|
-
when /^M
|
188
|
-
(
|
189
|
-
when /^(
|
190
|
-
(
|
195
|
+
when /^(c|C-).$/
|
196
|
+
(bare[-1].ord & 0b1001_1111).chr
|
197
|
+
when /^M-.$/
|
198
|
+
(bare[-1].ord | 0b1000_0000).chr
|
199
|
+
when /^(M-\\C-|C-\\M-|M-\\c|c\\M-).$/
|
200
|
+
(bare[-1].ord & 0b1001_1111 | 0b1000_0000).chr
|
191
201
|
when /^[0-7]+/
|
192
202
|
bare.to_i(8).chr
|
193
203
|
else
|
@@ -208,7 +218,6 @@ module RipperRubyParser
|
|
208
218
|
|
209
219
|
numflags
|
210
220
|
end
|
211
|
-
|
212
221
|
end
|
213
222
|
end
|
214
223
|
end
|
@@ -2,31 +2,19 @@ module RipperRubyParser
|
|
2
2
|
module SexpHandlers
|
3
3
|
module Loops
|
4
4
|
def process_until exp
|
5
|
-
|
6
|
-
|
7
|
-
s(:until, process(cond), wrap_in_block(map_body(block)), true)
|
5
|
+
handle_conditional_loop(:until, exp)
|
8
6
|
end
|
9
7
|
|
10
8
|
def process_until_mod exp
|
11
|
-
|
12
|
-
|
13
|
-
check_at_start = check_at_start?(block)
|
14
|
-
|
15
|
-
s(:until, process(cond), process(block), check_at_start)
|
9
|
+
handle_conditional_loop_mod(:until, exp)
|
16
10
|
end
|
17
11
|
|
18
12
|
def process_while exp
|
19
|
-
|
20
|
-
|
21
|
-
s(:while, process(cond), wrap_in_block(map_body(block)), true)
|
13
|
+
handle_conditional_loop(:while, exp)
|
22
14
|
end
|
23
15
|
|
24
16
|
def process_while_mod exp
|
25
|
-
|
26
|
-
|
27
|
-
check_at_start = check_at_start?(block)
|
28
|
-
|
29
|
-
s(:while, process(cond), process(block), check_at_start)
|
17
|
+
handle_conditional_loop_mod(:while, exp)
|
30
18
|
end
|
31
19
|
|
32
20
|
def process_for exp
|
@@ -43,10 +31,23 @@ module RipperRubyParser
|
|
43
31
|
|
44
32
|
private
|
45
33
|
|
46
|
-
def check_at_start?
|
34
|
+
def check_at_start? block
|
47
35
|
block.sexp_type != :begin
|
48
36
|
end
|
37
|
+
|
38
|
+
def handle_conditional_loop type, exp
|
39
|
+
_, cond, block = exp.shift 3
|
40
|
+
|
41
|
+
s(type, process(cond), wrap_in_block(map_body(block)), true)
|
42
|
+
end
|
43
|
+
|
44
|
+
def handle_conditional_loop_mod type, exp
|
45
|
+
_, cond, block = exp.shift 3
|
46
|
+
|
47
|
+
check_at_start = check_at_start?(block)
|
48
|
+
|
49
|
+
s(type, process(cond), process(block), check_at_start)
|
50
|
+
end
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
52
|
-
|
@@ -16,38 +16,39 @@ module RipperRubyParser
|
|
16
16
|
|
17
17
|
def process_call exp
|
18
18
|
_, receiver, _, ident = exp.shift 4
|
19
|
-
with_position_from_node_symbol(ident)
|
20
|
-
s(:call, process(receiver), method)
|
19
|
+
with_position_from_node_symbol(ident) do |method|
|
20
|
+
s(:call, process(receiver), method)
|
21
|
+
end
|
21
22
|
end
|
22
23
|
|
23
24
|
def process_command exp
|
24
25
|
_, ident, arglist = exp.shift 3
|
25
|
-
with_position_from_node_symbol(ident)
|
26
|
-
args =
|
27
|
-
args.shift
|
26
|
+
with_position_from_node_symbol(ident) do |method|
|
27
|
+
args = handle_argument_list(arglist)
|
28
28
|
s(:call, nil, method, *args)
|
29
|
-
|
29
|
+
end
|
30
30
|
end
|
31
31
|
|
32
32
|
def process_command_call exp
|
33
33
|
_, receiver, _, ident, arguments = exp.shift 5
|
34
|
-
with_position_from_node_symbol(ident)
|
35
|
-
args =
|
36
|
-
args.shift
|
34
|
+
with_position_from_node_symbol(ident) do |method|
|
35
|
+
args = handle_argument_list(arguments)
|
37
36
|
s(:call, process(receiver), method, *args)
|
38
|
-
|
37
|
+
end
|
39
38
|
end
|
40
39
|
|
41
40
|
def process_vcall exp
|
42
41
|
_, ident = exp.shift 2
|
43
|
-
with_position_from_node_symbol(ident)
|
44
|
-
s(:call, nil, method)
|
42
|
+
with_position_from_node_symbol(ident) do |method|
|
43
|
+
s(:call, nil, method)
|
44
|
+
end
|
45
45
|
end
|
46
46
|
|
47
47
|
def process_fcall exp
|
48
48
|
_, ident = exp.shift 2
|
49
|
-
with_position_from_node_symbol(ident)
|
50
|
-
s(:call, nil, method)
|
49
|
+
with_position_from_node_symbol(ident) do |method|
|
50
|
+
s(:call, nil, method)
|
51
|
+
end
|
51
52
|
end
|
52
53
|
|
53
54
|
def process_super exp
|
@@ -59,4 +60,3 @@ module RipperRubyParser
|
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
62
|
-
|