to_source 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,8 +9,11 @@ module Rubinius
9
9
  #
10
10
  # Returns nothing.
11
11
  def lazy_visit(visitor, parent=nil, indent=false)
12
- args = [self.node_name, self, parent]
13
- args.push true if indent
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
14
17
 
15
18
  visitor.__send__ *args
16
19
  end
@@ -1,3 +1,3 @@
1
1
  module ToSource
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -17,6 +17,42 @@ module ToSource
17
17
  ' ' * @indentation
18
18
  end
19
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
+
20
56
  def local_variable_assignment(node, parent)
21
57
  emit "%s = " % node.name
22
58
  node.value.lazy_visit self, node
@@ -15,6 +15,26 @@ module ToSource
15
15
  assert_equal expected, visit(code)
16
16
  end
17
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
+
18
38
  def test_local_assignment
19
39
  assert_source "foo = 1"
20
40
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_source
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.1.3
4
5
  prerelease:
5
- version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Josep M. Bach
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-11 00:00:00.000000000 Z
12
+ date: 2012-04-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Transform your Rubinius AST nodes back to source code. Reverse parsing!
15
15
  email:
@@ -37,17 +37,17 @@ rdoc_options: []
37
37
  require_paths:
38
38
  - lib
39
39
  required_ruby_version: !ruby/object:Gem::Requirement
40
- none: false
41
40
  requirements:
42
41
  - - ! '>='
43
42
  - !ruby/object:Gem::Version
44
43
  version: '0'
45
- required_rubygems_version: !ruby/object:Gem::Requirement
46
44
  none: false
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
46
  requirements:
48
47
  - - ! '>='
49
48
  - !ruby/object:Gem::Version
50
49
  version: '0'
50
+ none: false
51
51
  requirements: []
52
52
  rubyforge_project:
53
53
  rubygems_version: 1.8.12