melbourne 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/HISTORY +3 -0
  2. data/LICENSE +27 -0
  3. data/README.rdoc +38 -0
  4. data/Rakefile +38 -0
  5. data/VERSION.yml +4 -0
  6. data/ext/melbourne/bstring-license.txt +29 -0
  7. data/ext/melbourne/bstrlib.c +2918 -0
  8. data/ext/melbourne/bstrlib.h +302 -0
  9. data/ext/melbourne/extconf.rb +76 -0
  10. data/ext/melbourne/grammar.cpp +11885 -0
  11. data/ext/melbourne/grammar.hpp +14 -0
  12. data/ext/melbourne/grammar.y +6013 -0
  13. data/ext/melbourne/internal.hpp +137 -0
  14. data/ext/melbourne/lex.c.tab +136 -0
  15. data/ext/melbourne/local_state.hpp +41 -0
  16. data/ext/melbourne/melbourne.cpp +37 -0
  17. data/ext/melbourne/node.hpp +262 -0
  18. data/ext/melbourne/node_types.cpp +245 -0
  19. data/ext/melbourne/node_types.hpp +135 -0
  20. data/ext/melbourne/node_types.rb +190 -0
  21. data/ext/melbourne/quark.cpp +52 -0
  22. data/ext/melbourne/quark.hpp +14 -0
  23. data/ext/melbourne/symbols.cpp +219 -0
  24. data/ext/melbourne/symbols.hpp +116 -0
  25. data/ext/melbourne/var_table.cpp +113 -0
  26. data/ext/melbourne/var_table.hpp +33 -0
  27. data/ext/melbourne/visitor.cpp +1052 -0
  28. data/ext/melbourne/visitor.hpp +20 -0
  29. data/lib/melbourne/ast/constants.rb +128 -0
  30. data/lib/melbourne/ast/control_flow.rb +382 -0
  31. data/lib/melbourne/ast/data.rb +19 -0
  32. data/lib/melbourne/ast/definitions.rb +561 -0
  33. data/lib/melbourne/ast/exceptions.rb +182 -0
  34. data/lib/melbourne/ast/file.rb +15 -0
  35. data/lib/melbourne/ast/grapher.rb +75 -0
  36. data/lib/melbourne/ast/literals.rb +268 -0
  37. data/lib/melbourne/ast/node.rb +21 -0
  38. data/lib/melbourne/ast/operators.rb +117 -0
  39. data/lib/melbourne/ast/self.rb +17 -0
  40. data/lib/melbourne/ast/sends.rb +451 -0
  41. data/lib/melbourne/ast/values.rb +74 -0
  42. data/lib/melbourne/ast/variables.rb +251 -0
  43. data/lib/melbourne/ast.rb +22 -0
  44. data/lib/melbourne/parser.rb +38 -0
  45. data/lib/melbourne/processor.rb +460 -0
  46. data/lib/melbourne.rb +46 -0
  47. data/spec/helpers/ast/node.rb +15 -0
  48. data/spec/helpers/ast/reduced_graph.rb +64 -0
  49. data/spec/lib/parser/alias_spec.rb +97 -0
  50. data/spec/lib/parser/and_spec.rb +63 -0
  51. data/spec/lib/parser/array_spec.rb +157 -0
  52. data/spec/lib/parser/attrasgn_spec.rb +401 -0
  53. data/spec/lib/parser/back_ref_spec.rb +20 -0
  54. data/spec/lib/parser/call_spec.rb +958 -0
  55. data/spec/lib/parser/case_spec.rb +577 -0
  56. data/spec/lib/parser/cdecl_spec.rb +108 -0
  57. data/spec/lib/parser/class_spec.rb +221 -0
  58. data/spec/lib/parser/colon2_spec.rb +13 -0
  59. data/spec/lib/parser/colon3_spec.rb +12 -0
  60. data/spec/lib/parser/const_spec.rb +12 -0
  61. data/spec/lib/parser/cvar_spec.rb +55 -0
  62. data/spec/lib/parser/cvasgn_spec.rb +71 -0
  63. data/spec/lib/parser/cvdecl_spec.rb +31 -0
  64. data/spec/lib/parser/defined_spec.rb +353 -0
  65. data/spec/lib/parser/defn_spec.rb +1409 -0
  66. data/spec/lib/parser/defs_spec.rb +247 -0
  67. data/spec/lib/parser/dot2_spec.rb +29 -0
  68. data/spec/lib/parser/dot3_spec.rb +29 -0
  69. data/spec/lib/parser/dregx_spec.rb +127 -0
  70. data/spec/lib/parser/dstr_spec.rb +453 -0
  71. data/spec/lib/parser/dsym_spec.rb +31 -0
  72. data/spec/lib/parser/dxstr_spec.rb +31 -0
  73. data/spec/lib/parser/ensure_spec.rb +279 -0
  74. data/spec/lib/parser/false_spec.rb +12 -0
  75. data/spec/lib/parser/flip2_spec.rb +138 -0
  76. data/spec/lib/parser/flip3_spec.rb +100 -0
  77. data/spec/lib/parser/for_spec.rb +279 -0
  78. data/spec/lib/parser/gasgn_spec.rb +34 -0
  79. data/spec/lib/parser/gvar_spec.rb +33 -0
  80. data/spec/lib/parser/hash_spec.rb +77 -0
  81. data/spec/lib/parser/iasgn_spec.rb +54 -0
  82. data/spec/lib/parser/if_spec.rb +439 -0
  83. data/spec/lib/parser/iter_spec.rb +2582 -0
  84. data/spec/lib/parser/lasgn_spec.rb +1066 -0
  85. data/spec/lib/parser/lit_spec.rb +75 -0
  86. data/spec/lib/parser/masgn_spec.rb +1970 -0
  87. data/spec/lib/parser/match2_spec.rb +47 -0
  88. data/spec/lib/parser/match3_spec.rb +54 -0
  89. data/spec/lib/parser/match_spec.rb +19 -0
  90. data/spec/lib/parser/module_spec.rb +102 -0
  91. data/spec/lib/parser/nil_spec.rb +13 -0
  92. data/spec/lib/parser/not_spec.rb +39 -0
  93. data/spec/lib/parser/nth_ref_spec.rb +12 -0
  94. data/spec/lib/parser/op_asgn_spec.rb +619 -0
  95. data/spec/lib/parser/or_spec.rb +155 -0
  96. data/spec/lib/parser/postexe_spec.rb +31 -0
  97. data/spec/lib/parser/regex_spec.rb +52 -0
  98. data/spec/lib/parser/rescue_spec.rb +1028 -0
  99. data/spec/lib/parser/return_spec.rb +151 -0
  100. data/spec/lib/parser/sclass_spec.rb +172 -0
  101. data/spec/lib/parser/str_spec.rb +162 -0
  102. data/spec/lib/parser/super_spec.rb +276 -0
  103. data/spec/lib/parser/true_spec.rb +12 -0
  104. data/spec/lib/parser/undef_spec.rb +222 -0
  105. data/spec/lib/parser/until_spec.rb +286 -0
  106. data/spec/lib/parser/valias_spec.rb +12 -0
  107. data/spec/lib/parser/while_spec.rb +458 -0
  108. data/spec/lib/parser/xstr_spec.rb +12 -0
  109. data/spec/lib/parser/yield_spec.rb +202 -0
  110. data/spec/lib/parser/zsuper_spec.rb +101 -0
  111. data/spec/matchers/parse_as.rb +27 -0
  112. data/spec/spec_helper.rb +10 -0
  113. metadata +168 -0
