From 4d9d67af5cfcc63cfdd65ae29a63c38f7082580e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 27 Sep 2015 11:26:53 +0300 Subject: [PATCH] move ast code/patch here --- lib/bosl/ast_helper.rb | 23 +++++++++++++++++++++++ lib/bosl/compiler.rb | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 lib/bosl/ast_helper.rb diff --git a/lib/bosl/ast_helper.rb b/lib/bosl/ast_helper.rb new file mode 100644 index 00000000..a1706805 --- /dev/null +++ b/lib/bosl/ast_helper.rb @@ -0,0 +1,23 @@ +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 diff --git a/lib/bosl/compiler.rb b/lib/bosl/compiler.rb index 589dabdd..c2142797 100644 --- a/lib/bosl/compiler.rb +++ b/lib/bosl/compiler.rb @@ -33,11 +33,12 @@ module Bosl end end -require_relative "compiler/basic_expressions" +require_relative "ast_helper" require_relative "compiler/callsite_expression" require_relative "compiler/compound_expressions" require_relative "compiler/expression_list" require_relative "compiler/field_def" +require_relative "compiler/field_access" require_relative "compiler/function_expression" require_relative "compiler/if_expression" require_relative "compiler/module_expression"