fix module handling at ruby level
Was returning arrays instead of Statements, which messed things up
This commit is contained in:
parent
646797301e
commit
363d1cb36f
@ -26,6 +26,8 @@ module Ruby
|
|||||||
sendd.arguments << lambda
|
sendd.arguments << lambda
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
def to_s(depth = 0)
|
||||||
|
at_depth(depth , "{|#{@args.join(',')}| #{@body}}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -38,7 +38,7 @@ module Ruby
|
|||||||
begin
|
begin
|
||||||
self.new.process(ast)
|
self.new.process(ast)
|
||||||
rescue => e
|
rescue => e
|
||||||
puts "Error processing #{ast}"
|
puts "Error processing \n#{ast}"
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -139,7 +139,11 @@ module Ruby
|
|||||||
not_implemented(expression)
|
not_implemented(expression)
|
||||||
end
|
end
|
||||||
def on_kwbegin statement
|
def on_kwbegin statement
|
||||||
ScopeStatement.new process_all( statement.children )
|
scope = ScopeStatement.new([])
|
||||||
|
statement.children.each do |kid| #do the loop to catch errors (not process_all)
|
||||||
|
scope << process(kid)
|
||||||
|
end
|
||||||
|
scope
|
||||||
end
|
end
|
||||||
alias :on_begin :on_kwbegin
|
alias :on_begin :on_kwbegin
|
||||||
|
|
||||||
@ -269,7 +273,12 @@ module Ruby
|
|||||||
name = kids.shift
|
name = kids.shift
|
||||||
if(name.type == :const and
|
if(name.type == :const and
|
||||||
name.children[1] == :Parfait)
|
name.children[1] == :Parfait)
|
||||||
process_all(kids)
|
raise "No empty modules for now #{statement}" if kids.empty?
|
||||||
|
if(kids.length == 1)
|
||||||
|
process(kids.first)
|
||||||
|
else
|
||||||
|
on_kwbegin(kids)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
not_implemented(statement)
|
not_implemented(statement)
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,8 @@ module Ruby
|
|||||||
class Statements < Statement
|
class Statements < Statement
|
||||||
attr_reader :statements
|
attr_reader :statements
|
||||||
def initialize(statements)
|
def initialize(statements)
|
||||||
@statements = statements
|
@statements = []
|
||||||
|
statements.each{|st| self << st}
|
||||||
end
|
end
|
||||||
|
|
||||||
def empty?
|
def empty?
|
||||||
@ -30,6 +31,7 @@ module Ruby
|
|||||||
@statements[i]
|
@statements[i]
|
||||||
end
|
end
|
||||||
def <<(o)
|
def <<(o)
|
||||||
|
raise "Not Statement #{o.class}=#{o.to_s[0..100]}" unless o.is_a?(Statement)
|
||||||
@statements << o
|
@statements << o
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
@ -9,12 +9,12 @@ module Ruby
|
|||||||
def to_vool
|
def to_vool
|
||||||
vool_brother.new(@name)
|
vool_brother.new(@name)
|
||||||
end
|
end
|
||||||
|
def to_s(depth=0)
|
||||||
|
name.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class LocalVariable < Variable
|
class LocalVariable < Variable
|
||||||
def to_s
|
|
||||||
name.to_s
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class InstanceVariable < Variable
|
class InstanceVariable < Variable
|
||||||
@ -24,7 +24,7 @@ module Ruby
|
|||||||
array << @name
|
array << @name
|
||||||
end
|
end
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
at_depth(depth , "@#{name}" )
|
"@#{name}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,11 +4,14 @@ module Ruby
|
|||||||
class ModuleNameTest < Minitest::Test
|
class ModuleNameTest < Minitest::Test
|
||||||
include RubyTests
|
include RubyTests
|
||||||
|
|
||||||
def test_parfait_module
|
def test_parfait_module_scoped
|
||||||
assert_equal [nil], compile("module Parfait ; end")
|
lst = compile("module Parfait ; 1 ; 1 ; end")
|
||||||
|
assert_equal ScopeStatement, lst.class
|
||||||
|
assert_equal IntegerConstant, lst.first.class
|
||||||
|
assert_equal 2, lst.length
|
||||||
end
|
end
|
||||||
def test_parfait_module_const
|
def test_parfait_module_const
|
||||||
assert_equal IntegerConstant, compile("module Parfait ; 1;end").first.class
|
assert_equal IntegerConstant, compile("module Parfait ; 1;end").class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_module_parfait_removed
|
def test_module_parfait_removed
|
||||||
|
Loading…
Reference in New Issue
Block a user