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.
Files changed (89) hide show
  1. data/.gitignore +6 -6
  2. data/.rspec +1 -0
  3. data/.travis.yml +12 -1
  4. data/Changelog.md +115 -0
  5. data/Gemfile +5 -3
  6. data/Gemfile.devtools +67 -0
  7. data/Guardfile +18 -0
  8. data/LICENSE +21 -0
  9. data/README.md +52 -0
  10. data/Rakefile +3 -8
  11. data/TODO +9 -0
  12. data/bin/to_source +17 -0
  13. data/config/flay.yml +3 -0
  14. data/config/flog.yml +2 -0
  15. data/config/roodi.yml +26 -0
  16. data/config/site.reek +97 -0
  17. data/config/yardstick.yml +2 -0
  18. data/lib/to_source/command.rb +106 -0
  19. data/lib/to_source/emitter/access.rb +28 -0
  20. data/lib/to_source/emitter/actual_arguments.rb +89 -0
  21. data/lib/to_source/emitter/alias.rb +27 -0
  22. data/lib/to_source/emitter/assignment.rb +119 -0
  23. data/lib/to_source/emitter/attribute_assignment.rb +28 -0
  24. data/lib/to_source/emitter/begin.rb +71 -0
  25. data/lib/to_source/emitter/binary_operator.rb +63 -0
  26. data/lib/to_source/emitter/binary_operator_method.rb +58 -0
  27. data/lib/to_source/emitter/block.rb +29 -0
  28. data/lib/to_source/emitter/block_argument.rb +23 -0
  29. data/lib/to_source/emitter/block_pass.rb +23 -0
  30. data/lib/to_source/emitter/case.rb +85 -0
  31. data/lib/to_source/emitter/class.rb +44 -0
  32. data/lib/to_source/emitter/concat_arguments.rb +28 -0
  33. data/lib/to_source/emitter/default_arguments.rb +22 -0
  34. data/lib/to_source/emitter/define.rb +99 -0
  35. data/lib/to_source/emitter/defined.rb +24 -0
  36. data/lib/to_source/emitter/element_assignment.rb +29 -0
  37. data/lib/to_source/emitter/element_reference.rb +25 -0
  38. data/lib/to_source/emitter/empty_body.rb +21 -0
  39. data/lib/to_source/emitter/ensure.rb +50 -0
  40. data/lib/to_source/emitter/ensure_body.rb +27 -0
  41. data/lib/to_source/emitter/execute_string.rb +22 -0
  42. data/lib/to_source/emitter/formal_arguments.rb +212 -0
  43. data/lib/to_source/emitter/if.rb +96 -0
  44. data/lib/to_source/emitter/iter.rb +27 -0
  45. data/lib/to_source/emitter/keyword_value.rb +67 -0
  46. data/lib/to_source/emitter/literal/dynamic.rb +178 -0
  47. data/lib/to_source/emitter/literal.rb +232 -0
  48. data/lib/to_source/emitter/loop.rb +40 -0
  49. data/lib/to_source/emitter/match3.rb +25 -0
  50. data/lib/to_source/emitter/module.rb +28 -0
  51. data/lib/to_source/emitter/multiple_assignment.rb +49 -0
  52. data/lib/to_source/emitter/nth_ref.rb +22 -0
  53. data/lib/to_source/emitter/op_assign1.rb +27 -0
  54. data/lib/to_source/emitter/op_assign2.rb +27 -0
  55. data/lib/to_source/emitter/pattern_arguments.rb +24 -0
  56. data/lib/to_source/emitter/rescue.rb +28 -0
  57. data/lib/to_source/emitter/rescue_condition.rb +93 -0
  58. data/lib/to_source/emitter/scope.rb +24 -0
  59. data/lib/to_source/emitter/scope_name.rb +23 -0
  60. data/lib/to_source/emitter/scoped_name.rb +28 -0
  61. data/lib/to_source/emitter/send.rb +133 -0
  62. data/lib/to_source/emitter/send_with_arguments.rb +103 -0
  63. data/lib/to_source/emitter/singleton_class.rb +38 -0
  64. data/lib/to_source/emitter/splat.rb +24 -0
  65. data/lib/to_source/emitter/splat_when.rb +23 -0
  66. data/lib/to_source/emitter/static.rb +52 -0
  67. data/lib/to_source/emitter/super.rb +92 -0
  68. data/lib/to_source/emitter/to_array.rb +22 -0
  69. data/lib/to_source/emitter/to_string.rb +24 -0
  70. data/lib/to_source/emitter/toplevel.rb +24 -0
  71. data/lib/to_source/emitter/unary_operator_method.rb +27 -0
  72. data/lib/to_source/emitter/unless.rb +45 -0
  73. data/lib/to_source/emitter/util.rb +28 -0
  74. data/lib/to_source/emitter/when.rb +63 -0
  75. data/lib/to_source/emitter/yield.rb +28 -0
  76. data/lib/to_source/emitter/z_super.rb +24 -0
  77. data/lib/to_source/emitter.rb +278 -0
  78. data/lib/to_source/state.rb +144 -0
  79. data/lib/to_source.rb +78 -11
  80. data/spec/spec_helper.rb +11 -0
  81. data/spec/unit/to_source/class_methods/run_spec.rb +1254 -0
  82. data/to_source.gemspec +16 -14
  83. metadata +160 -20
  84. data/.rvmrc +0 -1
  85. data/Readme.md +0 -38
  86. data/lib/to_source/core_ext/node.rb +0 -22
  87. data/lib/to_source/version.rb +0 -3
  88. data/lib/to_source/visitor.rb +0 -377
  89. data/test/to_source/visitor_test.rb +0 -202
