Descope Parfait in the compiler
Compiler now removes the module Parfait scope and also the ::Parfait:: Scope in module names Which means we can compile scoped code and get unscoped code. for Parfait Handy for tests too
This commit is contained in:
parent
7d92ee9e6a
commit
f126aa52df
@ -170,10 +170,17 @@ module Ruby
|
||||
ClassVariable.new(expression.children.first.to_s[2 .. -1].to_sym)
|
||||
end
|
||||
|
||||
# remove global parfait module scopes from consts
|
||||
# Other modules _scopes_ not implemented
|
||||
def on_const expression
|
||||
scope = expression.children.first
|
||||
if scope
|
||||
not_implemented(expression) unless scope.type == :cbase
|
||||
unless(scope.type == :const and
|
||||
scope.children.first and
|
||||
scope.children.first.type == :cbase and
|
||||
scope.children[1] == :Parfait)
|
||||
not_implemented(expression) unless scope.type == :cbase
|
||||
end
|
||||
end
|
||||
ModuleName.new(expression.children[1])
|
||||
end
|
||||
@ -254,6 +261,19 @@ module Ruby
|
||||
w
|
||||
end
|
||||
|
||||
# Unscope stuff out of the parfait module
|
||||
# less magic in requires
|
||||
# Other modules still not implemented
|
||||
def on_module(statement)
|
||||
kids = statement.children.dup
|
||||
name = kids.shift
|
||||
if(name.type == :const and
|
||||
name.children[1] == :Parfait)
|
||||
process_all(kids)
|
||||
else
|
||||
not_implemented(statement)
|
||||
end
|
||||
end
|
||||
private
|
||||
|
||||
def instance_name sym
|
||||
|
21
test/ruby/test_module_name.rb
Normal file
21
test/ruby/test_module_name.rb
Normal file
@ -0,0 +1,21 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Ruby
|
||||
class ModuleNameTest < Minitest::Test
|
||||
include RubyTests
|
||||
|
||||
def test_parfait_module
|
||||
assert_equal [nil], compile("module Parfait ; end")
|
||||
end
|
||||
def test_parfait_module_const
|
||||
assert_equal IntegerConstant, compile("module Parfait ; 1;end").first.class
|
||||
end
|
||||
|
||||
def test_module_parfait_removed
|
||||
exp = compile( "::Parfait::Object" )
|
||||
assert_equal ModuleName , exp.class
|
||||
assert_equal :Object , exp.name
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -4,17 +4,25 @@ module Ruby
|
||||
class NotImplemented < Minitest::Test
|
||||
include RubyTests
|
||||
|
||||
# random module names don't work, only global Parfait
|
||||
def assert_handler_missing(input)
|
||||
assert_raises(Ruby::ProcessError){ compile(input) }
|
||||
end
|
||||
|
||||
def test_module
|
||||
assert_handler_missing "module Name ; end"
|
||||
assert_handler_missing( "module Mod ; end" )
|
||||
end
|
||||
|
||||
def test_module_module_scoped
|
||||
assert_handler_missing( "M::Module" )
|
||||
end
|
||||
def test_module_parfait_scoped
|
||||
assert_handler_missing( "Parfait::Module" )
|
||||
end
|
||||
|
||||
def test_module_parfait_scoped
|
||||
assert_handler_missing( "module Mod ; end" )
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user