2018-07-19 13:46:51 +02:00
|
|
|
module Ruby
|
|
|
|
class ClassStatement < Statement
|
|
|
|
attr_reader :name, :super_class_name , :body
|
|
|
|
|
|
|
|
def initialize( name , supe , body)
|
|
|
|
@name , @super_class_name = name , supe
|
|
|
|
case body
|
2019-03-05 19:36:40 +01:00
|
|
|
when MethodStatement , SendStatement
|
2018-07-19 13:46:51 +02:00
|
|
|
@body = Statements.new([body])
|
|
|
|
when Statements
|
|
|
|
@body = body
|
|
|
|
when nil
|
|
|
|
@body = Statements.new([])
|
|
|
|
else
|
2019-03-05 19:36:40 +01:00
|
|
|
raise "what body #{body.class}:#{body}"
|
2018-07-19 13:46:51 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-19 13:59:10 +02:00
|
|
|
def to_vool
|
2019-03-05 19:36:40 +01:00
|
|
|
meths = body.statements.collect do |meth|
|
|
|
|
meth.is_a?(MethodStatement) ? meth.to_vool : tranform_statement(meth)
|
|
|
|
end
|
2018-07-19 20:44:48 +02:00
|
|
|
Vool::ClassStatement.new(@name , @super_class_name, Vool::Statements.new(meths) )
|
2018-07-19 13:46:51 +02:00
|
|
|
end
|
|
|
|
|
2019-03-05 19:36:40 +01:00
|
|
|
def tranform_statement( class_send )
|
|
|
|
unless class_send.is_a?(SendStatement)
|
|
|
|
raise "Other than methods, only class methods allowed, not #{class_send.class}"
|
|
|
|
end
|
|
|
|
unless class_send.name == :attr
|
|
|
|
raise "Only remapping attr and cattr, not #{class_send.name}"
|
|
|
|
end
|
|
|
|
raise "todo"
|
|
|
|
end
|
|
|
|
|
2018-07-19 13:46:51 +02:00
|
|
|
def to_s(depth = 0)
|
|
|
|
at_depth(depth , "class #{name}" , @body.to_s(depth + 1) , "end")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|