rubinius-processor 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/rubinius/processor/processor.rb +657 -0
- data/lib/rubinius/processor/version.rb +5 -0
- data/lib/rubinius/processor.rb +2 -0
- data/rubinius-processor.gemspec +22 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6df08eadd456b4980806e6a9172640257787b02a
|
4
|
+
data.tar.gz: 9e5841c47d2a0c4c025e6962df45403f7da430b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7fb6833424b9206f12d8d4f887cd6440d5b99cd33f4d7598097739593c689efff6e227c39c2e733f3ceb367661a06311c82a34e78df971fc4fad7d6bdf54edeb
|
7
|
+
data.tar.gz: 01efcac3415b6937c51316f1a02f4fee868161839e46fff42367e66374be54940d67037c2e3808e3d69a293c0fff85569998ba4f6cf68447ecaaa8e2c678bcea
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2013, Brian Shirai
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
3. Neither the name of the library nor the names of its contributors may be
|
13
|
+
used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
|
20
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
21
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
22
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
23
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
25
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rubinius::Processor
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rubinius-processor'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rubinius-processor
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,657 @@
|
|
1
|
+
module Rubinius::ToolSet.current::TS
|
2
|
+
# TODO: This will change to:
|
3
|
+
# class Processor
|
4
|
+
class Melbourne
|
5
|
+
def process_parse_error(message, column, line, source)
|
6
|
+
msg = "#{message}: #{@name}:#{line}:#{column}"
|
7
|
+
@syntax_errors << SyntaxError.from(msg, column, line, source, @name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def process_dangling_node
|
11
|
+
puts "Processing called but node was NULL"
|
12
|
+
# TODO: output info about the current AST node
|
13
|
+
end
|
14
|
+
|
15
|
+
# This method is analogous to #method_missing. It is called
|
16
|
+
# if there is no processing method defined for a node.
|
17
|
+
def process_missing_node(line, node_name, node_type)
|
18
|
+
puts "Unhandled node #{node_name} (#{node_type})"
|
19
|
+
end
|
20
|
+
|
21
|
+
# TODO: remove when all processors are defined
|
22
|
+
def method_missing(sym, *args)
|
23
|
+
puts " *** missing #{sym} #{args.map { |x| x.inspect}.join(", ")}"
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
# Processing methods
|
28
|
+
|
29
|
+
def process_alias(line, to, from)
|
30
|
+
AST::Alias.new line, to, from
|
31
|
+
end
|
32
|
+
|
33
|
+
def process_and(line, left, right)
|
34
|
+
AST::And.new line, left, right
|
35
|
+
end
|
36
|
+
|
37
|
+
def process_args(line, args, defaults, splat)
|
38
|
+
AST::FormalArguments.new line, args, defaults, splat
|
39
|
+
end
|
40
|
+
|
41
|
+
def process_argscat(line, array, rest)
|
42
|
+
AST::ConcatArgs.new line, array, rest
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_argspush(line, arguments, value)
|
46
|
+
AST::PushArgs.new line, arguments, value
|
47
|
+
end
|
48
|
+
|
49
|
+
def process_array(line, array)
|
50
|
+
AST::ArrayLiteral.new line, array
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_attrasgn(line, receiver, name, arguments)
|
54
|
+
if name == :[]=
|
55
|
+
AST::ElementAssignment.new line, receiver, arguments
|
56
|
+
else
|
57
|
+
AST::AttributeAssignment.new line, receiver, name, arguments
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def process_back_ref(line, ref)
|
62
|
+
AST::BackRef.new line, ref
|
63
|
+
end
|
64
|
+
|
65
|
+
def process_begin(line, body)
|
66
|
+
AST::Begin.new line, body
|
67
|
+
end
|
68
|
+
|
69
|
+
def process_block(line, array)
|
70
|
+
AST::Block.new line, array
|
71
|
+
end
|
72
|
+
|
73
|
+
def process_block_arg(line, name)
|
74
|
+
AST::BlockArgument.new line, name
|
75
|
+
end
|
76
|
+
|
77
|
+
def process_block_pass(line, method_send, body)
|
78
|
+
node = AST::BlockPass.new line, body
|
79
|
+
if method_send
|
80
|
+
method_send.block = node
|
81
|
+
method_send
|
82
|
+
else
|
83
|
+
node
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def process_break(line, value)
|
88
|
+
AST::Break.new line, value
|
89
|
+
end
|
90
|
+
|
91
|
+
def process_call(line, receiver, name, arguments)
|
92
|
+
if arguments.kind_of? AST::BlockPass
|
93
|
+
block = arguments
|
94
|
+
arguments = block.arguments
|
95
|
+
block.arguments = nil
|
96
|
+
else
|
97
|
+
block = nil
|
98
|
+
end
|
99
|
+
|
100
|
+
if node = process_transforms(line, receiver, name, arguments)
|
101
|
+
node.block = block if block
|
102
|
+
return node
|
103
|
+
end
|
104
|
+
|
105
|
+
if arguments
|
106
|
+
node = AST::SendWithArguments.new line, receiver, name, arguments
|
107
|
+
else
|
108
|
+
node = AST::Send.new line, receiver, name
|
109
|
+
end
|
110
|
+
|
111
|
+
node.block = block
|
112
|
+
node
|
113
|
+
end
|
114
|
+
|
115
|
+
def process_case(line, receiver, whens, else_body)
|
116
|
+
if receiver
|
117
|
+
AST::ReceiverCase.new line, receiver, whens, else_body
|
118
|
+
else
|
119
|
+
AST::Case.new line, whens, else_body
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def process_cdecl(line, expr, value)
|
124
|
+
AST::ConstantAssignment.new line, expr, value
|
125
|
+
end
|
126
|
+
|
127
|
+
def process_class(line, name, superclass, body)
|
128
|
+
AST::Class.new line, name, superclass, body
|
129
|
+
end
|
130
|
+
|
131
|
+
def process_colon2(line, outer, name)
|
132
|
+
if outer
|
133
|
+
if outer.kind_of? AST::ConstantAccess and
|
134
|
+
outer.name == :Rubinius
|
135
|
+
case name
|
136
|
+
when :Type
|
137
|
+
AST::TypeConstant.new line
|
138
|
+
when :Mirror
|
139
|
+
AST::MirrorConstant.new line
|
140
|
+
else
|
141
|
+
AST::ScopedConstant.new line, outer, name
|
142
|
+
end
|
143
|
+
else
|
144
|
+
AST::ScopedConstant.new line, outer, name
|
145
|
+
end
|
146
|
+
else
|
147
|
+
AST::ConstantAccess.new line, name
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def process_colon3(line, name)
|
152
|
+
AST::ToplevelConstant.new line, name
|
153
|
+
end
|
154
|
+
|
155
|
+
def process_const(line, name)
|
156
|
+
AST::ConstantAccess.new line, name
|
157
|
+
end
|
158
|
+
|
159
|
+
def process_cvar(line, name)
|
160
|
+
AST::ClassVariableAccess.new line, name
|
161
|
+
end
|
162
|
+
|
163
|
+
def process_cvasgn(line, name, value)
|
164
|
+
AST::ClassVariableAssignment.new line, name, value
|
165
|
+
end
|
166
|
+
|
167
|
+
def process_cvdecl(line, name, value)
|
168
|
+
AST::ClassVariableDeclaration.new line, name, value
|
169
|
+
end
|
170
|
+
|
171
|
+
def process_defined(line, expr)
|
172
|
+
AST::Defined.new line, expr
|
173
|
+
end
|
174
|
+
|
175
|
+
def process_defn(line, name, body)
|
176
|
+
AST::Define.new line, name, body
|
177
|
+
end
|
178
|
+
|
179
|
+
def process_defs(line, receiver, name, body)
|
180
|
+
AST::DefineSingleton.new line, receiver, name, body
|
181
|
+
end
|
182
|
+
|
183
|
+
def process_dot2(line, start, finish)
|
184
|
+
AST::Range.new line, start, finish
|
185
|
+
end
|
186
|
+
|
187
|
+
def process_dot3(line, start, finish)
|
188
|
+
AST::RangeExclude.new line, start, finish
|
189
|
+
end
|
190
|
+
|
191
|
+
def process_dregx(line, str, array, flags)
|
192
|
+
AST::DynamicRegex.new line, str, array, flags
|
193
|
+
end
|
194
|
+
|
195
|
+
def process_dregx_once(line, str, array, flags)
|
196
|
+
AST::DynamicOnceRegex.new line, str, array, flags
|
197
|
+
end
|
198
|
+
|
199
|
+
def process_dstr(line, str, array)
|
200
|
+
AST::DynamicString.new line, str, array
|
201
|
+
end
|
202
|
+
|
203
|
+
def process_dsym(line, str, array)
|
204
|
+
AST::DynamicSymbol.new line, str, array
|
205
|
+
end
|
206
|
+
|
207
|
+
def process_dxstr(line, str, array)
|
208
|
+
AST::DynamicExecuteString.new line, str, array
|
209
|
+
end
|
210
|
+
|
211
|
+
def process_ensure(line, body, ensr)
|
212
|
+
AST::Ensure.new line, body, ensr
|
213
|
+
end
|
214
|
+
|
215
|
+
def process_evstr(line, value)
|
216
|
+
if value
|
217
|
+
AST::ToString.new line, value
|
218
|
+
else
|
219
|
+
AST::StringLiteral.new line, ""
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def process_false(line)
|
224
|
+
AST::FalseLiteral.new line
|
225
|
+
end
|
226
|
+
|
227
|
+
def process_fcall(line, name, arguments)
|
228
|
+
receiver = AST::Self.new line
|
229
|
+
|
230
|
+
if arguments.kind_of? AST::BlockPass
|
231
|
+
block = arguments
|
232
|
+
arguments = block.arguments
|
233
|
+
block.arguments = nil
|
234
|
+
else
|
235
|
+
block = nil
|
236
|
+
end
|
237
|
+
|
238
|
+
if node = process_transforms(line, receiver, name, arguments, true)
|
239
|
+
node.block = block if block
|
240
|
+
return node
|
241
|
+
end
|
242
|
+
|
243
|
+
if arguments
|
244
|
+
node = AST::SendWithArguments.new line, receiver, name, arguments, true
|
245
|
+
else
|
246
|
+
node = AST::Send.new line, receiver, name, true
|
247
|
+
end
|
248
|
+
|
249
|
+
node.block = block
|
250
|
+
node
|
251
|
+
end
|
252
|
+
|
253
|
+
def process_file(line)
|
254
|
+
AST::File.new line
|
255
|
+
end
|
256
|
+
|
257
|
+
def process_fixnum(line, value)
|
258
|
+
AST::FixnumLiteral.new line, value
|
259
|
+
end
|
260
|
+
|
261
|
+
def process_flip2(line, start, finish)
|
262
|
+
AST::Flip2.new line, start, finish
|
263
|
+
end
|
264
|
+
|
265
|
+
def process_flip3(line, start, finish)
|
266
|
+
AST::Flip3.new line, start, finish
|
267
|
+
end
|
268
|
+
|
269
|
+
def process_float(line, str)
|
270
|
+
AST::FloatLiteral.new line, str
|
271
|
+
end
|
272
|
+
|
273
|
+
def process_for(line, iter, arguments, body)
|
274
|
+
method_send = AST::Send.new line, iter, :each
|
275
|
+
method_send.block = AST::For.new line, arguments, body
|
276
|
+
method_send
|
277
|
+
end
|
278
|
+
|
279
|
+
def process_gasgn(line, name, expr)
|
280
|
+
AST::GlobalVariableAssignment.new line, name, expr
|
281
|
+
end
|
282
|
+
|
283
|
+
def process_gvar(line, name)
|
284
|
+
AST::GlobalVariableAccess.for_name line, name
|
285
|
+
end
|
286
|
+
|
287
|
+
def process_hash(line, array)
|
288
|
+
AST::HashLiteral.new line, array
|
289
|
+
end
|
290
|
+
|
291
|
+
def process_iasgn(line, name, value)
|
292
|
+
AST::InstanceVariableAssignment.new line, name, value
|
293
|
+
end
|
294
|
+
|
295
|
+
def process_if(line, cond, body, else_body)
|
296
|
+
AST::If.new line, cond, body, else_body
|
297
|
+
end
|
298
|
+
|
299
|
+
def process_iter(line, method_send, arguments, body)
|
300
|
+
method_send.block = AST::Iter.new line, arguments, body
|
301
|
+
method_send
|
302
|
+
end
|
303
|
+
|
304
|
+
def process_ivar(line, name)
|
305
|
+
AST::InstanceVariableAccess.new line, name
|
306
|
+
end
|
307
|
+
|
308
|
+
def process_lasgn(line, name, value)
|
309
|
+
AST::LocalVariableAssignment.new line, name, value
|
310
|
+
end
|
311
|
+
|
312
|
+
def process_lit(line, sym)
|
313
|
+
AST::SymbolLiteral.new line, sym
|
314
|
+
end
|
315
|
+
|
316
|
+
def process_lvar(line, name)
|
317
|
+
AST::LocalVariableAccess.new line, name
|
318
|
+
end
|
319
|
+
|
320
|
+
def process_masgn(line, left, right, splat)
|
321
|
+
AST::MultipleAssignment.new line, left, right, splat
|
322
|
+
end
|
323
|
+
|
324
|
+
def process_match(line, pattern, flags)
|
325
|
+
AST::Match.new line, pattern, flags
|
326
|
+
end
|
327
|
+
|
328
|
+
def process_match2(line, pattern, value)
|
329
|
+
AST::Match2.new line, pattern, value
|
330
|
+
end
|
331
|
+
|
332
|
+
def process_match3(line, pattern, value)
|
333
|
+
AST::Match3.new line, pattern, value
|
334
|
+
end
|
335
|
+
|
336
|
+
def process_module(line, name, body)
|
337
|
+
AST::Module.new line, name, body
|
338
|
+
end
|
339
|
+
|
340
|
+
def process_negate(line, value)
|
341
|
+
AST::Negate.new line, value
|
342
|
+
end
|
343
|
+
|
344
|
+
def process_next(line, value)
|
345
|
+
AST::Next.new line, value
|
346
|
+
end
|
347
|
+
|
348
|
+
def process_nil(line)
|
349
|
+
AST::NilLiteral.new line
|
350
|
+
end
|
351
|
+
|
352
|
+
def process_not(line, value)
|
353
|
+
AST::Not.new line, value
|
354
|
+
end
|
355
|
+
|
356
|
+
def process_nth_ref(line, ref)
|
357
|
+
AST::NthRef.new line, ref
|
358
|
+
end
|
359
|
+
|
360
|
+
# TODO: Fix the way 1.8 parser handles this
|
361
|
+
def process_number(line, base, str)
|
362
|
+
value = str.to_i base
|
363
|
+
case value
|
364
|
+
when Fixnum
|
365
|
+
AST::FixnumLiteral.new line, value
|
366
|
+
when Bignum
|
367
|
+
AST::NumberLiteral.new line, value
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
def process_op_asgn1(line, receiver, index, op, value)
|
372
|
+
AST::OpAssign1.new line, receiver, index, op, value
|
373
|
+
end
|
374
|
+
|
375
|
+
def process_op_asgn2(line, receiver, name, op, value)
|
376
|
+
AST::OpAssign2.new line, receiver, name, op, value
|
377
|
+
end
|
378
|
+
|
379
|
+
def process_op_asgn_and(line, var, value)
|
380
|
+
AST::OpAssignAnd.new line, var, value
|
381
|
+
end
|
382
|
+
|
383
|
+
def process_op_asgn_or(line, var, value)
|
384
|
+
AST::OpAssignOr.new line, var, value
|
385
|
+
end
|
386
|
+
|
387
|
+
def process_or(line, left, right)
|
388
|
+
AST::Or.new line, left, right
|
389
|
+
end
|
390
|
+
|
391
|
+
def process_postexe(line)
|
392
|
+
AST::Send.new line, AST::Self.new(line), :at_exit, true
|
393
|
+
end
|
394
|
+
|
395
|
+
def process_preexe(line)
|
396
|
+
node = AST::PreExe.new line
|
397
|
+
add_pre_exe node
|
398
|
+
node
|
399
|
+
end
|
400
|
+
|
401
|
+
def process_redo(line)
|
402
|
+
AST::Redo.new line
|
403
|
+
end
|
404
|
+
|
405
|
+
def process_regex(line, str, flags)
|
406
|
+
AST::RegexLiteral.new line, str, flags
|
407
|
+
end
|
408
|
+
|
409
|
+
def process_resbody(line, conditions, body, nxt)
|
410
|
+
AST::RescueCondition.new line, conditions, body, nxt
|
411
|
+
end
|
412
|
+
|
413
|
+
def process_rescue(line, body, rescue_body, else_body)
|
414
|
+
AST::Rescue.new line, body, rescue_body, else_body
|
415
|
+
end
|
416
|
+
|
417
|
+
def process_retry(line)
|
418
|
+
AST::Retry.new line
|
419
|
+
end
|
420
|
+
|
421
|
+
def process_return(line, value)
|
422
|
+
AST::Return.new line, value
|
423
|
+
end
|
424
|
+
|
425
|
+
def process_sclass(line, receiver, body)
|
426
|
+
AST::SClass.new line, receiver, body
|
427
|
+
end
|
428
|
+
|
429
|
+
def process_scope(line, body)
|
430
|
+
if body.kind_of? AST::Block
|
431
|
+
body
|
432
|
+
elsif body
|
433
|
+
AST::Block.new line, [body]
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
def process_self(line)
|
438
|
+
AST::Self.new line
|
439
|
+
end
|
440
|
+
|
441
|
+
def process_splat(line, expr)
|
442
|
+
AST::SplatValue.new line, expr
|
443
|
+
end
|
444
|
+
|
445
|
+
def process_str(line, str)
|
446
|
+
AST::StringLiteral.new line, str
|
447
|
+
end
|
448
|
+
|
449
|
+
def process_super(line, arguments)
|
450
|
+
AST::Super.new line, arguments
|
451
|
+
end
|
452
|
+
|
453
|
+
def process_svalue(line, expr)
|
454
|
+
AST::SValue.new line, expr
|
455
|
+
end
|
456
|
+
|
457
|
+
def process_to_ary(line, expr)
|
458
|
+
AST::ToArray.new line, expr
|
459
|
+
end
|
460
|
+
|
461
|
+
def process_true(line)
|
462
|
+
AST::TrueLiteral.new line
|
463
|
+
end
|
464
|
+
|
465
|
+
def process_undef(line, sym)
|
466
|
+
AST::Undef.new line, sym
|
467
|
+
end
|
468
|
+
|
469
|
+
def process_until(line, cond, body, check_first)
|
470
|
+
AST::Until.new line, cond, body, check_first
|
471
|
+
end
|
472
|
+
|
473
|
+
def process_vcall(line, name)
|
474
|
+
receiver = AST::Self.new line
|
475
|
+
|
476
|
+
if node = process_transforms(line, receiver, name, nil, true)
|
477
|
+
return node
|
478
|
+
end
|
479
|
+
|
480
|
+
AST::Send.new line, receiver, name, true, true
|
481
|
+
end
|
482
|
+
|
483
|
+
def process_valias(line, to, from)
|
484
|
+
AST::VAlias.new line, to, from
|
485
|
+
end
|
486
|
+
|
487
|
+
def process_values(line, first, rest)
|
488
|
+
rest.body.unshift first
|
489
|
+
rest
|
490
|
+
end
|
491
|
+
|
492
|
+
def process_when(line, conditions, body)
|
493
|
+
AST::When.new line, conditions, body
|
494
|
+
end
|
495
|
+
|
496
|
+
def process_while(line, cond, body, check_first)
|
497
|
+
AST::While.new line, cond, body, check_first
|
498
|
+
end
|
499
|
+
|
500
|
+
def process_xstr(line, str)
|
501
|
+
AST::ExecuteString.new line, str
|
502
|
+
end
|
503
|
+
|
504
|
+
def process_yield(line, arguments, unwrap)
|
505
|
+
AST::Yield.new line, arguments, unwrap
|
506
|
+
end
|
507
|
+
|
508
|
+
def process_zarray(line)
|
509
|
+
AST::EmptyArray.new line
|
510
|
+
end
|
511
|
+
|
512
|
+
def process_zsuper(line)
|
513
|
+
AST::ZSuper.new line
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
class Melbourne19 < Melbourne
|
518
|
+
def process_args(line, required, optional, splat, post, block)
|
519
|
+
AST::FormalArguments19.new line, required, optional, splat, post, block
|
520
|
+
end
|
521
|
+
|
522
|
+
def process_block_pass(line, arguments, body)
|
523
|
+
AST::BlockPass19.new line, arguments, body
|
524
|
+
end
|
525
|
+
|
526
|
+
def process_encoding(line, name)
|
527
|
+
AST::Encoding.new line, name
|
528
|
+
end
|
529
|
+
|
530
|
+
def process_postarg(line, into, rest)
|
531
|
+
AST::PostArg.new line, into, rest
|
532
|
+
end
|
533
|
+
|
534
|
+
def process_iter(line, method_send, scope)
|
535
|
+
ary = scope && scope.array || []
|
536
|
+
arguments = nil
|
537
|
+
|
538
|
+
if ary.first.kind_of? AST::FormalArguments
|
539
|
+
arguments = scope.array.shift
|
540
|
+
end
|
541
|
+
|
542
|
+
unless arguments
|
543
|
+
arguments = AST::FormalArguments19.new line, nil, nil, nil, nil, nil
|
544
|
+
end
|
545
|
+
|
546
|
+
case ary.size
|
547
|
+
when 0
|
548
|
+
body = nil
|
549
|
+
when 1
|
550
|
+
if scope.locals
|
551
|
+
body = scope
|
552
|
+
else
|
553
|
+
body = scope.array.shift
|
554
|
+
end
|
555
|
+
else
|
556
|
+
body = scope
|
557
|
+
end
|
558
|
+
|
559
|
+
method_send.block = AST::Iter19.new line, arguments, body
|
560
|
+
method_send
|
561
|
+
end
|
562
|
+
|
563
|
+
def process_for(line, iter, arguments, body)
|
564
|
+
send = AST::Send.new line, iter, :each
|
565
|
+
send.block = AST::For19.new line, arguments, body
|
566
|
+
send
|
567
|
+
end
|
568
|
+
|
569
|
+
def process_lambda(line, scope)
|
570
|
+
arguments = scope.array.shift
|
571
|
+
if scope.array.size == 1
|
572
|
+
body = scope.array.shift
|
573
|
+
else
|
574
|
+
body = scope
|
575
|
+
end
|
576
|
+
|
577
|
+
receiver = AST::Self.new line
|
578
|
+
method_send = AST::Send.new line, receiver, :lambda, true
|
579
|
+
|
580
|
+
method_send.block = AST::Iter19.new line, arguments, body
|
581
|
+
method_send
|
582
|
+
end
|
583
|
+
|
584
|
+
def process_number(line, value)
|
585
|
+
case value
|
586
|
+
when Fixnum
|
587
|
+
AST::FixnumLiteral.new line, value
|
588
|
+
when Bignum
|
589
|
+
AST::NumberLiteral.new line, value
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
def process_op_asgn_or(line, var, value)
|
594
|
+
AST::OpAssignOr19.new line, var, value
|
595
|
+
end
|
596
|
+
|
597
|
+
def process_opt_arg(line, arguments)
|
598
|
+
AST::Block.new line, arguments
|
599
|
+
end
|
600
|
+
|
601
|
+
def process_postexe(line, body)
|
602
|
+
node = AST::Send.new line, AST::Self.new(line), :at_exit, true
|
603
|
+
node.block = AST::Iter.new line, nil, body
|
604
|
+
node
|
605
|
+
end
|
606
|
+
|
607
|
+
def process_preexe(line, body)
|
608
|
+
node = AST::PreExe19.new line
|
609
|
+
node.block = AST::Iter19.new line, nil, body
|
610
|
+
add_pre_exe node
|
611
|
+
node
|
612
|
+
end
|
613
|
+
|
614
|
+
def process_scope(line, arguments, body, locals)
|
615
|
+
case body
|
616
|
+
when AST::Begin
|
617
|
+
if body.rescue.kind_of? AST::NilLiteral
|
618
|
+
return nil unless arguments
|
619
|
+
end
|
620
|
+
body = AST::Block.new line, [body.rescue]
|
621
|
+
when AST::Block
|
622
|
+
ary = body.array
|
623
|
+
if ary.size > 1 and
|
624
|
+
ary.first.kind_of?(AST::Begin) and
|
625
|
+
ary.first.rescue.kind_of?(AST::NilLiteral)
|
626
|
+
ary.shift
|
627
|
+
end
|
628
|
+
when nil
|
629
|
+
# Nothing
|
630
|
+
else
|
631
|
+
body = AST::Block.new line, [body]
|
632
|
+
end
|
633
|
+
|
634
|
+
if arguments and body
|
635
|
+
body.array.unshift arguments
|
636
|
+
end
|
637
|
+
|
638
|
+
body.locals = locals if locals
|
639
|
+
|
640
|
+
body
|
641
|
+
end
|
642
|
+
|
643
|
+
def process_super(line, arguments)
|
644
|
+
if arguments.kind_of? AST::BlockPass
|
645
|
+
block = arguments
|
646
|
+
arguments = block.arguments
|
647
|
+
block.arguments = nil
|
648
|
+
else
|
649
|
+
block = nil
|
650
|
+
end
|
651
|
+
|
652
|
+
node = AST::Super.new line, arguments
|
653
|
+
node.block = block
|
654
|
+
node
|
655
|
+
end
|
656
|
+
end
|
657
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rubinius/toolset'
|
3
|
+
require './lib/rubinius/processor/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rubinius-processor"
|
7
|
+
spec.version = Rubinius::ToolSet.current::TS::Processor::VERSION
|
8
|
+
spec.authors = ["Brian Shirai"]
|
9
|
+
spec.email = ["brixen@gmail.com"]
|
10
|
+
spec.description = %q{Converts Melbourne parse tree into an AST.}
|
11
|
+
spec.summary = %q{Converts Melbourne parse tree into an AST.}
|
12
|
+
spec.homepage = "https://github.com/rubinius/rubinius-processor"
|
13
|
+
spec.license = "BSD"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubinius-processor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Shirai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Converts Melbourne parse tree into an AST.
|
42
|
+
email:
|
43
|
+
- brixen@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/rubinius/processor.rb
|
54
|
+
- lib/rubinius/processor/processor.rb
|
55
|
+
- lib/rubinius/processor/version.rb
|
56
|
+
- rubinius-processor.gemspec
|
57
|
+
homepage: https://github.com/rubinius/rubinius-processor
|
58
|
+
licenses:
|
59
|
+
- BSD
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.0.7
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Converts Melbourne parse tree into an AST.
|
81
|
+
test_files: []
|