adds method_statement to vool

This commit is contained in:
Torsten Ruger 2017-04-01 16:27:32 +03:00
parent 295782d9e6
commit 34fdf7b2cd
7 changed files with 55 additions and 1 deletions

View File

@ -1,2 +1,3 @@
require_relative "vool/compiler"
require_relative "vool/class_statement"
require_relative "vool/method_statement"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,2 +1,3 @@
require_relative "helper"
require_relative "test_class_statement"
require_relative "test_method_statement"

View File

@ -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