From 73964aeb6ed7dccf237f77e1e13bc7446bcc8764 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 4 Apr 2017 18:00:21 +0300 Subject: [PATCH] adds modules to vool --- lib/vool/compiler.rb | 8 ++++++++ lib/vool/variables.rb | 3 +++ test/vool/test_variables.rb | 15 +++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/lib/vool/compiler.rb b/lib/vool/compiler.rb index 028fe347..173b5265 100644 --- a/lib/vool/compiler.rb +++ b/lib/vool/compiler.rb @@ -101,6 +101,14 @@ module Vool ClassVariable.new(expression.children.first.to_s[2 .. -1].to_sym) 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 name = expression.children[0] value = process(expression.children[1]) diff --git a/lib/vool/variables.rb b/lib/vool/variables.rb index 909835ed..320e0ba6 100644 --- a/lib/vool/variables.rb +++ b/lib/vool/variables.rb @@ -18,4 +18,7 @@ module Vool include Named end + class ModuleName < Statement + include Named + end end diff --git a/test/vool/test_variables.rb b/test/vool/test_variables.rb index eb53b6fe..d376f728 100644 --- a/test/vool/test_variables.rb +++ b/test/vool/test_variables.rb @@ -31,5 +31,20 @@ module Vool lst = Compiler.compile( "return @@var" ) assert_equal ClassVariable , lst.return_value.class 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