to_source 0.1.3 → 0.2.16
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.
- data/.gitignore +6 -6
- data/.rspec +1 -0
- data/.travis.yml +12 -1
- data/Changelog.md +115 -0
- data/Gemfile +5 -3
- data/Gemfile.devtools +67 -0
- data/Guardfile +18 -0
- data/LICENSE +21 -0
- data/README.md +52 -0
- data/Rakefile +3 -8
- data/TODO +9 -0
- data/bin/to_source +17 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/roodi.yml +26 -0
- data/config/site.reek +97 -0
- data/config/yardstick.yml +2 -0
- data/lib/to_source/command.rb +106 -0
- data/lib/to_source/emitter/access.rb +28 -0
- data/lib/to_source/emitter/actual_arguments.rb +89 -0
- data/lib/to_source/emitter/alias.rb +27 -0
- data/lib/to_source/emitter/assignment.rb +119 -0
- data/lib/to_source/emitter/attribute_assignment.rb +28 -0
- data/lib/to_source/emitter/begin.rb +71 -0
- data/lib/to_source/emitter/binary_operator.rb +63 -0
- data/lib/to_source/emitter/binary_operator_method.rb +58 -0
- data/lib/to_source/emitter/block.rb +29 -0
- data/lib/to_source/emitter/block_argument.rb +23 -0
- data/lib/to_source/emitter/block_pass.rb +23 -0
- data/lib/to_source/emitter/case.rb +85 -0
- data/lib/to_source/emitter/class.rb +44 -0
- data/lib/to_source/emitter/concat_arguments.rb +28 -0
- data/lib/to_source/emitter/default_arguments.rb +22 -0
- data/lib/to_source/emitter/define.rb +99 -0
- data/lib/to_source/emitter/defined.rb +24 -0
- data/lib/to_source/emitter/element_assignment.rb +29 -0
- data/lib/to_source/emitter/element_reference.rb +25 -0
- data/lib/to_source/emitter/empty_body.rb +21 -0
- data/lib/to_source/emitter/ensure.rb +50 -0
- data/lib/to_source/emitter/ensure_body.rb +27 -0
- data/lib/to_source/emitter/execute_string.rb +22 -0
- data/lib/to_source/emitter/formal_arguments.rb +212 -0
- data/lib/to_source/emitter/if.rb +96 -0
- data/lib/to_source/emitter/iter.rb +27 -0
- data/lib/to_source/emitter/keyword_value.rb +67 -0
- data/lib/to_source/emitter/literal/dynamic.rb +178 -0
- data/lib/to_source/emitter/literal.rb +232 -0
- data/lib/to_source/emitter/loop.rb +40 -0
- data/lib/to_source/emitter/match3.rb +25 -0
- data/lib/to_source/emitter/module.rb +28 -0
- data/lib/to_source/emitter/multiple_assignment.rb +49 -0
- data/lib/to_source/emitter/nth_ref.rb +22 -0
- data/lib/to_source/emitter/op_assign1.rb +27 -0
- data/lib/to_source/emitter/op_assign2.rb +27 -0
- data/lib/to_source/emitter/pattern_arguments.rb +24 -0
- data/lib/to_source/emitter/rescue.rb +28 -0
- data/lib/to_source/emitter/rescue_condition.rb +93 -0
- data/lib/to_source/emitter/scope.rb +24 -0
- data/lib/to_source/emitter/scope_name.rb +23 -0
- data/lib/to_source/emitter/scoped_name.rb +28 -0
- data/lib/to_source/emitter/send.rb +133 -0
- data/lib/to_source/emitter/send_with_arguments.rb +103 -0
- data/lib/to_source/emitter/singleton_class.rb +38 -0
- data/lib/to_source/emitter/splat.rb +24 -0
- data/lib/to_source/emitter/splat_when.rb +23 -0
- data/lib/to_source/emitter/static.rb +52 -0
- data/lib/to_source/emitter/super.rb +92 -0
- data/lib/to_source/emitter/to_array.rb +22 -0
- data/lib/to_source/emitter/to_string.rb +24 -0
- data/lib/to_source/emitter/toplevel.rb +24 -0
- data/lib/to_source/emitter/unary_operator_method.rb +27 -0
- data/lib/to_source/emitter/unless.rb +45 -0
- data/lib/to_source/emitter/util.rb +28 -0
- data/lib/to_source/emitter/when.rb +63 -0
- data/lib/to_source/emitter/yield.rb +28 -0
- data/lib/to_source/emitter/z_super.rb +24 -0
- data/lib/to_source/emitter.rb +278 -0
- data/lib/to_source/state.rb +144 -0
- data/lib/to_source.rb +78 -11
- data/spec/spec_helper.rb +11 -0
- data/spec/unit/to_source/class_methods/run_spec.rb +1254 -0
- data/to_source.gemspec +16 -14
- metadata +160 -20
- data/.rvmrc +0 -1
- data/Readme.md +0 -38
- data/lib/to_source/core_ext/node.rb +0 -22
- data/lib/to_source/version.rb +0 -3
- data/lib/to_source/visitor.rb +0 -377
- data/test/to_source/visitor_test.rb +0 -202
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
# Emitter for rescue condition within rescue nodes
|
|
4
|
+
class RescueCondition < self
|
|
5
|
+
|
|
6
|
+
handle(Rubinius::AST::RescueCondition)
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
# Perform dispatch
|
|
11
|
+
#
|
|
12
|
+
# @return [undefined]
|
|
13
|
+
#
|
|
14
|
+
# @api private
|
|
15
|
+
#
|
|
16
|
+
def dispatch
|
|
17
|
+
emit('rescue')
|
|
18
|
+
emit_conditions
|
|
19
|
+
emit_splat
|
|
20
|
+
emit_assignment
|
|
21
|
+
emit_body
|
|
22
|
+
emit_next
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Emit body
|
|
26
|
+
#
|
|
27
|
+
# @return [undefined]
|
|
28
|
+
#
|
|
29
|
+
# @api private
|
|
30
|
+
#
|
|
31
|
+
def emit_body
|
|
32
|
+
indented do
|
|
33
|
+
visit(node.body)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Emit conditions
|
|
38
|
+
#
|
|
39
|
+
# @return [undefined]
|
|
40
|
+
#
|
|
41
|
+
# @api private
|
|
42
|
+
#
|
|
43
|
+
def emit_conditions
|
|
44
|
+
conditions = node.conditions || return
|
|
45
|
+
body = conditions.body
|
|
46
|
+
|
|
47
|
+
first = body.first
|
|
48
|
+
unless body.one? and first.kind_of?(Rubinius::AST::ConstantAccess) and first.name == :StandardError
|
|
49
|
+
space
|
|
50
|
+
run(Util::DelimitedBody, body)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Emit splat
|
|
55
|
+
#
|
|
56
|
+
# @return [undefined]
|
|
57
|
+
#
|
|
58
|
+
# @api private
|
|
59
|
+
#
|
|
60
|
+
def emit_splat
|
|
61
|
+
util = node
|
|
62
|
+
splat = util.splat || return
|
|
63
|
+
emit(',') if util.conditions
|
|
64
|
+
space
|
|
65
|
+
visit(splat)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Emit assignment
|
|
69
|
+
#
|
|
70
|
+
# @return [undefined]
|
|
71
|
+
#
|
|
72
|
+
# @api private
|
|
73
|
+
#
|
|
74
|
+
def emit_assignment
|
|
75
|
+
assignment = node.assignment || return
|
|
76
|
+
emit(' => ')
|
|
77
|
+
emit(assignment.name)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Emit next
|
|
81
|
+
#
|
|
82
|
+
# @return [undefined]
|
|
83
|
+
#
|
|
84
|
+
# @api private
|
|
85
|
+
#
|
|
86
|
+
def emit_next
|
|
87
|
+
next_rescue = node.next || return
|
|
88
|
+
visit(next_rescue)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
# Emitter for class module or singleton class scopes
|
|
4
|
+
class Scope < self
|
|
5
|
+
|
|
6
|
+
handle(Rubinius::AST::ClassScope)
|
|
7
|
+
handle(Rubinius::AST::ModuleScope)
|
|
8
|
+
handle(Rubinius::AST::SClassScope)
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
# Perform dispatch
|
|
13
|
+
#
|
|
14
|
+
# @return [undefined]
|
|
15
|
+
#
|
|
16
|
+
# @api private
|
|
17
|
+
#
|
|
18
|
+
def dispatch
|
|
19
|
+
visit(node.body)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
# Emitter for class or modue scope names
|
|
4
|
+
class ScopeName < self
|
|
5
|
+
|
|
6
|
+
handle(Rubinius::AST::ClassName)
|
|
7
|
+
handle(Rubinius::AST::ModuleName)
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
# Perform dispatch
|
|
12
|
+
#
|
|
13
|
+
# @return [undefined]
|
|
14
|
+
#
|
|
15
|
+
# @api private
|
|
16
|
+
#
|
|
17
|
+
def dispatch
|
|
18
|
+
emit(node.name)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
# Emitter for scoped cass module or constant names
|
|
4
|
+
class ScopedName < self
|
|
5
|
+
|
|
6
|
+
handle(Rubinius::AST::ScopedClassName)
|
|
7
|
+
handle(Rubinius::AST::ScopedModuleName)
|
|
8
|
+
handle(Rubinius::AST::ScopedConstant)
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
delegate(:parent, :name)
|
|
13
|
+
|
|
14
|
+
# Perform dispatch
|
|
15
|
+
#
|
|
16
|
+
# @return [undefined]
|
|
17
|
+
#
|
|
18
|
+
# @api private
|
|
19
|
+
#
|
|
20
|
+
def dispatch
|
|
21
|
+
visit(parent)
|
|
22
|
+
emit('::')
|
|
23
|
+
emit(name)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
class Send < self
|
|
4
|
+
|
|
5
|
+
handle(Rubinius::AST::Send)
|
|
6
|
+
|
|
7
|
+
UNARY_OPERATORS = %w(
|
|
8
|
+
! ~ -@ +@
|
|
9
|
+
).map(&:to_sym).to_set.freeze
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
delegate(:block, :name, :receiver)
|
|
14
|
+
|
|
15
|
+
# Perform dispatch
|
|
16
|
+
#
|
|
17
|
+
# @return [undefined]
|
|
18
|
+
#
|
|
19
|
+
# @api private
|
|
20
|
+
#
|
|
21
|
+
def dispatch
|
|
22
|
+
if unary_operator_method?
|
|
23
|
+
run(UnaryOperatorMethod, node)
|
|
24
|
+
return
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
normal_dispatch
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Test for unary operator method
|
|
31
|
+
#
|
|
32
|
+
# @return [true]
|
|
33
|
+
# if node is an unary operator method
|
|
34
|
+
#
|
|
35
|
+
# @return [false]
|
|
36
|
+
# otherwise
|
|
37
|
+
#
|
|
38
|
+
# @api private
|
|
39
|
+
#
|
|
40
|
+
def unary_operator_method?
|
|
41
|
+
UNARY_OPERATORS.include?(name)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Perform normal dispatch
|
|
45
|
+
#
|
|
46
|
+
# @return [undefined]
|
|
47
|
+
#
|
|
48
|
+
# @api private
|
|
49
|
+
#
|
|
50
|
+
def normal_dispatch
|
|
51
|
+
emit_receiver
|
|
52
|
+
emit_name
|
|
53
|
+
emit_block_pass
|
|
54
|
+
emit_block
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Test for block
|
|
58
|
+
#
|
|
59
|
+
# @return [true]
|
|
60
|
+
# if block is present
|
|
61
|
+
#
|
|
62
|
+
# @return [false]
|
|
63
|
+
# otherwise
|
|
64
|
+
#
|
|
65
|
+
# @api private
|
|
66
|
+
#
|
|
67
|
+
def block?
|
|
68
|
+
!!block
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Test for block pass
|
|
72
|
+
#
|
|
73
|
+
# @return [true]
|
|
74
|
+
# if block pass is present
|
|
75
|
+
#
|
|
76
|
+
# @return [false]
|
|
77
|
+
# otherwise
|
|
78
|
+
#
|
|
79
|
+
# @api private
|
|
80
|
+
#
|
|
81
|
+
def block_pass?
|
|
82
|
+
block? && block.kind_of?(Rubinius::AST::BlockPass19)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Emit name
|
|
86
|
+
#
|
|
87
|
+
# @return [undefined]
|
|
88
|
+
#
|
|
89
|
+
# @api private
|
|
90
|
+
#
|
|
91
|
+
def emit_name
|
|
92
|
+
emit(name)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Emit receiver
|
|
96
|
+
#
|
|
97
|
+
# @return [undefined]
|
|
98
|
+
#
|
|
99
|
+
# @api private
|
|
100
|
+
#
|
|
101
|
+
def emit_receiver
|
|
102
|
+
return if node.privately
|
|
103
|
+
visit(receiver)
|
|
104
|
+
emit('.')
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Emit block
|
|
108
|
+
#
|
|
109
|
+
# @return [undefined]
|
|
110
|
+
#
|
|
111
|
+
# @api private
|
|
112
|
+
#
|
|
113
|
+
def emit_block
|
|
114
|
+
return unless block? and !block_pass?
|
|
115
|
+
visit(block)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Emit block pass
|
|
119
|
+
#
|
|
120
|
+
# @return [undefined]
|
|
121
|
+
#
|
|
122
|
+
# @api private
|
|
123
|
+
#
|
|
124
|
+
def emit_block_pass
|
|
125
|
+
return unless block_pass?
|
|
126
|
+
emit('(')
|
|
127
|
+
visit(block)
|
|
128
|
+
emit(')')
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
class SendWithArguments < Send
|
|
4
|
+
|
|
5
|
+
handle(Rubinius::AST::SendWithArguments)
|
|
6
|
+
|
|
7
|
+
BINARY_OPERATORS = %w(
|
|
8
|
+
+ - * / & | && || << >> ==
|
|
9
|
+
=== != <= < <=> > >= =~ !~ ^
|
|
10
|
+
**
|
|
11
|
+
).map(&:to_sym).to_set
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
# Perform dispatch
|
|
16
|
+
#
|
|
17
|
+
# @return [undefined]
|
|
18
|
+
#
|
|
19
|
+
# @api private
|
|
20
|
+
#
|
|
21
|
+
def dispatch
|
|
22
|
+
if element_reference?
|
|
23
|
+
run(ElementReference)
|
|
24
|
+
return
|
|
25
|
+
end
|
|
26
|
+
if binary_operator_method?
|
|
27
|
+
run(BinaryOperatorMethod)
|
|
28
|
+
return
|
|
29
|
+
end
|
|
30
|
+
normal_dispatch
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Test for element reference
|
|
34
|
+
#
|
|
35
|
+
# @return [true]
|
|
36
|
+
# if node is an element reference
|
|
37
|
+
#
|
|
38
|
+
# @return [false]
|
|
39
|
+
# otherwise
|
|
40
|
+
#
|
|
41
|
+
# @api private
|
|
42
|
+
#
|
|
43
|
+
def element_reference?
|
|
44
|
+
name == :[]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Test for binary operator method
|
|
48
|
+
#
|
|
49
|
+
# @return [true]
|
|
50
|
+
# if node is a binary operator method
|
|
51
|
+
#
|
|
52
|
+
# @return [false]
|
|
53
|
+
# otherwise
|
|
54
|
+
#
|
|
55
|
+
# @api private
|
|
56
|
+
#
|
|
57
|
+
def binary_operator_method?
|
|
58
|
+
BINARY_OPERATORS.include?(name)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Perform normal dispatch
|
|
62
|
+
#
|
|
63
|
+
# @return [undefined]
|
|
64
|
+
#
|
|
65
|
+
# @api private
|
|
66
|
+
#
|
|
67
|
+
def normal_dispatch
|
|
68
|
+
emit_receiver
|
|
69
|
+
emit_name
|
|
70
|
+
emit_arguments
|
|
71
|
+
emit_block
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Emit arguments
|
|
75
|
+
#
|
|
76
|
+
# @return [undefined]
|
|
77
|
+
#
|
|
78
|
+
# @api private
|
|
79
|
+
#
|
|
80
|
+
def emit_arguments
|
|
81
|
+
emit('(')
|
|
82
|
+
emitter = visit(node.arguments)
|
|
83
|
+
emit_block_pass(emitter)
|
|
84
|
+
emit(')')
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Emit block pass
|
|
88
|
+
#
|
|
89
|
+
# @param [Class:Emitter] emitter
|
|
90
|
+
#
|
|
91
|
+
# @return [undefined]
|
|
92
|
+
#
|
|
93
|
+
# @api private
|
|
94
|
+
#
|
|
95
|
+
def emit_block_pass(emitter)
|
|
96
|
+
return unless block_pass?
|
|
97
|
+
emit(', ') if emitter.any?
|
|
98
|
+
visit(block)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
# Emitter for singleton class nodes
|
|
4
|
+
class SingletonClass < self
|
|
5
|
+
|
|
6
|
+
handle(Rubinius::AST::SClass)
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
# Perform dispatch
|
|
11
|
+
#
|
|
12
|
+
# @return [undefined]
|
|
13
|
+
#
|
|
14
|
+
# @api private
|
|
15
|
+
#
|
|
16
|
+
def dispatch
|
|
17
|
+
emit('class << ')
|
|
18
|
+
visit(node.receiver)
|
|
19
|
+
emit_body
|
|
20
|
+
emit_end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Emit body
|
|
24
|
+
#
|
|
25
|
+
# @return [undefined]
|
|
26
|
+
#
|
|
27
|
+
# @api private
|
|
28
|
+
#
|
|
29
|
+
def emit_body
|
|
30
|
+
indented do
|
|
31
|
+
# FIXME: attr_reader missing on Rubinius::AST::SClass
|
|
32
|
+
visit(node.instance_variable_get(:@body))
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
# Emitter for splat nodes
|
|
4
|
+
class Splat < self
|
|
5
|
+
|
|
6
|
+
handle(Rubinius::AST::SplatValue)
|
|
7
|
+
handle(Rubinius::AST::RescueSplat)
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
# Perform dispatch
|
|
12
|
+
#
|
|
13
|
+
# @return [undefined]
|
|
14
|
+
#
|
|
15
|
+
# @api private
|
|
16
|
+
#
|
|
17
|
+
def dispatch
|
|
18
|
+
emit('*')
|
|
19
|
+
visit(node.value)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
# Emitter for spat when nodes
|
|
4
|
+
class SplatWhen < self
|
|
5
|
+
|
|
6
|
+
handle(Rubinius::AST::SplatWhen)
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
# Perform dispatch
|
|
11
|
+
#
|
|
12
|
+
# @return [undefined]
|
|
13
|
+
#
|
|
14
|
+
# @api private
|
|
15
|
+
#
|
|
16
|
+
def dispatch
|
|
17
|
+
emit('*')
|
|
18
|
+
visit(node.condition)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
# Base class for emitters with static content
|
|
4
|
+
class Static < self
|
|
5
|
+
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
# Perform dispatch
|
|
9
|
+
#
|
|
10
|
+
# @return [undefined]
|
|
11
|
+
#
|
|
12
|
+
# @api private
|
|
13
|
+
#
|
|
14
|
+
def dispatch
|
|
15
|
+
emit(self.class::SYMBOL)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Emitter for next nodes
|
|
19
|
+
class Next < self
|
|
20
|
+
|
|
21
|
+
handle(Rubinius::AST::Next)
|
|
22
|
+
SYMBOL = :next
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Emitter for current exception node
|
|
27
|
+
class CurrentException < self
|
|
28
|
+
|
|
29
|
+
handle(Rubinius::AST::CurrentException)
|
|
30
|
+
SYMBOL = :'$!'
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Emitter for self node
|
|
35
|
+
class Self < self
|
|
36
|
+
|
|
37
|
+
handle(Rubinius::AST::Self)
|
|
38
|
+
SYMBOL = :self
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Emitter for file node
|
|
43
|
+
class File < self
|
|
44
|
+
|
|
45
|
+
handle(Rubinius::AST::File)
|
|
46
|
+
SYMBOL = :__FILE__
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
# emitter for super node
|
|
4
|
+
class Super < self
|
|
5
|
+
|
|
6
|
+
handle(Rubinius::AST::Super)
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
delegate(:block)
|
|
11
|
+
|
|
12
|
+
# Perform dispatch
|
|
13
|
+
#
|
|
14
|
+
# @return [undefined]
|
|
15
|
+
#
|
|
16
|
+
# @api private
|
|
17
|
+
#
|
|
18
|
+
def dispatch
|
|
19
|
+
emit('super')
|
|
20
|
+
emit_arguments
|
|
21
|
+
emit_block
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Emit arguments
|
|
25
|
+
#
|
|
26
|
+
# @return [undefined]
|
|
27
|
+
#
|
|
28
|
+
# @api private
|
|
29
|
+
#
|
|
30
|
+
def emit_arguments
|
|
31
|
+
emit('(')
|
|
32
|
+
emitter = visit(node.arguments)
|
|
33
|
+
emit_block_pass(emitter)
|
|
34
|
+
emit(')')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Test for block presence
|
|
38
|
+
#
|
|
39
|
+
# @return [true]
|
|
40
|
+
# if block is present
|
|
41
|
+
#
|
|
42
|
+
# @return [false]
|
|
43
|
+
# otherwise
|
|
44
|
+
#
|
|
45
|
+
# @api private
|
|
46
|
+
#
|
|
47
|
+
def block?
|
|
48
|
+
!!block
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Test for block pass
|
|
52
|
+
#
|
|
53
|
+
# @return [true]
|
|
54
|
+
# if block pass is present
|
|
55
|
+
#
|
|
56
|
+
# @return [false]
|
|
57
|
+
# otherwise
|
|
58
|
+
#
|
|
59
|
+
# @api private
|
|
60
|
+
#
|
|
61
|
+
def block_pass?
|
|
62
|
+
block.kind_of?(Rubinius::AST::BlockPass19)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Emit block pass
|
|
66
|
+
#
|
|
67
|
+
# @param [Class:Emitter] emitter
|
|
68
|
+
#
|
|
69
|
+
# @return [undefined]
|
|
70
|
+
#
|
|
71
|
+
# @api private
|
|
72
|
+
#
|
|
73
|
+
def emit_block_pass(emitter)
|
|
74
|
+
return unless block? and block_pass?
|
|
75
|
+
emit(', ') if emitter.any?
|
|
76
|
+
visit(block)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Emit block
|
|
80
|
+
#
|
|
81
|
+
# @return [undefined]
|
|
82
|
+
#
|
|
83
|
+
# @api private
|
|
84
|
+
#
|
|
85
|
+
def emit_block
|
|
86
|
+
return unless block? and !block_pass?
|
|
87
|
+
visit(block)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
# Emit to array node
|
|
4
|
+
class ToArray < self
|
|
5
|
+
|
|
6
|
+
handle(Rubinius::AST::ToArray)
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
# Perform dispatch
|
|
11
|
+
#
|
|
12
|
+
# @return [undefined]
|
|
13
|
+
#
|
|
14
|
+
# @api private
|
|
15
|
+
#
|
|
16
|
+
def dispatch
|
|
17
|
+
visit(node.value)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
# Emit to string node
|
|
4
|
+
class ToString < self
|
|
5
|
+
|
|
6
|
+
handle(Rubinius::AST::ToString)
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
# Perform dispatch
|
|
11
|
+
#
|
|
12
|
+
# @return [undefined]
|
|
13
|
+
#
|
|
14
|
+
# @api private
|
|
15
|
+
#
|
|
16
|
+
def dispatch
|
|
17
|
+
emit('#{')
|
|
18
|
+
visit(node.value)
|
|
19
|
+
emit('}')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module ToSource
|
|
2
|
+
class Emitter
|
|
3
|
+
# Emitter for toplevel constants or classes
|
|
4
|
+
class Toplevel < self
|
|
5
|
+
|
|
6
|
+
handle(Rubinius::AST::ToplevelClassName)
|
|
7
|
+
handle(Rubinius::AST::ToplevelConstant)
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
# Perform dispatch
|
|
12
|
+
#
|
|
13
|
+
# @return [undefined]
|
|
14
|
+
#
|
|
15
|
+
# @api private
|
|
16
|
+
#
|
|
17
|
+
def dispatch
|
|
18
|
+
emit('::')
|
|
19
|
+
emit(node.name)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|