adds arrays to vool

also symbols and some cleanup
This commit is contained in:
Torsten Ruger 2017-04-02 10:43:22 +03:00
parent 8f03d98330
commit d5af6dad42
7 changed files with 70 additions and 11 deletions

View File

@ -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"

View File

@ -0,0 +1,13 @@
module Vool
class ArrayStatement
attr_reader :values
def initialize( values )
@values = values
end
def length
@values.length
end
end
end

View File

@ -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

View File

@ -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,8 +52,23 @@ 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

View File

@ -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

View File

@ -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

View File

@ -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"