adds method_statement to vool
This commit is contained in:
parent
295782d9e6
commit
34fdf7b2cd
@ -1,2 +1,3 @@
|
||||
require_relative "vool/compiler"
|
||||
require_relative "vool/class_statement"
|
||||
require_relative "vool/method_statement"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
10
lib/vool/method_statement.rb
Normal file
10
lib/vool/method_statement.rb
Normal 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
|
@ -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
|
||||
|
@ -1,2 +1,3 @@
|
||||
require_relative "helper"
|
||||
require_relative "test_class_statement"
|
||||
require_relative "test_method_statement"
|
||||
|
28
test/vool/test_method_statement.rb
Normal file
28
test/vool/test_method_statement.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user