adds modules to vool

This commit is contained in:
Torsten Ruger 2017-04-04 18:00:21 +03:00
parent 5f70067fa0
commit 73964aeb6e
3 changed files with 26 additions and 0 deletions

View File

@ -101,6 +101,14 @@ module Vool
ClassVariable.new(expression.children.first.to_s[2 .. -1].to_sym) ClassVariable.new(expression.children.first.to_s[2 .. -1].to_sym)
end end
def on_const expression
scope = expression.children.first
if scope
raise "Only unscoped Names implemented #{scope}" unless scope.type == :cbase
end
ModuleName.new(expression.children[1])
end
def on_lvasgn expression def on_lvasgn expression
name = expression.children[0] name = expression.children[0]
value = process(expression.children[1]) value = process(expression.children[1])

View File

@ -18,4 +18,7 @@ module Vool
include Named include Named
end end
class ModuleName < Statement
include Named
end
end end

View File

@ -31,5 +31,20 @@ module Vool
lst = Compiler.compile( "return @@var" ) lst = Compiler.compile( "return @@var" )
assert_equal ClassVariable , lst.return_value.class assert_equal ClassVariable , lst.return_value.class
end end
def test_module_basic
lst = Compiler.compile( "Module" )
assert_equal ModuleName , lst.class
assert_equal :Module , lst.name
end
def test_module_base_scoped
lst = Compiler.compile( "::Module" )
assert_equal ModuleName , lst.class
assert_equal :Module , lst.name
end
def test_module_module_scoped
assert_raises {Compiler.compile( "M::Module" ) }
end
end end
end end