data/to_source.gemspec CHANGED
@@ -1,18 +1,20 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "to_source/version"
4
-
5
2
  Gem::Specification.new do |s|
6
- s.name = "to_source"
7
- s.version = ToSource::VERSION
8
- s.authors = ["Josep M. Bach"]
9
- s.email = ["josep.m.bach@gmail.com"]
10
- s.homepage = "http://github.com/txus/to_source"
11
- s.summary = %q{Transform your Rubinius AST nodes back to source code. Reverse parsing!}
12
- s.description = %q{Transform your Rubinius AST nodes back to source code. Reverse parsing!}
3
+ s.name = 'to_source'
4
+ s.version = '0.2.16'
5
+ s.authors = ['Markus Schirp']
6
+ s.email = ['mbj@seonic.net']
7
+ s.homepage = 'http://github.com/mbj/to_source'
8
+ s.summary = %q{Transform Rubinius 1.9 AST back to equvalent source code.}
9
+ s.description = s.summary
10
+ s.files = `git ls-files`.split("\n")
11
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
12
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ s.extra_rdoc_files = %w[LICENSE README.md TODO]
14
+ s.require_paths = ['lib']
13
15
 
14
- s.files = `git ls-files`.split("\n")
15
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
- s.require_paths = ["lib"]
16
+ s.add_dependency('adamantium', '~> 0.0.5')
17
+ s.add_dependency('equalizer', '~> 0.0.3')
18
+ s.add_dependency('abstract_type', '~> 0.0.2')
19
+ s.add_dependency('mutant-melbourne', '~> 2.0.3')
18
20
  end
metadata CHANGED
@@ -1,58 +1,198 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_source
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Josep M. Bach
8
+ - Markus Schirp
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-12 00:00:00.000000000 Z
13
- dependencies: []
14
- description: Transform your Rubinius AST nodes back to source code. Reverse parsing!
12
+ date: 2013-01-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: adamantium
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.5
30
+ - !ruby/object:Gem::Dependency
31
+ name: equalizer
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.0.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.0.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: abstract_type
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: mutant-melbourne
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.0.3
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.0.3
78
+ description: Transform Rubinius 1.9 AST back to equvalent source code.
15
79
  email:
16
- - josep.m.bach@gmail.com
17
- executables: []
80
+ - mbj@seonic.net
81
+ executables:
82
+ - to_source
18
83
  extensions: []
19
- extra_rdoc_files: []
84
+ extra_rdoc_files:
85
+ - LICENSE
86
+ - README.md
87
+ - TODO
20
88
  files:
21
89
  - .gitignore
22
- - .rvmrc
90
+ - .rspec
23
91
  - .travis.yml
92
+ - Changelog.md
24
93
  - Gemfile
94
+ - Gemfile.devtools
95
+ - Guardfile
96
+ - LICENSE
97
+ - README.md
25
98
  - Rakefile
26
- - Readme.md
99
+ - TODO
100
+ - bin/to_source
101
+ - config/flay.yml
102
+ - config/flog.yml
103
+ - config/roodi.yml
104
+ - config/site.reek
105
+ - config/yardstick.yml
27
106
  - lib/to_source.rb