@@ -0,0 +1,1028 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Melbourne::Parser do
4
+
5
+ it 'should correctly parse "blah rescue nil"' do
6
+ ruby = 'blah rescue nil'
7
+ ast = {:rescue=>
8
+ {:@body=>
9
+ {:send=>
10
+ {:@block=>nil,
11
+ :@name=>:blah,
12
+ :@line=>1,
13
+ :@privately=>true,
14
+ :@receiver=>{:self=>{:@line=>1}},
15
+ :@check_for_local=>false}},
16
+ :@rescue=>
17
+ {:rescuecondition=>
18
+ {:@conditions=>
19
+ {:arrayliteral=>
20
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>1}}],
21
+ :@line=>1}},
22
+ :@body=>{},
23
+ :@splat=>nil,
24
+ :@next=>nil,
25
+ :@line=>1,
26
+ :@assignment=>nil}},
27
+ :@else=>nil,
28
+ :@line=>1}}
29
+
30
+ ruby.should parse_as(ast)
31
+ end
32
+
33
+ it 'should correctly parse "begin ... blah ... rescue ..."' do
34
+ ruby = <<-ruby
35
+ begin
36
+ blah
37
+ rescue
38
+ end
39
+ ruby
40
+ ast = {:begin=>
41
+ {:@rescue=>
42
+ {:rescue=>
43
+ {:@body=>
44
+ {:send=>
45
+ {:@block=>nil,
46
+ :@name=>:blah,
47
+ :@line=>2,
48
+ :@privately=>true,
49
+ :@receiver=>{:self=>{:@line=>2}},
50
+ :@check_for_local=>false}},
51
+ :@rescue=>
52
+ {:rescuecondition=>
53
+ {:@conditions=>
54
+ {:arrayliteral=>
55
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>4}}],
56
+ :@line=>4}},
57
+ :@body=>{},
58
+ :@splat=>nil,
59
+ :@next=>nil,
60
+ :@line=>4,
61
+ :@assignment=>nil}},
62
+ :@else=>nil,
63
+ :@line=>2}},
64
+ :@line=>1}}
65
+
66
+ ruby.should parse_as(ast)
67
+ end
68
+
69
+ it 'should correctly parse "begin ... rescue A ... rescue B ..."' do
70
+ ruby = <<-ruby
71
+ begin
72
+ a
73
+ rescue A
74
+ b
75
+ rescue B
76
+ c
77
+ rescue C
78
+ d
79
+ end
80
+ ruby
81
+ ast = {:begin=>
82
+ {:@rescue=>
83
+ {:rescue=>
84
+ {:@body=>
85
+ {:send=>
86
+ {:@block=>nil,
87
+ :@name=>:a,
88
+ :@line=>2,
89
+ :@privately=>true,
90
+ :@receiver=>{:self=>{:@line=>2}},
91
+ :@check_for_local=>false}},
92
+ :@rescue=>
93
+ {:rescuecondition=>
94
+ {:@conditions=>
95
+ {:arrayliteral=>
96
+ {:@body=>[{:constfind=>{:@name=>:A, :@line=>3}}], :@line=>3}},
97
+ :@body=>
98
+ {:send=>
99
+ {:@block=>nil,
100
+ :@name=>:b,
101
+ :@line=>4,
102
+ :@privately=>true,
103
+ :@receiver=>{:self=>{:@line=>4}},
104
+ :@check_for_local=>false}},
105
+ :@splat=>nil,
106
+ :@next=>
107
+ {:rescuecondition=>
108
+ {:@conditions=>
109
+ {:arrayliteral=>
110
+ {:@body=>[{:constfind=>{:@name=>:B, :@line=>5}}],
111
+ :@line=>5}},
112
+ :@body=>
113
+ {:send=>
114
+ {:@block=>nil,
115
+ :@name=>:c,
116
+ :@line=>6,
117
+ :@privately=>true,
118
+ :@receiver=>{:self=>{:@line=>6}},
119
+ :@check_for_local=>false}},
120
+ :@splat=>nil,
121
+ :@next=>
122
+ {:rescuecondition=>
123
+ {:@conditions=>
124
+ {:arrayliteral=>
125
+ {:@body=>[{:constfind=>{:@name=>:C, :@line=>7}}],
126
+ :@line=>7}},
127
+ :@body=>
128
+ {:send=>
129
+ {:@block=>nil,
130
+ :@name=>:d,
131
+ :@line=>8,
132
+ :@privately=>true,
133
+ :@receiver=>{:self=>{:@line=>8}},
134
+ :@check_for_local=>false}},
135
+ :@splat=>nil,
136
+ :@next=>nil,
137
+ :@line=>7,
138
+ :@assignment=>nil}},
139
+ :@line=>5,
140
+ :@assignment=>nil}},
141
+ :@line=>3,
142
+ :@assignment=>nil}},
143
+ :@else=>nil,
144
+ :@line=>2}},
145
+ :@line=>1}}
146
+
147
+ ruby.should parse_as(ast)
148
+ end
149
+
150
+ it 'should correctly parse "begin ... rescue => @e ..."' do
151
+ ruby = <<-ruby
152
+ begin
153
+ a
154
+ rescue => @e
155
+ c
156
+ d
157
+ end
158
+ ruby
159
+ ast = {:begin=>
160
+ {:@rescue=>
161
+ {:rescue=>
162
+ {:@body=>
163
+ {:send=>
164
+ {:@block=>nil,
165
+ :@name=>:a,
166
+ :@line=>2,
167
+ :@privately=>true,
168
+ :@receiver=>{:self=>{:@line=>2}},
169
+ :@check_for_local=>false}},
170
+ :@rescue=>
171
+ {:rescuecondition=>
172
+ {:@conditions=>
173
+ {:arrayliteral=>
174
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>3}}],
175
+ :@line=>3}},
176
+ :@body=>
177
+ {:block=>
178
+ {:@array=>
179
+ [{:send=>
180
+ {:@block=>nil,
181
+ :@name=>:c,
182
+ :@line=>4,
183
+ :@privately=>true,
184
+ :@receiver=>{:self=>{:@line=>4}},
185
+ :@check_for_local=>false}},
186
+ {:send=>
187
+ {:@block=>nil,
188
+ :@name=>:d,
189
+ :@line=>5,
190
+ :@privately=>true,
191
+ :@receiver=>{:self=>{:@line=>5}},
192
+ :@check_for_local=>false}}],
193
+ :@line=>3}},
194
+ :@splat=>nil,
195
+ :@next=>nil,
196
+ :@line=>3,
197
+ :@assignment=>
198
+ {:instancevariableassignment=>
199
+ {:@name=>:@e,
200
+ :@line=>3,
201
+ :@value=>{:globalvariableaccess=>{:@name=>:$!, :@line=>6}}}}}},
202
+ :@else=>nil,
203
+ :@line=>2}},
204
+ :@line=>1}}
205
+
206
+ ruby.should parse_as(ast)
207
+ end
208
+
209
+ it 'should correctly parse "begin ... rescue => e ..."' do
210
+ ruby = <<-ruby
211
+ begin
212
+ a
213
+ rescue => e
214
+ c
215
+ d
216
+ end
217
+ ruby
218
+ ast = {:begin=>
219
+ {:@rescue=>
220
+ {:rescue=>
221
+ {:@body=>
222
+ {:send=>
223
+ {:@block=>nil,
224
+ :@name=>:a,
225
+ :@line=>2,
226
+ :@privately=>true,
227
+ :@receiver=>{:self=>{:@line=>2}},
228
+ :@check_for_local=>false}},
229
+ :@rescue=>
230
+ {:rescuecondition=>
231
+ {:@conditions=>
232
+ {:arrayliteral=>
233
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>3}}],
234
+ :@line=>3}},
235
+ :@body=>
236
+ {:block=>
237
+ {:@array=>
238
+ [{:send=>
239
+ {:@block=>nil,
240
+ :@name=>:c,
241
+ :@line=>4,
242
+ :@privately=>true,
243
+ :@receiver=>{:self=>{:@line=>4}},
244
+ :@check_for_local=>false}},
245
+ {:send=>
246
+ {:@block=>nil,
247
+ :@name=>:d,
248
+ :@line=>5,
249
+ :@privately=>true,
250
+ :@receiver=>{:self=>{:@line=>5}},
251
+ :@check_for_local=>false}}],
252
+ :@line=>3}},
253
+ :@splat=>nil,
254
+ :@next=>nil,
255
+ :@line=>3,
256
+ :@assignment=>
257
+ {:localvariableassignment=>
258
+ {:@variable=>nil,
259
+ :@name=>:e,
260
+ :@line=>3,
261
+ :@value=>{:globalvariableaccess=>{:@name=>:$!, :@line=>6}}}}}},
262
+ :@else=>nil,
263
+ :@line=>2}},
264
+ :@line=>1}}
265
+
266
+ ruby.should parse_as(ast)
267
+ end
268
+
269
+ it 'should correctly parse "begin ... rescue => mes ... begin ... rescue => mes ..."' do
270
+ ruby = <<-ruby
271
+ begin
272
+ a
273
+ rescue => mes
274
+ # do nothing
275
+ end
276
+
277
+ begin
278
+ b
279
+ rescue => mes
280
+ # do nothing
281
+ end
282
+ ruby
283
+ ast = {:block=>
284
+ {:@array=>
285
+ [{:begin=>
286
+ {:@rescue=>
287
+ {:rescue=>
288
+ {:@body=>
289
+ {:send=>
290
+ {:@block=>nil,
291
+ :@name=>:a,
292
+ :@line=>2,
293
+ :@privately=>true,
294
+ :@receiver=>{:self=>{:@line=>2}},
295
+ :@check_for_local=>false}},
296
+ :@rescue=>
297
+ {:rescuecondition=>
298
+ {:@conditions=>
299
+ {:arrayliteral=>
300
+ {:@body=>
301
+ [{:constfind=>{:@name=>:StandardError, :@line=>3}}],
302
+ :@line=>3}},
303
+ :@body=>{},
304
+ :@splat=>nil,
305
+ :@next=>nil,
306
+ :@line=>3,
307
+ :@assignment=>
308
+ {:localvariableassignment=>
309
+ {:@variable=>nil,
310
+ :@name=>:mes,
311
+ :@line=>3,
312
+ :@value=>
313
+ {:globalvariableaccess=>{:@name=>:$!, :@line=>5}}}}}},
314
+ :@else=>nil,
315
+ :@line=>2}},
316
+ :@line=>1}},
317
+ {:begin=>
318
+ {:@rescue=>
319
+ {:rescue=>
320
+ {:@body=>
321
+ {:send=>
322
+ {:@block=>nil,
323
+ :@name=>:b,
324
+ :@line=>8,
325
+ :@privately=>true,
326
+ :@receiver=>{:self=>{:@line=>8}},
327
+ :@check_for_local=>false}},
328
+ :@rescue=>
329
+ {:rescuecondition=>
330
+ {:@conditions=>
331
+ {:arrayliteral=>
332
+ {:@body=>
333
+ [{:constfind=>{:@name=>:StandardError, :@line=>9}}],
334
+ :@line=>9}},
335
+ :@body=>{},
336
+ :@splat=>nil,
337
+ :@next=>nil,
338
+ :@line=>9,
339
+ :@assignment=>
340
+ {:localvariableassignment=>
341
+ {:@variable=>nil,
342
+ :@name=>:mes,
343
+ :@line=>9,
344
+ :@value=>
345
+ {:globalvariableaccess=>{:@name=>:$!, :@line=>11}}}}}},
346
+ :@else=>nil,
347
+ :@line=>8}},
348
+ :@line=>7}}],
349
+ :@line=>1}}
350
+
351
+ ruby.should parse_as(ast)
352
+ end
353
+
354
+ it 'should correctly parse "begin ... blah ... rescue RuntimeError => r ..."' do
355
+ ruby = <<-ruby
356
+ begin
357
+ blah
358
+ rescue RuntimeError => r
359
+ end
360
+ ruby
361
+ ast = {:begin=>
362
+ {:@rescue=>
363
+ {:rescue=>
364
+ {:@body=>
365
+ {:send=>
366
+ {:@block=>nil,
367
+ :@name=>:blah,
368
+ :@line=>2,
369
+ :@privately=>true,
370
+ :@receiver=>{:self=>{:@line=>2}},
371
+ :@check_for_local=>false}},
372
+ :@rescue=>
373
+ {:rescuecondition=>
374
+ {:@conditions=>
375
+ {:arrayliteral=>
376
+ {:@body=>[{:constfind=>{:@name=>:RuntimeError, :@line=>3}}],
377
+ :@line=>3}},
378
+ :@body=>{},
379
+ :@splat=>nil,
380
+ :@next=>nil,
381
+ :@line=>3,
382
+ :@assignment=>
383
+ {:localvariableassignment=>
384
+ {:@variable=>nil,
385
+ :@name=>:r,
386
+ :@line=>3,
387
+ :@value=>{:globalvariableaccess=>{:@name=>:$!, :@line=>4}}}}}},
388
+ :@else=>nil,
389
+ :@line=>2}},
390
+ :@line=>1}}
391
+
392
+ ruby.should parse_as(ast)
393
+ end
394
+
395
+ it 'should correctly parse "begin ... 1 ... rescue => @e"' do
396
+ ruby = <<-ruby
397
+ begin
398
+ 1
399
+ rescue => @e
400
+ end
401
+ ruby
402
+ ast = {:begin=>
403
+ {:@rescue=>
404
+ {:rescue=>
405
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>1}},
406
+ :@rescue=>
407
+ {:rescuecondition=>
408
+ {:@conditions=>
409
+ {:arrayliteral=>
410
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>3}}],
411
+ :@line=>3}},
412
+ :@body=>{},
413
+ :@splat=>nil,
414
+ :@next=>nil,
415
+ :@line=>3,
416
+ :@assignment=>
417
+ {:instancevariableassignment=>
418
+ {:@name=>:@e,
419
+ :@line=>3,
420
+ :@value=>{:globalvariableaccess=>{:@name=>:$!, :@line=>4}}}}}},
421
+ :@else=>nil,
422
+ :@line=>2}},
423
+ :@line=>1}}
424
+
425
+ ruby.should parse_as(ast)
426
+ end
427
+
428
+ it 'should correctly parse "begin ... rescue ... var = 2 ..."' do
429
+ ruby = <<-ruby
430
+ begin
431
+ 1
432
+ rescue
433
+ var = 2
434
+ end
435
+ ruby
436
+ ast = {:begin=>
437
+ {:@rescue=>
438
+ {:rescue=>
439
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>1}},
440
+ :@rescue=>
441
+ {:rescuecondition=>
442
+ {:@conditions=>
443
+ {:arrayliteral=>
444
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>4}}],
445
+ :@line=>4}},
446
+ :@body=>
447
+ {:localvariableassignment=>
448
+ {:@variable=>nil,
449
+ :@name=>:var,
450
+ :@line=>4,
451
+ :@value=>{:fixnumliteral=>{:@line=>4, :@value=>2}}}},
452
+ :@splat=>nil,
453
+ :@next=>nil,
454
+ :@line=>4,
455
+ :@assignment=>nil}},
456
+ :@else=>nil,
457
+ :@line=>2}},
458
+ :@line=>1}}
459
+
460
+ ruby.should parse_as(ast)
461
+ end
462
+
463
+ it 'should correctly parse "begin 1 rescue => e ..."' do
464
+ ruby = <<-ruby
465
+ begin
466
+ 1
467
+ rescue => e
468
+ end
469
+ ruby
470
+ ast = {:begin=>
471
+ {:@rescue=>
472
+ {:rescue=>
473
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>1}},
474
+ :@rescue=>
475
+ {:rescuecondition=>
476
+ {:@conditions=>
477
+ {:arrayliteral=>
478
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>3}}],
479
+ :@line=>3}},
480
+ :@body=>{},
481
+ :@splat=>nil,
482
+ :@next=>nil,
483
+ :@line=>3,
484
+ :@assignment=>
485
+ {:localvariableassignment=>
486
+ {:@variable=>nil,
487
+ :@name=>:e,
488
+ :@line=>3,
489
+ :@value=>{:globalvariableaccess=>{:@name=>:$!, :@line=>4}}}}}},
490
+ :@else=>nil,
491
+ :@line=>2}},
492
+ :@line=>1}}
493
+
494
+ ruby.should parse_as(ast)
495
+ end
496
+
497
+ it 'should correctly parse "begin 1 rescue a.b = nil ..."' do
498
+ ruby = <<-ruby
499
+ begin
500
+ 1
501
+ rescue
502
+ a.b = nil
503
+ end
504
+ ruby
505
+ ast = {:begin=>
506
+ {:@rescue=>
507
+ {:rescue=>
508
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>1}},
509
+ :@rescue=>
510
+ {:rescuecondition=>
511
+ {:@conditions=>
512
+ {:arrayliteral=>
513
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>4}}],
514
+ :@line=>4}},
515
+ :@body=>
516
+ {:attributeassignment=>
517
+ {:@name=>:b=,
518
+ :@line=>4,
519
+ :@privately=>false,
520
+ :@receiver=>
521
+ {:send=>
522
+ {:@block=>nil,
523
+ :@name=>:a,
524
+ :@line=>4,
525
+ :@privately=>true,
526
+ :@receiver=>{:self=>{:@line=>4}},
527
+ :@check_for_local=>false}},
528
+ :@arguments=>
529
+ {:actualarguments=>{:@array=>[{}], :@splat=>nil, :@line=>4}}}},
530
+ :@splat=>nil,
531
+ :@next=>nil,
532
+ :@line=>4,
533
+ :@assignment=>nil}},
534
+ :@else=>nil,
535
+ :@line=>2}},
536
+ :@line=>1}}
537
+
538
+ ruby.should parse_as(ast)
539
+ end
540
+
541
+ it 'should correctly parse "begin 1 rescue => e var = 2 ..."' do
542
+ ruby = <<-ruby
543
+ begin
544
+ 1
545
+ rescue => e
546
+ var = 2
547
+ end
548
+ ruby
549
+ ast = {:begin=>
550
+ {:@rescue=>
551
+ {:rescue=>
552
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>1}},
553
+ :@rescue=>
554
+ {:rescuecondition=>
555
+ {:@conditions=>
556
+ {:arrayliteral=>
557
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>3}}],
558
+ :@line=>3}},
559
+ :@body=>
560
+ {:block=>
561
+ {:@array=>
562
+ [{:localvariableassignment=>
563
+ {:@variable=>nil,
564
+ :@name=>:var,
565
+ :@line=>4,
566
+ :@value=>{:fixnumliteral=>{:@line=>4, :@value=>2}}}}],
567
+ :@line=>3}},
568
+ :@splat=>nil,
569
+ :@next=>nil,
570
+ :@line=>3,
571
+ :@assignment=>
572
+ {:localvariableassignment=>
573
+ {:@variable=>nil,
574
+ :@name=>:e,
575
+ :@line=>3,
576
+ :@value=>{:globalvariableaccess=>{:@name=>:$!, :@line=>5}}}}}},
577
+ :@else=>nil,
578
+ :@line=>2}},
579
+ :@line=>1}}
580
+
581
+ ruby.should parse_as(ast)
582
+ end
583
+
584
+ it 'should correctly parse "begin ... rescue ... else ..."' do
585
+ ruby = <<-ruby
586
+ begin
587
+ 12
588
+ rescue String
589
+ 13
590
+ else
591
+ 14
592
+ end
593
+ ruby
594
+ ast = {:begin=>
595
+ {:@rescue=>
596
+ {:rescue=>
597
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>12}},
598
+ :@rescue=>
599
+ {:rescuecondition=>
600
+ {:@conditions=>
601
+ {:arrayliteral=>
602
+ {:@body=>[{:constfind=>{:@name=>:String, :@line=>3}}],
603
+ :@line=>3}},
604
+ :@body=>{:fixnumliteral=>{:@line=>4, :@value=>13}},
605
+ :@splat=>nil,
606
+ :@next=>nil,
607
+ :@line=>3,
608
+ :@assignment=>nil}},
609
+ :@else=>{:fixnumliteral=>{:@line=>6, :@value=>14}},
610
+ :@line=>2}},
611
+ :@line=>1}}
612
+
613
+ ruby.should parse_as(ast)
614
+ end
615
+
616
+ it 'should correctly parse "begin ... rescue *blah ..."' do
617
+ ruby = <<-ruby
618
+ begin
619
+ 12
620
+ rescue *blah
621
+ 13
622
+ end
623
+ ruby
624
+ ast = {:begin=>
625
+ {:@rescue=>
626
+ {:rescue=>
627
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>12}},
628
+ :@rescue=>
629
+ {:rescuecondition=>
630
+ {:@body=>{:fixnumliteral=>{:@line=>4, :@value=>13}},
631
+ :@splat=>
632
+ {:rescuesplat=>
633
+ {:@line=>3,
634
+ :@value=>
635
+ {:send=>
636
+ {:@block=>nil,
637
+ :@name=>:blah,
638
+ :@line=>3,
639
+ :@privately=>true,
640
+ :@receiver=>{:self=>{:@line=>3}},
641
+ :@check_for_local=>false}}}},
642
+ :@next=>nil,
643
+ :@line=>3,
644
+ :@assignment=>nil}},
645
+ :@else=>nil,
646
+ :@line=>2}},
647
+ :@line=>1}}
648
+
649
+ ruby.should parse_as(ast)
650
+ end
651
+
652
+ it 'should correctly parse "begin ... rescue String, *blah ..."' do
653
+ ruby = <<-ruby
654
+ begin
655
+ 12
656
+ rescue String, *blah
657
+ 13
658
+ end
659
+ ruby
660
+ ast = {:begin=>
661
+ {:@rescue=>
662
+ {:rescue=>
663
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>12}},
664
+ :@rescue=>
665
+ {:rescuecondition=>
666
+ {:@conditions=>
667
+ {:arrayliteral=>
668
+ {:@body=>[{:constfind=>{:@name=>:String, :@line=>3}}],
669
+ :@line=>3}},
670
+ :@body=>{:fixnumliteral=>{:@line=>4, :@value=>13}},
671
+ :@splat=>
672
+ {:rescuesplat=>
673
+ {:@line=>3,
674
+ :@value=>
675
+ {:send=>
676
+ {:@block=>nil,
677
+ :@name=>:blah,
678
+ :@line=>3,
679
+ :@privately=>true,
680
+ :@receiver=>{:self=>{:@line=>3}},
681
+ :@check_for_local=>false}}}},
682
+ :@next=>nil,
683
+ :@line=>3,
684
+ :@assignment=>nil}},
685
+ :@else=>nil,
686
+ :@line=>2}},
687
+ :@line=>1}}
688
+
689
+ ruby.should parse_as(ast)
690
+ end
691
+
692
+ it 'should correctly parse "begin ... rescue *blah => e ..."' do
693
+ ruby = <<-ruby
694
+ begin
695
+ 12
696
+ rescue *blah => e
697
+ 13
698
+ end
699
+ ruby
700
+ ast = {:begin=>
701
+ {:@rescue=>
702
+ {:rescue=>
703
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>12}},
704
+ :@rescue=>
705
+ {:rescuecondition=>
706
+ {:@body=>
707
+ {:block=>
708
+ {:@array=>[{:fixnumliteral=>{:@line=>4, :@value=>13}}],
709
+ :@line=>3}},
710
+ :@splat=>
711
+ {:rescuesplat=>
712
+ {:@line=>3,
713
+ :@value=>
714
+ {:send=>
715
+ {:@block=>nil,
716
+ :@name=>:blah,
717
+ :@line=>3,
718
+ :@privately=>true,
719
+ :@receiver=>{:self=>{:@line=>3}},
720
+ :@check_for_local=>false}}}},
721
+ :@next=>nil,
722
+ :@line=>3,
723
+ :@assignment=>
724
+ {:localvariableassignment=>
725
+ {:@variable=>nil,
726
+ :@name=>:e,
727
+ :@line=>3,
728
+ :@value=>{:globalvariableaccess=>{:@name=>:$!, :@line=>5}}}}}},
729
+ :@else=>nil,
730
+ :@line=>2}},
731
+ :@line=>1}}
732
+
733
+ ruby.should parse_as(ast)
734
+ end
735
+
736
+ it 'should correctly parse "begin ... rescue String, *blah => e ..."' do
737
+ ruby = <<-ruby
738
+ begin
739
+ 12
740
+ rescue String, *blah => e
741
+ 13
742
+ end
743
+ ruby
744
+ ast = {:begin=>
745
+ {:@rescue=>
746
+ {:rescue=>
747
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>12}},
748
+ :@rescue=>
749
+ {:rescuecondition=>
750
+ {:@conditions=>
751
+ {:arrayliteral=>
752
+ {:@body=>[{:constfind=>{:@name=>:String, :@line=>3}}],
753
+ :@line=>3}},
754
+ :@body=>
755
+ {:block=>
756
+ {:@array=>[{:fixnumliteral=>{:@line=>4, :@value=>13}}],
757
+ :@line=>3}},
758
+ :@splat=>
759
+ {:rescuesplat=>
760
+ {:@line=>3,
761
+ :@value=>
762
+ {:send=>
763
+ {:@block=>nil,
764
+ :@name=>:blah,
765
+ :@line=>3,
766
+ :@privately=>true,
767
+ :@receiver=>{:self=>{:@line=>3}},
768
+ :@check_for_local=>false}}}},
769
+ :@next=>nil,
770
+ :@line=>3,
771
+ :@assignment=>
772
+ {:localvariableassignment=>
773
+ {:@variable=>nil,
774
+ :@name=>:e,
775
+ :@line=>3,
776
+ :@value=>{:globalvariableaccess=>{:@name=>:$!, :@line=>5}}}}}},
777
+ :@else=>nil,
778
+ :@line=>2}},
779
+ :@line=>1}}
780
+
781
+ ruby.should parse_as(ast)
782
+ end
783
+
784
+ it 'should correctly parse "begin ... rescue ... return"' do
785
+ ruby = <<-ruby
786
+ begin
787
+ 12
788
+ rescue String
789
+ return nil
790
+ end
791
+ ruby
792
+ ast = {:begin=>
793
+ {:@rescue=>
794
+ {:rescue=>
795
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>12}},
796
+ :@rescue=>
797
+ {:rescuecondition=>
798
+ {:@conditions=>
799
+ {:arrayliteral=>
800
+ {:@body=>[{:constfind=>{:@name=>:String, :@line=>3}}],
801
+ :@line=>3}},
802
+ :@body=>{:return=>{:@splat=>nil, :@line=>4, :@value=>{}}},
803
+ :@splat=>nil,
804
+ :@next=>nil,
805
+ :@line=>3,
806
+ :@assignment=>nil}},
807
+ :@else=>nil,
808
+ :@line=>2}},
809
+ :@line=>1}}
810
+
811
+ ruby.should parse_as(ast)
812
+ end
813
+
814
+ it 'should correctly parse "begin ... rescue begin ... rescue ..."' do
815
+ ruby = <<-ruby
816
+ begin
817
+ 1
818
+ rescue
819
+ begin
820
+ 2
821
+ rescue
822
+ return 3
823
+ end
824
+ end
825
+ ruby
826
+ ast = {:begin=>
827
+ {:@rescue=>
828
+ {:rescue=>
829
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>1}},
830
+ :@rescue=>
831
+ {:rescuecondition=>
832
+ {:@conditions=>
833
+ {:arrayliteral=>
834
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>4}}],
835
+ :@line=>4}},
836
+ :@body=>
837
+ {:begin=>
838
+ {:@rescue=>
839
+ {:rescue=>
840
+ {:@body=>{:fixnumliteral=>{:@line=>5, :@value=>2}},
841
+ :@rescue=>
842
+ {:rescuecondition=>
843
+ {:@conditions=>
844
+ {:arrayliteral=>
845
+ {:@body=>
846
+ [{:constfind=>
847
+ {:@name=>:StandardError, :@line=>7}}],
848
+ :@line=>7}},
849
+ :@body=>
850
+ {:return=>
851
+ {:@splat=>nil,
852
+ :@line=>7,
853
+ :@value=>
854
+ {:fixnumliteral=>{:@line=>7, :@value=>3}}}},
855
+ :@splat=>nil,
856
+ :@next=>nil,
857
+ :@line=>7,
858
+ :@assignment=>nil}},
859
+ :@else=>nil,
860
+ :@line=>5}},
861
+ :@line=>4}},
862
+ :@splat=>nil,
863
+ :@next=>nil,
864
+ :@line=>4,
865
+ :@assignment=>nil}},
866
+ :@else=>nil,
867
+ :@line=>2}},
868
+ :@line=>1}}
869
+
870
+ ruby.should parse_as(ast)
871
+ end
872
+
873
+ it 'should correctly parse "begin ... rescue def ..."' do
874
+ ruby = <<-ruby
875
+ begin
876
+ 1
877
+ rescue
878
+ def x
879
+ return 2
880
+ end
881
+ x
882
+ end
883
+ ruby
884
+ ast = {:begin=>
885
+ {:@rescue=>
886
+ {:rescue=>
887
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>1}},
888
+ :@rescue=>
889
+ {:rescuecondition=>
890
+ {:@conditions=>
891
+ {:arrayliteral=>
892
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>4}}],
893
+ :@line=>4}},
894
+ :@body=>
895
+ {:block=>
896
+ {:@array=>
897
+ [{:define=>
898
+ {:@body=>
899
+ {:block=>
900
+ {:@array=>
901
+ [{:return=>
902
+ {:@splat=>nil,
903
+ :@line=>5,
904
+ :@value=>
905
+ {:fixnumliteral=>{:@line=>5, :@value=>2}}}}],
906
+ :@line=>4}},
907
+ :@name=>:x,
908
+ :@line=>4,
909
+ :@arguments=>
910
+ {:formalarguments=>
911
+ {:@block_arg=>nil,
912
+ :@names=>[],
913
+ :@defaults=>nil,
914
+ :@optional=>[],
915
+ :@splat=>nil,
916
+ :@line=>4,
917
+ :@required=>[]}}}},
918
+ {:send=>
919
+ {:@block=>nil,
920
+ :@name=>:x,
921
+ :@line=>7,
922
+ :@privately=>true,
923
+ :@receiver=>{:self=>{:@line=>7}},
924
+ :@check_for_local=>false}}],
925
+ :@line=>4}},
926
+ :@splat=>nil,
927
+ :@next=>nil,
928
+ :@line=>4,
929
+ :@assignment=>nil}},
930
+ :@else=>nil,
931
+ :@line=>2}},
932
+ :@line=>1}}
933
+
934
+ ruby.should parse_as(ast)
935
+ end
936
+
937
+ it 'should correctly parse "begin while ... break ... rescue ..."' do
938
+ ruby = <<-ruby
939
+ begin
940
+ while 1
941
+ 2
942
+ break :brk
943
+ end
944
+ rescue
945
+ 3
946
+ end
947
+ ruby
948
+ ast = {:begin=>
949
+ {:@rescue=>
950
+ {:rescue=>
951
+ {:@body=>
952
+ {:while=>
953
+ {:@body=>
954
+ {:block=>
955
+ {:@array=>
956
+ [{:fixnumliteral=>{:@line=>3, :@value=>2}},
957
+ {:break=>
958
+ {:@line=>4,
959
+ :@value=>{:symbolliteral=>{:@line=>4, :@value=>:brk}}}}],
960
+ :@line=>3}},
961
+ :@condition=>{:fixnumliteral=>{:@line=>2, :@value=>1}},
962
+ :@line=>2,
963
+ :@check_first=>true}},
964
+ :@rescue=>
965
+ {:rescuecondition=>
966
+ {:@conditions=>
967
+ {:arrayliteral=>
968
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>7}}],
969
+ :@line=>7}},
970
+ :@body=>{:fixnumliteral=>{:@line=>7, :@value=>3}},
971
+ :@splat=>nil,
972
+ :@next=>nil,
973
+ :@line=>7,
974
+ :@assignment=>nil}},
975
+ :@else=>nil,
976
+ :@line=>2}},
977
+ :@line=>1}}
978
+
979
+ ruby.should parse_as(ast)
980
+ end
981
+
982
+ it 'should correctly parse "begin ... rescue while ... break ..."' do
983
+ ruby = <<-ruby
984
+ begin
985
+ 1
986
+ rescue
987
+ while 2
988
+ 3
989
+ break :brk
990
+ end
991
+ end
992
+ ruby
993
+ ast = {:begin=>
994
+ {:@rescue=>
995
+ {:rescue=>
996
+ {:@body=>{:fixnumliteral=>{:@line=>2, :@value=>1}},
997
+ :@rescue=>
998
+ {:rescuecondition=>
999
+ {:@conditions=>
1000
+ {:arrayliteral=>
1001
+ {:@body=>[{:constfind=>{:@name=>:StandardError, :@line=>4}}],
1002
+ :@line=>4}},
1003
+ :@body=>
1004
+ {:while=>
1005
+ {:@body=>
1006
+ {:block=>
1007
+ {:@array=>
1008
+ [{:fixnumliteral=>{:@line=>5, :@value=>3}},
1009
+ {:break=>
1010
+ {:@line=>6,
1011
+ :@value=>
1012
+ {:symbolliteral=>{:@line=>6, :@value=>:brk}}}}],
1013
+ :@line=>5}},
1014
+ :@condition=>{:fixnumliteral=>{:@line=>4, :@value=>2}},
1015
+ :@line=>4,
1016
+ :@check_first=>true}},
1017
+ :@splat=>nil,
1018
+ :@next=>nil,
1019
+ :@line=>4,
1020
+ :@assignment=>nil}},
1021
+ :@else=>nil,
1022
+ :@line=>2}},
1023
+ :@line=>1}}
1024
+
1025
+ ruby.should parse_as(ast)
1026
+ end
1027
+
1028
+ end