pick up instance variables from the class

Crude first set to creating types
This commit is contained in:
Torsten Ruger
2016-12-18 20:05:11 +02:00
parent e77298f4b1
commit 107e3e6d58
3 changed files with 35 additions and 2 deletions

View File

@ -1,3 +1,4 @@
require_relative "type_collector"
module Melon
@ -15,8 +16,9 @@ module Melon
end
def on_class statement
name , sup , _ = *statement
Parfait::Space.object_space.create_class(get_name(name) , get_name(sup) )
name , sup , body = *statement
clazz = Parfait::Space.object_space.create_class(get_name(name) , get_name(sup) )
clazz.set_instance_names( TypeCollector.new.collect(body) )
end
end
end

View File

@ -0,0 +1,24 @@
module Melon
class TypeCollector < AST::Processor
def initialize
@ivar_names = []
end
def collect(statement)
process statement
@ivar_names
end
def on_ivar(statement)
@ivar_names.push statement.children[0].to_s[1..-1].to_sym
end
def handler_missing(node)
node.children.each do |kid |
process(kid) if kid.is_a?(AST::Node)
end
end
end
end