28
- - lib/to_source/core_ext/node.rb
29
- - lib/to_source/version.rb
30
- - lib/to_source/visitor.rb
31
- - test/to_source/visitor_test.rb
107
+ - lib/to_source/command.rb
108
+ - lib/to_source/emitter.rb
109
+ - lib/to_source/emitter/access.rb
110
+ - lib/to_source/emitter/actual_arguments.rb
111
+ - lib/to_source/emitter/alias.rb
112
+ - lib/to_source/emitter/assignment.rb
113
+ - lib/to_source/emitter/attribute_assignment.rb
114
+ - lib/to_source/emitter/begin.rb
115
+ - lib/to_source/emitter/binary_operator.rb
116
+ - lib/to_source/emitter/binary_operator_method.rb
117
+ - lib/to_source/emitter/block.rb
118
+ - lib/to_source/emitter/block_argument.rb
119
+ - lib/to_source/emitter/block_pass.rb
120
+ - lib/to_source/emitter/case.rb
121
+ - lib/to_source/emitter/class.rb
122
+ - lib/to_source/emitter/concat_arguments.rb
123
+ - lib/to_source/emitter/default_arguments.rb
124
+ - lib/to_source/emitter/define.rb
125
+ - lib/to_source/emitter/defined.rb
126
+ - lib/to_source/emitter/element_assignment.rb
127
+ - lib/to_source/emitter/element_reference.rb
128
+ - lib/to_source/emitter/empty_body.rb
129
+ - lib/to_source/emitter/ensure.rb
130
+ - lib/to_source/emitter/ensure_body.rb
131
+ - lib/to_source/emitter/execute_string.rb
132
+ - lib/to_source/emitter/formal_arguments.rb
133
+ - lib/to_source/emitter/if.rb
134
+ - lib/to_source/emitter/iter.rb
135
+ - lib/to_source/emitter/keyword_value.rb
136
+ - lib/to_source/emitter/literal.rb
137
+ - lib/to_source/emitter/literal/dynamic.rb
138
+ - lib/to_source/emitter/loop.rb
139
+ - lib/to_source/emitter/match3.rb
140
+ - lib/to_source/emitter/module.rb
141
+ - lib/to_source/emitter/multiple_assignment.rb
142
+ - lib/to_source/emitter/nth_ref.rb
143
+ - lib/to_source/emitter/op_assign1.rb
144
+ - lib/to_source/emitter/op_assign2.rb
145
+ - lib/to_source/emitter/pattern_arguments.rb
146
+ - lib/to_source/emitter/rescue.rb
147
+ - lib/to_source/emitter/rescue_condition.rb
148
+ - lib/to_source/emitter/scope.rb
149
+ - lib/to_source/emitter/scope_name.rb
150
+ - lib/to_source/emitter/scoped_name.rb
151
+ - lib/to_source/emitter/send.rb
152
+ - lib/to_source/emitter/send_with_arguments.rb
153
+ - lib/to_source/emitter/singleton_class.rb
154
+ - lib/to_source/emitter/splat.rb
155
+ - lib/to_source/emitter/splat_when.rb
156
+ - lib/to_source/emitter/static.rb
157
+ - lib/to_source/emitter/super.rb
158
+ - lib/to_source/emitter/to_array.rb
159
+ - lib/to_source/emitter/to_string.rb
160
+ - lib/to_source/emitter/toplevel.rb
161
+ - lib/to_source/emitter/unary_operator_method.rb
162
+ - lib/to_source/emitter/unless.rb
163
+ - lib/to_source/emitter/util.rb
164
+ - lib/to_source/emitter/when.rb
165
+ - lib/to_source/emitter/yield.rb
166
+ - lib/to_source/emitter/z_super.rb
167
+ - lib/to_source/state.rb
168
+ - spec/spec_helper.rb
169
+ - spec/unit/to_source/class_methods/run_spec.rb
32
170
  - to_source.gemspec
33
- homepage: http://github.com/txus/to_source
171
+ homepage: http://github.com/mbj/to_source
34
172
  licenses: []
35
173
  post_install_message:
36
174
  rdoc_options: []
37
175
  require_paths:
38
176
  - lib
39
177
  required_ruby_version: !ruby/object:Gem::Requirement
178
+ none: false
40
179
  requirements:
41
180
  - - ! '>='
42
181
  - !ruby/object:Gem::Version
43
182
  version: '0'
44
- none: false
45
183
  required_rubygems_version: !ruby/object:Gem::Requirement
