to_source 0.1.3 → 0.2.0

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/to_source.gemspec CHANGED
@@ -1,18 +1,22 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "to_source/version"
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ require 'to_source/version'
4
5
 
5
6
  Gem::Specification.new do |s|
6
- s.name = "to_source"
7
+ s.name = 'to_source'
7
8
  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"
9
+ s.authors = ['Josep M. Bach', 'Markus Schirp']
10
+ s.email = ['josep.m.bach@gmail.com', 'mbj@seonic.net']
11
+ s.homepage = 'http://github.com/txus/to_source'
11
12
  s.summary = %q{Transform your Rubinius AST nodes back to source code. Reverse parsing!}
12
13
  s.description = %q{Transform your Rubinius AST nodes back to source code. Reverse parsing!}
13
14
 
14
15
  s.files = `git ls-files`.split("\n")
15
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
- s.require_paths = ["lib"]
18
+ s.require_paths = ['lib']
19
+
20
+ s.add_dependency('adamantium', '~> 0.0.3')
21
+ s.add_dependency('mutant-melbourne', '~> 2.0.1')
18
22
  end
metadata CHANGED
@@ -1,34 +1,79 @@
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.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Josep M. Bach
9
+ - Markus Schirp
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-04-12 00:00:00.000000000 Z
13
- dependencies: []
13
+ date: 2012-12-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: adamantium
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 0.0.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 0.0.3
31
+ - !ruby/object:Gem::Dependency
32
+ name: mutant-melbourne
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 2.0.1
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.1
14
47
  description: Transform your Rubinius AST nodes back to source code. Reverse parsing!
15
48
  email:
16
49
  - josep.m.bach@gmail.com
17
- executables: []
50
+ - mbj@seonic.net
51
+ executables:
52
+ - to_source
18
53
  extensions: []
19
54
  extra_rdoc_files: []
20
55
  files:
21
56
  - .gitignore
22
- - .rvmrc
57
+ - .rspec
23
58
  - .travis.yml
59
+ - Changelog.md
24
60
  - Gemfile
61
+ - Gemfile.devtools
62
+ - Guardfile
63
+ - README.md
25
64
  - Rakefile
26
- - Readme.md
65
+ - TODO
66
+ - bin/to_source
67
+ - config/flay.yml
68
+ - config/flog.yml
69
+ - config/roodi.yml
70
+ - config/site.reek
71
+ - config/yardstick.yml
27
72
  - lib/to_source.rb
28
- - lib/to_source/core_ext/node.rb
29
73
  - lib/to_source/version.rb
30
74
  - lib/to_source/visitor.rb
31
- - test/to_source/visitor_test.rb
75
+ - spec/spec_helper.rb
76
+ - spec/unit/to_source/visitor/class_methods/run_spec.rb
32
77
  - to_source.gemspec
33
78
  homepage: http://github.com/txus/to_source
34
79
  licenses: []
@@ -37,22 +82,24 @@ rdoc_options: []
37
82
  require_paths:
38
83
  - lib
39
84
  required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
40
86
  requirements:
41
87
  - - ! '>='
42
88
  - !ruby/object:Gem::Version
43
89
  version: '0'
44
- none: false
45
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
46
92
  requirements:
47
93
  - - ! '>='
48
94
  - !ruby/object:Gem::Version
49
95
  version: '0'
50
- none: false
51
96
  requirements: []
52
97
  rubyforge_project:
53
- rubygems_version: 1.8.12
98
+ rubygems_version: 1.8.24
54
99
  signing_key:
55
100
  specification_version: 3
56
101
  summary: Transform your Rubinius AST nodes back to source code. Reverse parsing!
57
102
  test_files:
