move ast to tree, remove seperate helper file

This commit is contained in:
Torsten Ruger 2016-12-09 13:56:13 +02:00
parent bab2fe32df
commit 4da13c3867
17 changed files with 47 additions and 57 deletions

View File

@ -1,27 +0,0 @@
# Base class for Expresssion and Statement
module Typed
class Code
end
class Statement < Code
end
class Expression < Code
end
end
require_relative "while_statement"
require_relative "if_statement"
require_relative "return_statement"
require_relative "statements"
require_relative "operator_expression"
require_relative "field_access"
require_relative "call_site"
require_relative "basic_values"
require_relative "assignment"
require_relative "class_statement"
require_relative "function_statement"
require_relative "to_code"

View File

@ -1,5 +0,0 @@
module Typed
class WhileStatement < Statement
attr_accessor :branch_type , :condition , :statements
end
end

View File

@ -1,23 +0,0 @@
AST::Node.class_eval do
def [](name)
#puts self.inspect
children.each do |child|
if child.is_a?(AST::Node)
#puts child.type
if (child.type == name)
return child.children
end
else
#puts child.class
end
end
nil
end
def first_from( node_name )
from = self[node_name]
return nil unless from
from.first
end
end

View File

@ -1,3 +1,5 @@
require_relative "tree"
module Typed module Typed
CompilerModules = [ "assignment" , "basic_values" , "call_site", "class_field" , CompilerModules = [ "assignment" , "basic_values" , "call_site", "class_field" ,
@ -187,8 +189,6 @@ module Typed
end end
end end
require_relative "ast_helper"
require_relative "ast/code"
require_relative "compiler/collections" require_relative "compiler/collections"
require_relative "compiler/field_def" require_relative "compiler/field_def"
require_relative "compiler/field_access" require_relative "compiler/field_access"

38
lib/typed/tree.rb Normal file
View File

@ -0,0 +1,38 @@
# Base class for Expresssion and Statement
module Typed
class Code ; end
class Statement < Code ; end
class Expression < Code ; end
end
["while_statement", "if_statement" , "return_statement" , "statements",
"operator_expression" , "field_access" , "call_site" , "basic_values",
"assignment" , "class_statement" , "function_statement" , "to_code"].each do |code|
require_relative "tree/" + code
end
AST::Node.class_eval do
def [](name)
#puts self.inspect
children.each do |child|
if child.is_a?(AST::Node)
#puts child.type
if (child.type == name)
return child.children
end
else
#puts child.class
end
end
nil
end
def first_from( node_name )
from = self[node_name]
return nil unless from
from.first
end
end

View File

@ -0,0 +1,7 @@
module Typed
module Tree
class WhileStatement < Statement
attr_accessor :branch_type , :condition , :statements
end
end
end