diff --git a/lib/vool.rb b/lib/vool.rb index e72db3db..9a0f002f 100644 --- a/lib/vool.rb +++ b/lib/vool.rb @@ -1,2 +1,3 @@ require_relative "vool/compiler" require_relative "vool/class_statement" +require_relative "vool/method_statement" diff --git a/lib/vool/class_statement.rb b/lib/vool/class_statement.rb index 86d0374a..8e39d94f 100644 --- a/lib/vool/class_statement.rb +++ b/lib/vool/class_statement.rb @@ -3,7 +3,7 @@ module Vool attr_reader :name, :super_class_name , :body def initialize( name , supe , body) - @name , @super_class_name , @body = name , supe , body + @name , @super_class_name , @body = name , supe , (body || []) end end diff --git a/lib/vool/compiler.rb b/lib/vool/compiler.rb index 5744f660..6325ad6b 100644 --- a/lib/vool/compiler.rb +++ b/lib/vool/compiler.rb @@ -11,6 +11,16 @@ module Vool ClassStatement.new( get_name(name) , get_name(sup) , body ) end + def on_def( statement ) + name , args , body = *statement + arg_array = process_all( args ) + MethodStatement.new( name , arg_array , body ) + end + + def on_arg( arg ) + arg.first + end + def get_name( statement ) return nil unless statement raise "Not const #{statement}" unless statement.type == :const diff --git a/lib/vool/method_statement.rb b/lib/vool/method_statement.rb new file mode 100644 index 00000000..5a62f867 --- /dev/null +++ b/lib/vool/method_statement.rb @@ -0,0 +1,10 @@ +module Vool + class MethodStatement + attr_reader :name, :args , :body + + def initialize( name , args , body) + @name , @args , @body = name , args , (body || []) + end + + end +end diff --git a/test/vool/test_class_statement.rb b/test/vool/test_class_statement.rb index 98477fb7..670f9c96 100644 --- a/test/vool/test_class_statement.rb +++ b/test/vool/test_class_statement.rb @@ -20,5 +20,9 @@ module Vool assert_equal :Base , @lst.super_class_name end + def test_compile_class_body + assert_equal [] , @lst.body + end + end end diff --git a/test/vool/test_compiler.rb b/test/vool/test_compiler.rb index 6a3f1070..0974d5e2 100644 --- a/test/vool/test_compiler.rb +++ b/test/vool/test_compiler.rb @@ -1,2 +1,3 @@ require_relative "helper" require_relative "test_class_statement" +require_relative "test_method_statement" diff --git a/test/vool/test_method_statement.rb b/test/vool/test_method_statement.rb new file mode 100644 index 00000000..446c5c26 --- /dev/null +++ b/test/vool/test_method_statement.rb @@ -0,0 +1,28 @@ +require_relative "../helper" + +module Vool + class TestMethodStatement < MiniTest::Test + + def setup + input = "def tryout(arg1, arg2) ; end " + @lst = Compiler.compile( input ) + end + + def test_compile_method + assert_equal MethodStatement , @lst.class + end + + def test_compile_method_name + assert_equal :tryout , @lst.name + end + + def test_compile_method_super + assert_equal [:arg1, :arg2] , @lst.args + end + + def test_compile_method_body + assert_equal [] , @lst.body + end + + end +end