diff --git a/lib/vool.rb b/lib/vool.rb index 550b57e1..ca431eab 100644 --- a/lib/vool.rb +++ b/lib/vool.rb @@ -3,6 +3,8 @@ module Vool end end +require_relative "vool/array_statement" +require_relative "vool/basic_values" require_relative "vool/class_statement" require_relative "vool/method_statement" @@ -12,7 +14,6 @@ require_relative "vool/return_statement" require_relative "vool/statements" require_relative "vool/operator_expression" require_relative "vool/call_site_statement" -require_relative "vool/basic_values" require_relative "vool/assignment_statement" require_relative "vool/compiler" diff --git a/lib/vool/array_statement.rb b/lib/vool/array_statement.rb new file mode 100644 index 00000000..42cef191 --- /dev/null +++ b/lib/vool/array_statement.rb @@ -0,0 +1,13 @@ +module Vool + class ArrayStatement + attr_reader :values + + def initialize( values ) + @values = values + end + + def length + @values.length + end + end +end diff --git a/lib/vool/basic_values.rb b/lib/vool/basic_values.rb index 01afc9a8..a41277b7 100644 --- a/lib/vool/basic_values.rb +++ b/lib/vool/basic_values.rb @@ -23,11 +23,6 @@ module Vool @value = value end end - class NameStatement < Statement - attr_accessor :value - alias :name :value - def initialize(value) - @value = value - end + class SymbolStatement < StringStatement end end diff --git a/lib/vool/compiler.rb b/lib/vool/compiler.rb index 6930760a..7ba59347 100644 --- a/lib/vool/compiler.rb +++ b/lib/vool/compiler.rb @@ -6,6 +6,11 @@ module Vool self.new.process(ast) end + # default to error, so non implemented stuff shows early + def handler_missing(node) + raise "Not implemented #{node.type}" + end + def on_class( statement ) name , sup , body = *statement ClassStatement.new( get_name(name) , get_name(sup) , process_all(body) ) @@ -21,6 +26,7 @@ module Vool arg.first end + #basic Values def on_int expression IntegerStatement.new(expression.children.first) end @@ -46,10 +52,25 @@ module Vool end alias :on_string :on_str - def on_dstr - raise "Not implemented dynamix strings (with interpolation)" + def on_dstr expression + raise "Not implemented dynamic strings (with interpolation)" end - + alias :on_xstr :on_dstr + + def on_sym expression + SymbolStatement.new(expression.children.first) + end + alias :on_string :on_str + + def on_dsym + raise "Not implemented dynamix symbols (with interpolation)" + end + + # Array + Hashes + def on_array expression + ArrayStatement.new expression.children.collect{ |elem| process(elem) } + end + def on_return statement w = ReturnStatement.new() w.return_value = process(statement.children.first) diff --git a/test/vool/test_array_statement.rb b/test/vool/test_array_statement.rb new file mode 100644 index 00000000..2cc5deae --- /dev/null +++ b/test/vool/test_array_statement.rb @@ -0,0 +1,19 @@ +require_relative "../helper" + +module Vool + class TestArray < MiniTest::Test + + def test_empty + lst = Compiler.compile( "[]") + assert_equal ArrayStatement , lst.class + end + def test_one + lst = Compiler.compile( "[1]") + assert_equal ArrayStatement , lst.class + end + def test_two + lst = Compiler.compile( "[1,2]") + assert_equal ArrayStatement , lst.class + end + end +end diff --git a/test/vool/test_basic_values.rb b/test/vool/test_basic_values.rb index dcdfdc2a..bdd4f452 100644 --- a/test/vool/test_basic_values.rb +++ b/test/vool/test_basic_values.rb @@ -23,5 +23,14 @@ module Vool lst = Compiler.compile( "'string'") assert_equal StringStatement , lst.class , lst.inspect end + def test_sym + lst = Compiler.compile( ":symbol") + assert_equal SymbolStatement , lst.class , lst.inspect + end + def test_dstr + assert_raises RuntimeError do + Compiler.compile( '"dstr#{self}"') + end + end end end diff --git a/test/vool/test_compiler.rb b/test/vool/test_compiler.rb index 1be9c2ab..20890910 100644 --- a/test/vool/test_compiler.rb +++ b/test/vool/test_compiler.rb @@ -1,4 +1,5 @@ require_relative "helper" +require_relative "test_array_statement" +require_relative "test_basic_values" require_relative "test_class_statement" require_relative "test_method_statement" -require_relative "test_basic_values"