58
- - test/to_source/visitor_test.rb
103
+ - spec/spec_helper.rb
104
+ - spec/unit/to_source/visitor/class_methods/run_spec.rb
105
+ 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,202 +0,0 @@
1
- require 'test/unit'
2
- require 'to_source'
3
-
4
- module ToSource
5
- class VisitorTest < Test::Unit::TestCase
6
- def visit(code)
7
- code.to_ast.to_source
8
- end
9
-
10
- def assert_source(code)
11
- assert_equal code, visit(code)
12
- end
13
-
14
- def assert_converts(expected, code)
15
- assert_equal expected, visit(code)
16
- end
17
-
18
- def test_class
19
- assert_source "class TestClass\nend"
20
- end
21
-
22
- def test_class_with_superclass
23
- assert_source "class TestClass < Object\nend"
24
- end
25
-
26
- def test_class_with_body
27
- assert_source "class TestClass\n 1\nend"
28
- end
29
-
30
- def test_module
31
- assert_source "module TestModule\nend"
32
- end
33
-
34
- def test_module_with_body
35
- assert_source "module TestModule\n 1\nend"
36
- end
37
-
38
- def test_local_assignment
39
- assert_source "foo = 1"
40
- end
41
-
42
- def test_ivar_assignment
43
- assert_source "@foo = 1"
44
- end
45
-
46
- def test_local_access
47
- assert_source "foo = 1\nfoo"
48
- end
49
-
50
- def test_ivar_access
51
- assert_source "@foo"
52
- end
53
-
54
- def test_toplevel_constant_access
55
- assert_source "::Rubinius"
56
- end
57
-
58
- def test_constant_access
59
- assert_source "Rubinius"
60
- end
61
-
62
- def test_scoped_constant_access
63
- assert_source "Rubinius::Debugger"
64
- end
65
-
66
- def test_fixnum_literal
67
- assert_source "1"
68
- end
69
-
70
- def test_float_literal
71
- assert_source "1.0"
72
- end
73
-
74
- def test_string_literal
75
- assert_source '"foo"'
76
- end
77
-
78
- def test_symbol_literal
79
- assert_source ':foo'
80
- end
81
-
82
- def test_true_literal
83
- assert_source 'true'
84
- end
85
-
86
- def test_false_literal
87
- assert_source 'false'
88
- end
89
-
90
- def test_nil_literal
91
- assert_source 'nil'
92
- end
93
-
94
- def test_array_literal
95
- assert_source '[1, 2, 3]'
96
- end
97
-
98
- def test_hash_literal
99
- assert_source '{:answer => 42, :bar => :baz}'
100
- end
101
-
102
- def test_range
103
- assert_source '20..34'
104
- end
105
-
106
- def test_range_exclude
107
- assert_source '20...34'
108
- end
109
-
110
- def test_regex
111
- assert_source '/.*/'
112
- end
113
-
114
- def test_send
115
- assert_source 'foo.bar'
116
- end
117
-
118
- def test_send_with_arguments
119
- assert_converts 'foo.bar(:baz, :yeah)', 'foo.bar :baz, :yeah'
120
- end
121
-
122
- def test_send_with_arguments_and_empty_block
123
- assert_converts "foo.bar(:baz, :yeah) do\n nil\nend", "foo.bar(:baz, :yeah) do\nend"
124
- end
125
-
126
- def test_send_with_arguments_and_block_with_one_argument
127
- assert_source "foo.bar(:baz, :yeah) do |a|\n 3\n 4\nend"
128
- end
129
-
130
- def test_send_with_arguments_and_block_with_arguments
131
- assert_source "foo.bar(:baz, :yeah) do |a, b|\n 3\n 4\nend"
132
- end
133
-
134
- def test_lambda
135
- assert_source "lambda do |a, b|\n a\nend"
136
- end
137
-
138
- def test_proc
139
- assert_source "Proc.new do\n a\nend"
140
- end
141
-
142
- def test_binary_operators
143
- %w(+ - * / & | && || <<).each do |operator|
144
- assert_source "1 #{operator} 2"
145
- end
146
- end
147
-
148
- def test_expands_binary_equal
149
- assert_converts "a = a + 2", "a += 2"
150
- assert_converts "a = a - 2", "a -= 2"
151
- assert_converts "a = a * 2", "a *= 2"
152
- assert_converts "a = a / 2", "a /= 2"
153
- assert_converts "a && a = 2", "a &&= 2"
154
- assert_converts "a || a = 2", "a ||= 2"
155
- end
156
-
157
- def test_unary_operators
158
- assert_source "!1"
159
- assert_source "!!1"
160
- end
161
-
162
- def test_if
163
- assert_source "if 3\n 9\nend"
164
- end
165
-
166
- def test_if_with_multiple_blocks
167
- assert_source "if 3\n 9\n 8\nend"
168
- end
169
-
170
- def test_else
171
- assert_source "if 3\n 9\nelse\n 9\nend"
172
- end
173
-
174
- def test_else_with_multiple_blocks
175
- assert_source "if 3\n 9\n 8\nelse\n 9\n 8\nend"
176
- end
177
-
178
- def test_unless
179
- assert_source "unless 3\n 9\nend"
180
- end
181
-
182
- def test_while
183
- assert_source "while false\n 3\nend"
184
- end
185
-
186
- def test_while_with_multiple_blocks
187
- assert_source "while false\n 3\n 5\nend"
188
- end
189
-
190
- def test_until
191
- assert_source "until false\n 3\nend"
192
- end
193
-
194
- def test_until_with_multiple_blocks
195
- assert_source "while false\n 3\n 5\nend"
196
- end
197
-
198
- def test_return
199
- assert_source "return 9"
200
- end
201
- end
202
- end