Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added support for arrays and hashes. Still no symbols.

  • Loading branch information...
commit b84a9e59273d77babe050f1a2e4d900d00545f91 1 parent 7b1c6b0
matt knox authored May 09, 2010
5  bin/dev.rb
@@ -18,6 +18,7 @@ def reload(f)
18 18
 v = EightBallVisitor.new
19 19
 a = e.parse 'lambda {|x| x + 1}'
20 20
 b = e.parse 'Proc.new {|x| x + 1 }'
21  
-d = e.parse 'class Foo < Fixnum;def bar; 1+2;end;end'
  21
+d = e.parse '{1 => "foo", "bar" => true, false => [2]}'
  22
+
22 23
 x = a.child_nodes.first.next_node
23  
-a.accept v
  24
+d.accept v
14  lib/8ball_visitor.rb
@@ -68,6 +68,16 @@ def visit_const_node(node)
68 68
     "(#{node.get_name})"
69 69
   end
70 70
 
  71
+  def visit_array_node(node)
  72
+    "([#{node.child_nodes.map { |x| visit(x) }.join(', ')}])"
  73
+  end
  74
+
  75
+  def visit_hash_node(node)
  76
+    acc = []
  77
+    node.first_child.child_nodes.each_slice(2) {|x,y| acc << "#{visit(x)} => #{visit(y)}"}
  78
+    "({#{acc.join(', ')}})"
  79
+  end
  80
+
71 81
   # def visitClassNode(node)
72 82
   #   gather("this.define_class(\"#{node.getCPath.getName}\",",
73 83
   #          "function() {",
@@ -75,10 +85,6 @@ def visit_const_node(node)
75 85
   #          "})")
76 86
   # end
77 87
 
78  
-  # def visitDefnNode(node)
79  
-  #   compile_function(node.get_name, node.args_node.args, node.body_node)
80  
-  # end
81  
-
82 88
   def visitArgsNode(node)
83 89
     node.args.child_nodes.to_a.map {|x| x.name}.join(", ")
84 90
   end
3  spec/8ball_spec.rb
@@ -16,9 +16,10 @@
16 16
     cs('Proc.new {|x| x + 1}').should == "(function  (x){\nreturn (x.rubyplus((1)));\n}\n)"
17 17
     cs('/foo/').should == "(/foo/)"
18 18
     cs('Foo').should == "(Foo)"
19  
-    cs('class Foo < Fixnum;def bar; 1+2;end;end').should == "Class.define(Foo, Fixnum, function bar (){\nreturn ((1).rubyplus((2)));\n}\n)"
  19
+    cs('class Foo < Fixnum;def bar;1+2;end;end').should == "Class.define(Foo, Fixnum, function bar (){\nreturn ((1).rubyplus((2)));\n}\n)"
20 20
     cs('puts "hello"').should == "EightBall.puts(('hello'));"
21 21
     cs("'foo'.length").should == "('foo').length()"
  22
+    cs("[2,3]").should == "([(2), (3)])"
22 23
     cs("").should == ""
23 24
   end
24 25
 

0 notes on commit b84a9e5

Please sign in to comment.
Something went wrong with that request. Please try again.