ruby_parser 2.3.1 → 3.0.0.a1
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.
Potentially problematic release.
This version of ruby_parser might be problematic. Click here for more details.
- data.tar.gz.sig +0 -0
- data/.autotest +1 -1
- data/History.txt +69 -0
- data/Manifest.txt +5 -1
- data/README.txt +5 -5
- data/Rakefile +65 -1
- data/bin/ruby_parse +9 -1
- data/bin/ruby_parse_extract_error +75 -0
- data/lib/ruby18_parser.rb +5737 -0
- data/lib/{ruby_parser.y → ruby18_parser.y} +172 -110
- data/lib/ruby19_parser.rb +6147 -0
- data/lib/ruby19_parser.y +2014 -0
- data/lib/ruby_lexer.rb +130 -37
- data/lib/ruby_parser.rb +3 -5543
- data/lib/ruby_parser_extras.rb +195 -48
- data/test/test_ruby_lexer.rb +94 -15
- data/test/test_ruby_parser.rb +134 -80
- data/test/test_ruby_parser_extras.rb +3 -0
- metadata +51 -27
- metadata.gz.sig +3 -1
data/test/test_ruby_parser.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
ENV['VERBOSE'] = "1"
|
4
4
|
|
5
5
|
require 'rubygems'
|
6
|
+
gem "minitest"
|
6
7
|
require 'minitest/autorun'
|
7
8
|
require 'ruby_parser'
|
8
9
|
|
@@ -10,13 +11,21 @@ $: << File.expand_path('~/Work/p4/zss/src/ParseTree/dev/test')
|
|
10
11
|
|
11
12
|
require 'pt_testcase'
|
12
13
|
|
13
|
-
class
|
14
|
+
class Ruby18Parser # FIX
|
15
|
+
def process input
|
16
|
+
parse input
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Ruby19Parser
|
14
21
|
def process input
|
15
22
|
parse input
|
16
23
|
end
|
17
24
|
end
|
18
25
|
|
19
26
|
class RubyParserTestCase < ParseTreeTestCase
|
27
|
+
attr_accessor :result, :processor
|
28
|
+
|
20
29
|
def self.previous key
|
21
30
|
"Ruby"
|
22
31
|
end
|
@@ -29,16 +38,6 @@ class RubyParserTestCase < ParseTreeTestCase
|
|
29
38
|
|
30
39
|
super
|
31
40
|
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class TestRubyParser < RubyParserTestCase
|
35
|
-
attr_accessor :result, :processor
|
36
|
-
|
37
|
-
def setup
|
38
|
-
super
|
39
|
-
|
40
|
-
self.processor = RubyParser.new
|
41
|
-
end
|
42
41
|
|
43
42
|
def assert_parse rb, pt
|
44
43
|
self.result = processor.parse rb
|
@@ -49,17 +48,18 @@ class TestRubyParser < RubyParserTestCase
|
|
49
48
|
assert_parse rb, pt
|
50
49
|
assert_equal line, result.line, "call should have line number"
|
51
50
|
end
|
51
|
+
end
|
52
52
|
|
53
|
+
module TestRubyParser
|
53
54
|
def test_attrasgn_array_lhs
|
54
55
|
rb = '[1, 2, 3, 4][from .. to] = ["a", "b", "c"]'
|
55
56
|
pt = s(:attrasgn,
|
56
57
|
s(:array, s(:lit, 1), s(:lit, 2), s(:lit, 3), s(:lit, 4)),
|
57
58
|
:[]=,
|
58
|
-
s(:
|
59
|
-
s(:
|
60
|
-
|
61
|
-
|
62
|
-
s(:array, s(:str, "a"), s(:str, "b"), s(:str, "c"))))
|
59
|
+
s(:dot2,
|
60
|
+
s(:call, nil, :from),
|
61
|
+
s(:call, nil, :to)),
|
62
|
+
s(:array, s(:str, "a"), s(:str, "b"), s(:str, "c")))
|
63
63
|
|
64
64
|
assert_parse rb, pt
|
65
65
|
end
|
@@ -100,18 +100,25 @@ class TestRubyParser < RubyParserTestCase
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def test_block_append_tail_block
|
103
|
-
head = s(:call, nil, :f1
|
103
|
+
head = s(:call, nil, :f1)
|
104
104
|
tail = s(:block, s(:undef, s(:lit, :x)), s(:undef, s(:lit, :y)))
|
105
105
|
expected = s(:block,
|
106
|
-
s(:call, nil, :f1
|
106
|
+
s(:call, nil, :f1),
|
107
107
|
s(:block, s(:undef, s(:lit, :x)), s(:undef, s(:lit, :y))))
|
108
108
|
assert_equal expected, processor.block_append(head, tail)
|
109
109
|
end
|
110
110
|
|
111
|
+
def test_call_array_arg
|
112
|
+
rb = "1 == [:b, :c]"
|
113
|
+
pt = s(:call, s(:lit, 1), :==, s(:array, s(:lit, :b), s(:lit, :c)))
|
114
|
+
|
115
|
+
assert_parse rb, pt
|
116
|
+
end
|
117
|
+
|
111
118
|
def test_call_env
|
112
119
|
processor.env[:a] = :lvar
|
113
120
|
rb = "a.happy"
|
114
|
-
pt = s(:call, s(:lvar, :a), :happy
|
121
|
+
pt = s(:call, s(:lvar, :a), :happy)
|
115
122
|
|
116
123
|
assert_parse rb, pt
|
117
124
|
end
|
@@ -119,7 +126,7 @@ class TestRubyParser < RubyParserTestCase
|
|
119
126
|
def test_dasgn_icky2
|
120
127
|
rb = "a do\n v = nil\n begin\n yield\n rescue Exception => v\n break\n end\nend"
|
121
128
|
pt = s(:iter,
|
122
|
-
s(:call, nil, :a
|
129
|
+
s(:call, nil, :a),
|
123
130
|
nil,
|
124
131
|
s(:block,
|
125
132
|
s(:lasgn, :v, s(:nil)),
|
@@ -135,29 +142,27 @@ class TestRubyParser < RubyParserTestCase
|
|
135
142
|
def test_class_comments
|
136
143
|
rb = "# blah 1\n# blah 2\n\nclass X\n # blah 3\n def blah\n # blah 4\n end\nend"
|
137
144
|
pt = s(:class, :X, nil,
|
138
|
-
s(:
|
139
|
-
s(:defn, :blah, s(:args), s(:scope, s(:block, s(:nil))))))
|
145
|
+
s(:defn, :blah, s(:args), s(:nil)))
|
140
146
|
|
141
147
|
assert_parse rb, pt
|
142
148
|
|
143
149
|
assert_equal "# blah 1\n# blah 2\n\n", result.comments
|
144
|
-
assert_equal "# blah 3\n", result.
|
150
|
+
assert_equal "# blah 3\n", result.defn.comments
|
145
151
|
end
|
146
152
|
|
147
153
|
def test_module_comments
|
148
154
|
rb = "# blah 1\n \n # blah 2\n\nmodule X\n # blah 3\n def blah\n # blah 4\n end\nend"
|
149
155
|
pt = s(:module, :X,
|
150
|
-
s(:
|
151
|
-
s(:defn, :blah, s(:args), s(:scope, s(:block, s(:nil))))))
|
156
|
+
s(:defn, :blah, s(:args), s(:nil)))
|
152
157
|
|
153
158
|
assert_parse rb, pt
|
154
159
|
assert_equal "# blah 1\n\n# blah 2\n\n", result.comments
|
155
|
-
assert_equal "# blah 3\n", result.
|
160
|
+
assert_equal "# blah 3\n", result.defn.comments
|
156
161
|
end
|
157
162
|
|
158
163
|
def test_defn_comments
|
159
164
|
rb = "# blah 1\n# blah 2\n\ndef blah\nend"
|
160
|
-
pt = s(:defn, :blah, s(:args), s(:
|
165
|
+
pt = s(:defn, :blah, s(:args), s(:nil))
|
161
166
|
|
162
167
|
assert_parse rb, pt
|
163
168
|
assert_equal "# blah 1\n# blah 2\n\n", result.comments
|
@@ -165,7 +170,7 @@ class TestRubyParser < RubyParserTestCase
|
|
165
170
|
|
166
171
|
def test_defs_comments
|
167
172
|
rb = "# blah 1\n# blah 2\n\ndef self.blah\nend"
|
168
|
-
pt = s(:defs, s(:self), :blah, s(:args)
|
173
|
+
pt = s(:defs, s(:self), :blah, s(:args))
|
169
174
|
|
170
175
|
assert_parse rb, pt
|
171
176
|
assert_equal "# blah 1\n# blah 2\n\n", result.comments
|
@@ -174,9 +179,9 @@ class TestRubyParser < RubyParserTestCase
|
|
174
179
|
def test_do_bug # TODO: rename
|
175
180
|
rb = "a 1\na.b do |c|\n # do nothing\nend"
|
176
181
|
pt = s(:block,
|
177
|
-
s(:call, nil, :a, s(:
|
182
|
+
s(:call, nil, :a, s(:lit, 1)),
|
178
183
|
s(:iter,
|
179
|
-
s(:call, s(:call, nil, :a
|
184
|
+
s(:call, s(:call, nil, :a), :b),
|
180
185
|
s(:lasgn, :c)))
|
181
186
|
|
182
187
|
assert_parse rb, pt
|
@@ -193,7 +198,7 @@ class TestRubyParser < RubyParserTestCase
|
|
193
198
|
|
194
199
|
def test_bug_call_arglist_parens
|
195
200
|
rb = 'g ( 1), 2'
|
196
|
-
pt = s(:call, nil, :g, s(:
|
201
|
+
pt = s(:call, nil, :g, s(:lit, 1), s(:lit, 2))
|
197
202
|
|
198
203
|
assert_parse rb, pt
|
199
204
|
|
@@ -204,11 +209,7 @@ class TestRubyParser < RubyParserTestCase
|
|
204
209
|
CODE
|
205
210
|
|
206
211
|
pt = s(:defn, :f, s(:args),
|
207
|
-
s(:
|
208
|
-
s(:block,
|
209
|
-
s(:call, nil, :g,
|
210
|
-
s(:arglist,
|
211
|
-
s(:lit, 1), s(:lit, 2))))))
|
212
|
+
s(:call, nil, :g, s(:lit, 1), s(:lit, 2)))
|
212
213
|
|
213
214
|
assert_parse rb, pt
|
214
215
|
|
@@ -223,7 +224,7 @@ class TestRubyParser < RubyParserTestCase
|
|
223
224
|
|
224
225
|
def test_dstr_evstr
|
225
226
|
rb = "\"#\{'a'}#\{b}\""
|
226
|
-
pt = s(:dstr, "a", s(:evstr, s(:call, nil, :b
|
227
|
+
pt = s(:dstr, "a", s(:evstr, s(:call, nil, :b)))
|
227
228
|
|
228
229
|
assert_parse rb, pt
|
229
230
|
end
|
@@ -244,14 +245,14 @@ class TestRubyParser < RubyParserTestCase
|
|
244
245
|
|
245
246
|
def test_evstr_evstr
|
246
247
|
rb = "\"#\{a}#\{b}\""
|
247
|
-
pt = s(:dstr, "", s(:evstr, s(:call, nil, :a
|
248
|
+
pt = s(:dstr, "", s(:evstr, s(:call, nil, :a)), s(:evstr, s(:call, nil, :b)))
|
248
249
|
|
249
250
|
assert_parse rb, pt
|
250
251
|
end
|
251
252
|
|
252
253
|
def test_evstr_str
|
253
254
|
rb = "\"#\{a} b\""
|
254
|
-
pt = s(:dstr, "", s(:evstr, s(:call, nil, :a
|
255
|
+
pt = s(:dstr, "", s(:evstr, s(:call, nil, :a)), s(:str, " b"))
|
255
256
|
|
256
257
|
assert_parse rb, pt
|
257
258
|
end
|
@@ -308,16 +309,16 @@ class TestRubyParser < RubyParserTestCase
|
|
308
309
|
|
309
310
|
def test_literal_concat_dstr_dstr
|
310
311
|
lhs = s(:dstr, "Failed to download spec ",
|
311
|
-
s(:evstr, s(:call, nil, :spec_name
|
312
|
+
s(:evstr, s(:call, nil, :spec_name)),
|
312
313
|
s(:str, " from "),
|
313
|
-
s(:evstr, s(:call, nil, :source_uri
|
314
|
+
s(:evstr, s(:call, nil, :source_uri)),
|
314
315
|
s(:str, ":\n"))
|
315
316
|
rhs = s(:dstr, "\t",
|
316
317
|
s(:evstr, s(:call, s(:ivar, :@fetch_error), :message)))
|
317
318
|
expected = s(:dstr, "Failed to download spec ",
|
318
|
-
s(:evstr, s(:call, nil, :spec_name
|
319
|
+
s(:evstr, s(:call, nil, :spec_name)),
|
319
320
|
s(:str, " from "),
|
320
|
-
s(:evstr, s(:call, nil, :source_uri
|
321
|
+
s(:evstr, s(:call, nil, :source_uri)),
|
321
322
|
s(:str, ":\n"),
|
322
323
|
s(:str, "\t"),
|
323
324
|
s(:evstr, s(:call, s(:ivar, :@fetch_error), :message)))
|
@@ -326,8 +327,8 @@ class TestRubyParser < RubyParserTestCase
|
|
326
327
|
end
|
327
328
|
|
328
329
|
def test_literal_concat_dstr_evstr
|
329
|
-
lhs, rhs = s(:dstr, "a"), s(:evstr, s(:call, nil, :b
|
330
|
-
expected = s(:dstr, "a", s(:evstr, s(:call, nil, :b
|
330
|
+
lhs, rhs = s(:dstr, "a"), s(:evstr, s(:call, nil, :b))
|
331
|
+
expected = s(:dstr, "a", s(:evstr, s(:call, nil, :b)))
|
331
332
|
|
332
333
|
assert_equal expected, processor.literal_concat(lhs, rhs)
|
333
334
|
end
|
@@ -392,11 +393,11 @@ class TestRubyParser < RubyParserTestCase
|
|
392
393
|
end
|
393
394
|
|
394
395
|
def test_logop_nested_mix
|
395
|
-
lhs = s(:or, s(:call, nil, :a
|
396
|
-
rhs = s(:and, s(:call, nil, :c
|
396
|
+
lhs = s(:or, s(:call, nil, :a), s(:call, nil, :b))
|
397
|
+
rhs = s(:and, s(:call, nil, :c), s(:call, nil, :d))
|
397
398
|
exp = s(:or,
|
398
|
-
s(:or, s(:call, nil, :a
|
399
|
-
s(:and, s(:call, nil, :c
|
399
|
+
s(:or, s(:call, nil, :a), s(:call, nil, :b)),
|
400
|
+
s(:and, s(:call, nil, :c), s(:call, nil, :d)))
|
400
401
|
|
401
402
|
lhs.paren = true
|
402
403
|
rhs.paren = true
|
@@ -406,7 +407,7 @@ class TestRubyParser < RubyParserTestCase
|
|
406
407
|
|
407
408
|
def test_str_evstr
|
408
409
|
rb = "\"a #\{b}\""
|
409
|
-
pt = s(:dstr, "a ", s(:evstr, s(:call, nil, :b
|
410
|
+
pt = s(:dstr, "a ", s(:evstr, s(:call, nil, :b)))
|
410
411
|
|
411
412
|
assert_parse rb, pt
|
412
413
|
end
|
@@ -439,7 +440,7 @@ class TestRubyParser < RubyParserTestCase
|
|
439
440
|
|
440
441
|
def test_str_pct_Q_nested
|
441
442
|
rb = "%Q[before [#\{nest}] after]"
|
442
|
-
pt = s(:dstr, "before [", s(:evstr, s(:call, nil, :nest
|
443
|
+
pt = s(:dstr, "before [", s(:evstr, s(:call, nil, :nest)), s(:str, "] after"))
|
443
444
|
|
444
445
|
assert_parse rb, pt
|
445
446
|
end
|
@@ -493,7 +494,7 @@ class TestRubyParser < RubyParserTestCase
|
|
493
494
|
rb = "a = 42\np a"
|
494
495
|
pt = s(:block,
|
495
496
|
s(:lasgn, :a, s(:lit, 42)),
|
496
|
-
s(:call, nil, :p, s(:
|
497
|
+
s(:call, nil, :p, s(:lvar, :a)))
|
497
498
|
|
498
499
|
assert_parse_line rb, pt, 1
|
499
500
|
assert_equal 1, result.lasgn.line, "lasgn should have line number"
|
@@ -512,9 +513,9 @@ class TestRubyParser < RubyParserTestCase
|
|
512
513
|
rb = "f do |x, y|\n x + y\nend"
|
513
514
|
|
514
515
|
pt = s(:iter,
|
515
|
-
s(:call, nil, :f
|
516
|
+
s(:call, nil, :f),
|
516
517
|
s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))),
|
517
|
-
s(:call, s(:lvar, :x), :+, s(:
|
518
|
+
s(:call, s(:lvar, :x), :+, s(:lvar, :y)))
|
518
519
|
|
519
520
|
assert_parse_line rb, pt, 1
|
520
521
|
assert_equal 1, result[1].line, "call should have line number"
|
@@ -523,7 +524,7 @@ class TestRubyParser < RubyParserTestCase
|
|
523
524
|
end
|
524
525
|
|
525
526
|
def test_parse_line_defn_no_parens
|
526
|
-
pt = s(:defn, :f, s(:args), s(:
|
527
|
+
pt = s(:defn, :f, s(:args), s(:nil))
|
527
528
|
|
528
529
|
rb = "def f\nend"
|
529
530
|
assert_parse_line rb, pt, 1
|
@@ -535,16 +536,13 @@ class TestRubyParser < RubyParserTestCase
|
|
535
536
|
def test_parse_line_defn_complex
|
536
537
|
rb = "def x(y)\n p(y)\n y *= 2\n return y;\nend" # TODO: remove () & ;
|
537
538
|
pt = s(:defn, :x, s(:args, :y),
|
538
|
-
s(:
|
539
|
-
|
540
|
-
|
541
|
-
s(:lasgn, :y,
|
542
|
-
s(:call, s(:lvar, :y), :*, s(:arglist, s(:lit, 2)))),
|
543
|
-
s(:return, s(:lvar, :y)))))
|
539
|
+
s(:call, nil, :p, s(:lvar, :y)),
|
540
|
+
s(:lasgn, :y, s(:call, s(:lvar, :y), :*, s(:lit, 2))),
|
541
|
+
s(:return, s(:lvar, :y)))
|
544
542
|
|
545
543
|
assert_parse_line rb, pt, 1
|
546
544
|
|
547
|
-
body = result
|
545
|
+
body = result
|
548
546
|
assert_equal 2, body.call.line, "call should have line number"
|
549
547
|
assert_equal 3, body.lasgn.line, "lasgn should have line number"
|
550
548
|
assert_equal 4, body.return.line, "return should have line number"
|
@@ -554,9 +552,9 @@ class TestRubyParser < RubyParserTestCase
|
|
554
552
|
rb = "f(a) do |x, y|\n x + y\nend"
|
555
553
|
|
556
554
|
pt = s(:iter,
|
557
|
-
s(:call, nil, :f, s(:
|
555
|
+
s(:call, nil, :f, s(:call, nil, :a)),
|
558
556
|
s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))),
|
559
|
-
s(:call, s(:lvar, :x), :+, s(:
|
557
|
+
s(:call, s(:lvar, :x), :+, s(:lvar, :y)))
|
560
558
|
|
561
559
|
assert_parse_line rb, pt, 1
|
562
560
|
|
@@ -569,9 +567,9 @@ class TestRubyParser < RubyParserTestCase
|
|
569
567
|
rb = "f a do |x, y|\n x + y\nend"
|
570
568
|
|
571
569
|
pt = s(:iter,
|
572
|
-
s(:call, nil, :f, s(:
|
570
|
+
s(:call, nil, :f, s(:call, nil, :a)),
|
573
571
|
s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))),
|
574
|
-
s(:call, s(:lvar, :x), :+, s(:
|
572
|
+
s(:call, s(:lvar, :x), :+, s(:lvar, :y)))
|
575
573
|
|
576
574
|
assert_parse_line rb, pt, 1
|
577
575
|
|
@@ -610,23 +608,20 @@ class TestRubyParser < RubyParserTestCase
|
|
610
608
|
RUBY
|
611
609
|
|
612
610
|
pt = s(:defn, :blah, s(:args),
|
613
|
-
s(:
|
614
|
-
s(:
|
615
|
-
|
616
|
-
s(:true),
|
617
|
-
s(:return, s(:lit, 42)),
|
618
|
-
nil))))
|
611
|
+
s(:if, s(:true),
|
612
|
+
s(:return, s(:lit, 42)),
|
613
|
+
nil))
|
619
614
|
|
620
615
|
assert_parse_line rb, pt, 1
|
621
616
|
|
622
|
-
assert_equal 3, result.
|
623
|
-
assert_equal 3, result.
|
617
|
+
assert_equal 3, result.if.return.line
|
618
|
+
assert_equal 3, result.if.return.lit.line
|
624
619
|
end
|
625
620
|
|
626
621
|
def test_parse_if_not_canonical
|
627
622
|
rb = "if not var.nil? then 'foo' else 'bar'\nend"
|
628
623
|
pt = s(:if,
|
629
|
-
s(:call, s(:call, nil, :var
|
624
|
+
s(:call, s(:call, nil, :var), :nil?),
|
630
625
|
s(:str, "bar"),
|
631
626
|
s(:str, "foo"))
|
632
627
|
|
@@ -637,7 +632,7 @@ class TestRubyParser < RubyParserTestCase
|
|
637
632
|
rb = "if not var.nil? then 'foo' else 'bar'\nend"
|
638
633
|
pt = s(:if,
|
639
634
|
s(:not,
|
640
|
-
s(:call, s(:call, nil, :var
|
635
|
+
s(:call, s(:call, nil, :var), :nil?)),
|
641
636
|
s(:str, "foo"),
|
642
637
|
s(:str, "bar"))
|
643
638
|
|
@@ -649,7 +644,7 @@ class TestRubyParser < RubyParserTestCase
|
|
649
644
|
def test_parse_while_not_canonical
|
650
645
|
rb = "while not var.nil?\n 'foo'\nend"
|
651
646
|
pt = s(:until,
|
652
|
-
s(:call, s(:call, nil, :var
|
647
|
+
s(:call, s(:call, nil, :var), :nil?),
|
653
648
|
s(:str, "foo"), true)
|
654
649
|
|
655
650
|
assert_parse rb, pt
|
@@ -659,7 +654,7 @@ class TestRubyParser < RubyParserTestCase
|
|
659
654
|
rb = "while not var.nil?\n 'foo'\nend"
|
660
655
|
pt = s(:while,
|
661
656
|
s(:not,
|
662
|
-
s(:call, s(:call, nil, :var
|
657
|
+
s(:call, s(:call, nil, :var), :nil?)),
|
663
658
|
s(:str, "foo"), true)
|
664
659
|
|
665
660
|
processor.canonicalize_conditions = false
|
@@ -671,7 +666,7 @@ class TestRubyParser < RubyParserTestCase
|
|
671
666
|
rb = "until not var.nil?\n 'foo'\nend"
|
672
667
|
|
673
668
|
pt = s(:while,
|
674
|
-
s(:call, s(:call, nil, :var
|
669
|
+
s(:call, s(:call, nil, :var), :nil?),
|
675
670
|
s(:str, "foo"), true)
|
676
671
|
|
677
672
|
assert_parse rb, pt
|
@@ -681,7 +676,7 @@ class TestRubyParser < RubyParserTestCase
|
|
681
676
|
rb = "until not var.nil?\n 'foo'\nend"
|
682
677
|
pt = s(:until,
|
683
678
|
s(:not,
|
684
|
-
s(:call, s(:call, nil, :var
|
679
|
+
s(:call, s(:call, nil, :var), :nil?)),
|
685
680
|
s(:str, "foo"), true)
|
686
681
|
|
687
682
|
processor.canonicalize_conditions = false
|
@@ -689,3 +684,62 @@ class TestRubyParser < RubyParserTestCase
|
|
689
684
|
assert_parse rb, pt
|
690
685
|
end
|
691
686
|
end
|
687
|
+
|
688
|
+
class TestRuby18Parser < RubyParserTestCase
|
689
|
+
include TestRubyParser
|
690
|
+
|
691
|
+
def setup
|
692
|
+
super
|
693
|
+
|
694
|
+
self.processor = Ruby18Parser.new
|
695
|
+
end
|
696
|
+
|
697
|
+
def test_flip2_env_lvar
|
698
|
+
rb = "if a..b then end"
|
699
|
+
pt = s(:if, s(:flip2, s(:call, nil, :a), s(:call, nil, :b)), nil, nil)
|
700
|
+
|
701
|
+
assert_parse rb, pt
|
702
|
+
|
703
|
+
top_env = processor.env.env.first
|
704
|
+
|
705
|
+
assert_kind_of Hash, top_env
|
706
|
+
|
707
|
+
flip = top_env.find { |k,v| k =~ /^flip/ }
|
708
|
+
|
709
|
+
assert flip
|
710
|
+
assert_equal :lvar, flip.last
|
711
|
+
end
|
712
|
+
end
|
713
|
+
|
714
|
+
class TestRuby19Parser < RubyParserTestCase
|
715
|
+
include TestRubyParser
|
716
|
+
|
717
|
+
def setup
|
718
|
+
super
|
719
|
+
|
720
|
+
self.processor = Ruby19Parser.new
|
721
|
+
end
|
722
|
+
|
723
|
+
# HACK: need to figure out the desired structure and get this working
|
724
|
+
# def test_wtf
|
725
|
+
# # lambda -> f_larglist lambda_body
|
726
|
+
# # f_larglist -> f_args opt_bv_decl
|
727
|
+
# # opt_bv_decl
|
728
|
+
# # bv_decls
|
729
|
+
# # bvar
|
730
|
+
#
|
731
|
+
# rb = "->(a, b=nil) { p [a, b] }"
|
732
|
+
# pt = s(:iter,
|
733
|
+
# s(:call, nil, :lambda),
|
734
|
+
# s(:args, :a, :b,
|
735
|
+
# s(:block, s(:lasgn, :b, s(nil)))),
|
736
|
+
# s(:call, nil, :p, s(:array, s(:lvar, :a), s(:lvar, :b))))
|
737
|
+
#
|
738
|
+
# assert_parse rb, pt
|
739
|
+
#
|
740
|
+
# rb = "->(a; b) { p [a, b] }"
|
741
|
+
#
|
742
|
+
# assert_parse rb, pt
|
743
|
+
# end
|
744
|
+
end
|
745
|
+
|