184
+ none: false
46
185
  requirements:
47
186
  - - ! '>='
48
187
  - !ruby/object:Gem::Version
49
188
  version: '0'
50
- none: false
51
189
  requirements: []
52
190
  rubyforge_project:
53
- rubygems_version: 1.8.12
191
+ rubygems_version: 1.8.23
54
192
  signing_key:
55
193
  specification_version: 3
56
- summary: Transform your Rubinius AST nodes back to source code. Reverse parsing!
194
+ summary: Transform Rubinius 1.9 AST back to equvalent source code.
57
195
  test_files:
58
- - test/to_source/visitor_test.rb
196
+ - spec/spec_helper.rb
197
+ - spec/unit/to_source/class_methods/run_spec.rb
198
+ has_rdoc:
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use rbx-head@to_source --create
data/Readme.md DELETED
@@ -1,38 +0,0 @@
1
- # to_source [![Build Status](https://secure.travis-ci.org/txus/to_source.png)](http://travis-ci.org/txus/to_source)
2
-
3
- to_source is a little Rubinius gem that enables Abstract Syntax Tree nodes to
4
- transform themselves into source code. It's the reverse of Rubinius' builtin
5
- `#to_ast` method. See for yourself:
6
-
7
- #!/bin/rbx
8
- some_code = "a = 123"
9
- ast = some_code.to_ast
10
- # => #<Rubinius::AST::LocalVariableAssignment:0x21b8
11
- @value=#<Rubinius::AST::FixnumLiteral:0x21bc @value=123 @line=1>
12
- @variable=nil @line=1 @name=:a>
13
-
14
- ast.to_source
15
- # => "a = 123"
16
-
17
- ## Installing
18
-
19
- to_source needs Rubinius 2.0 to run, in either 1.8 or 1.9 mode.
20
-
21
- To install it as a gem:
22
-
23
- $ gem install to_source
24
-
25
- And `require 'to_source'` from your code. Automatically, your AST nodes respond
26
- to the `#to_source` method.
27
-
28
- But if you're using Bundler, just put this in your Gemfile:
29
-
30
- gem 'to_source'
31
-
32
- And just call `#to_source` in any AST node!
33
-
34
- ## Who's this
35
-
36
- This was made by [Josep M. Bach (Txus)](http://txustice.me) under the MIT
37
- license. I'm [@txustice](http://twitter.com/txustice) on twitter (where you
38
- should probably follow me!).
@@ -1,22 +0,0 @@
1
- module Rubinius
2
- module AST
3
- class Node
4
- # Public: Works like #visit, but it doesn't visit the children just yet;
5
- # instead, lets the visitor decide when and how to do it.
6
- #
7
- # visitor - The visitor object. It must respond to methods named after the
8
- # node names.
9
- #
10
- # Returns nothing.
11
- def lazy_visit(visitor, parent=nil, indent=false)
12
- name = node_name
13
- name = "#{name}_def" if %w[ class module ].include?(name)
14
-
15
- args = [name, self, parent]
16
- args << true if indent
17
-
18
- visitor.__send__ *args
19
- end
20
- end
21
- end
22
- end
@@ -1,3 +0,0 @@
1
- module ToSource
2
- VERSION = "0.1.3"
3
- end
@@ -1,377 +0,0 @@
1
- module ToSource
2
- class Visitor
3
- def initialize
4
- @output = []
5
- @indentation = 0
6
- end
7
-
8
- def emit(code)
9
- @output.push code
10
- end
11
-
12
- def output
13
- @output.join
14
- end
15
-
16
- def current_indentation
17
- ' ' * @indentation
18
- end
19
-
20
- def class_def(node, parent)
21
- emit "class %s" % node.name.name
22
-
23
- superclass = node.superclass
24
- unless superclass.is_a?(Rubinius::AST::NilLiteral)
25
- emit " < %s" % superclass.name
26
- end
27
-
28
- node.body.lazy_visit self, node, true
29
-
30
- emit "\n"
31
- emit "end"
32
- end
33
-
34
- def module_def(node, parent)
35
- emit "module %s" % node.name.name
36
-
37
- node.body.lazy_visit self, node, true
38
-
39
- emit "\n"
40
- emit "end"
41
- end
42
-
43
- def empty_body(*)
44
- # do nothing
45
- end
46
-
47
- def class_scope(node, parent, indent)
48
- emit "\n"
49
- @indentation += 1 if indent
50
- node.body.lazy_visit self, node, indent
51
- ensure
52
- @indentation -= 1 if indent
53
- end
54
- alias module_scope class_scope
55
-
56
- def local_variable_assignment(node, parent)
57
- emit "%s = " % node.name
58
- node.value.lazy_visit self, node
59
- end
60
-
61
- def local_variable_access(node, parent)
62
- emit node.name
63
- end
64
-
65
- def instance_variable_assignment(node, parent)
66
- emit "%s = " % node.name
67
- node.value.lazy_visit self, node
68
- end
69
-
70
- def instance_variable_access(node, parent)
71
- emit node.name
72
- end
73
-
74
- def fixnum_literal(node, parent)
75
- emit node.value.to_s
76
- end
77
-
78
- def float_literal(node, parent)
79
- emit node.value.to_s
80
- end
81
-
82
- def string_literal(node, parent)
83
- emit '"' << node.string.to_s << '"'
84
- end
85
-
86
- def symbol_literal(node, parent)
87
- emit ':' << node.value.to_s
88
- end
89
-
90
- def true_literal(node, parent)
91
- emit 'true'
92
- end
93
-
94
- def false_literal(node, parent)
95
- emit 'false'
96
- end
97
-
98
- def nil_literal(node, parent)
99
- emit 'nil'
100
- end
101
-
102
- def array_literal(node, parent)
103
- body = node.body
104
-
105
- emit '['
106
- body.each_with_index do |node, index|
107
- node.lazy_visit self, node
108
- emit ', ' unless body.length == index + 1 # last element
109
- end
110
- emit ']'
111
- end
112
-
113
- def hash_literal(node, parent)
114
- body = node.array.each_slice(2)
115
-
116
- emit '{'
117
- body.each_with_index do |slice, index|
118
- key, value = slice
119
-
120
- key.lazy_visit self, node
121
- emit " => "
122
- value.lazy_visit self, node
123
-
124
- emit ', ' unless body.to_a.length == index + 1 # last element
125
- end
126
- emit '}'
127
- end
128
-
129
- def range(node, parent)
130
- node.start.lazy_visit self, node
131
- emit '..'
132
- node.finish.lazy_visit self, node
133
- end
134
-
135
- def range_exclude(node, parent)
136
- node.start.lazy_visit self, node
137
- emit '...'
138
- node.finish.lazy_visit self, node
139
- end
140
-
141
- def regex_literal(node, parent)
142
- emit '/'
143
- emit node.source
144
- emit '/'
145
- end
146
-
147
- def send(node, parent)
148
- unless node.receiver.is_a?(Rubinius::AST::Self)
149
- node.receiver.lazy_visit self, node
150
- emit '.'
151
- end
152
- emit node.name
153
-
154
- if node.block
155
- emit ' '
156
- node.block.lazy_visit self, node if node.block
157
- end
158
- end
159
-
160
- def send_with_arguments(node, parent)
161
- return if process_binary_operator(node, parent) # 1 * 2, a / 3, true && false
162
-
163
- unless node.receiver.is_a?(Rubinius::AST::Self)
164
- node.receiver.lazy_visit self, node
165
- emit '.'
166
- end
167
-
168
- emit node.name
169
- emit '('
170
- node.arguments.lazy_visit self, node
171
- emit ')'
172
- if node.block
173
- emit ' '
174
- node.block.lazy_visit self, node if node.block
175
- end
176
- end
177
-
178
- def actual_arguments(node, parent)
179
- body = node.array
180
- body.each_with_index do |argument, index|
181
- argument.lazy_visit self, parent
182
- emit ', ' unless body.length == index + 1 # last element
183
- end
184
- end
185
-
186
- def iter_arguments(node, parent)
187
- body = if node.prelude == :single
188
- Array(node.arguments.name)
189
- else
190
- node.arguments.left.body.map(&:name)
191
- end
192
-
193
- emit '|'
194
- body.each_with_index do |argument, index|
195
- emit argument.to_s
196
- emit ', ' unless body.length == index + 1 # last element
197
- end
198
- emit '|'
199
- end
200
-
201
- def iter(node, parent)
202
- emit 'do'
203
-
204
- if node.arguments && node.arguments.arity != -1
205
- emit ' '
206
- node.arguments.lazy_visit self, parent
207
- end
208
-
209
- emit "\n"
210
- @indentation += 1
211
-
212
- if node.body.is_a?(Rubinius::AST::Block)
213
- node.body.lazy_visit self, parent, true
214
- else
215
- emit current_indentation
216
- node.body.lazy_visit self, parent
217
- end
218
-
219
- emit "\n"
220
- emit 'end'
221
- end
222
-
223
- def block(node, parent, indent=false)
224
- body = node.array
225
- body.each_with_index do |expression, index|
226
- emit current_indentation if indent
227
- expression.lazy_visit self, parent
228
- emit "\n" unless body.length == index + 1 # last element
229
- end
230
- end
231
-
232
- def not(node, parent)
233
- emit '!'
234
- node.value.lazy_visit self, parent
235
- end
236
-
237
- def and(node, parent)
238
- node.left.lazy_visit self, node
239
- emit ' && '
240
- node.right.lazy_visit self, node
241
- end
242
-
243
- def or(node, parent)
244
- node.left.lazy_visit self, node
245
- emit ' || '
246
- node.right.lazy_visit self, node
247
- end
248
-
249
- def op_assign_and(node, parent)
250
- node.left.lazy_visit self, node
251
- emit ' && '
252
- node.right.lazy_visit self, node
253
- end
254
-
255
- def op_assign_or(node, parent)
256
- node.left.lazy_visit self, node
257
- emit ' || '
258
- node.right.lazy_visit self, node
259
- end
260
-
261
- def toplevel_constant(node, parent)
262
- emit "::"
263
- emit node.name
264
- end
265
-
266
- def constant_access(node, parent)
267
- emit node.name
268
- end
269
-
270
- def scoped_constant(node, parent)
271
- node.parent.lazy_visit self, node
272
- emit '::'
273
- emit node.name
274
- end
275
-
276
- def if(node, parent)
277
- body, else_body = node.body, node.else
278
- keyword = 'if'
279
-
280
- if node.body.is_a?(Rubinius::AST::NilLiteral) && !node.else.is_a?(Rubinius::AST::NilLiteral)
281
-
282
- body, else_body = else_body, body
283
- keyword = 'unless'
284
- end
285
-
286
- emit keyword << ' '
287
- node.condition.lazy_visit self, node
288
- emit "\n"
289
-
290
- @indentation += 1
291
-
292
- if body.is_a?(Rubinius::AST::Block)
293
- body.lazy_visit self, parent, true
294
- else
295
- emit current_indentation
296
- body.lazy_visit self, parent
297
- end
298
-
299
- emit "\n"
300
-
301
- if else_body.is_a?(Rubinius::AST::NilLiteral)
302
- emit 'end'
303
- return
304
- end
305
-
306
- emit "else\n"
307
-
308
- if else_body.is_a?(Rubinius::AST::Block)
309
- else_body.lazy_visit self, parent, true
310
- else
311
- emit current_indentation
312
- else_body.lazy_visit self, parent
313
- end
314
-
315
- emit "\n"
316
- emit 'end'
317
- end
318
-
319
- def while(node, parent)
320
- emit 'while '
321
- node.condition.lazy_visit self, node
322
- emit "\n"
323
-
324
- @indentation += 1
325
-
326
- if node.body.is_a?(Rubinius::AST::Block)
327
- node.body.lazy_visit self, parent, true
328
- else
329
- emit current_indentation
330
- node.body.lazy_visit self, parent
331
- end
332
-
333
- emit "\n"
334
- emit "end"
335
- end
336
-
337
- def until(node, parent)
338
- emit 'until '
339
- node.condition.lazy_visit self, node
340
- emit "\n"
341
-
342
- @indentation += 1
343
-
344
- if node.body.is_a?(Rubinius::AST::Block)
345
- node.body.lazy_visit self, parent, true
346
- else
347
- emit current_indentation
348
- node.body.lazy_visit self, parent
349
- end
350
-
351
- emit "\n"
352
- emit "end"
353
- end
354
-
355
- def return(node, parent)
356
- emit 'return '
357
- node.value.lazy_visit self, parent
358
- end
359
-
360
- private
361
-
362
- def process_binary_operator(node, parent)
363
- operators = %w(+ - * / & | <<).map(&:to_sym)
364
- return false unless operators.include?(node.name)
365
- return false if node.arguments.array.length != 1
366
-
367
- operand = node.arguments.array[0]
368
-
369
- unless node.receiver.is_a?(Rubinius::AST::Self)
370
- node.receiver.lazy_visit self, node
371
- end
372
-
373
- emit ' ' << node.name.to_s << ' '
374
- operand.lazy_visit self, node
375
- end
376
- end
377
- end