add vool hashes
This commit is contained in:
@ -6,6 +6,7 @@ end
|
||||
require_relative "vool/array_statement"
|
||||
require_relative "vool/basic_values"
|
||||
require_relative "vool/class_statement"
|
||||
require_relative "vool/hash_statement"
|
||||
require_relative "vool/method_statement"
|
||||
|
||||
require_relative "vool/while_statement"
|
||||
|
@ -71,6 +71,15 @@ module Vool
|
||||
ArrayStatement.new expression.children.collect{ |elem| process(elem) }
|
||||
end
|
||||
|
||||
def on_hash expression
|
||||
hash = HashStatement.new
|
||||
expression.children.each do |elem|
|
||||
raise "Hash error, hash contains non pair: #{elem.type}" if elem.type != :pair
|
||||
hash.add( process(elem.children[0]) , process(elem.children[1]) )
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
def on_return statement
|
||||
w = ReturnStatement.new()
|
||||
w.return_value = process(statement.children.first)
|
||||
|
17
lib/vool/hash_statement.rb
Normal file
17
lib/vool/hash_statement.rb
Normal file
@ -0,0 +1,17 @@
|
||||
module Vool
|
||||
class HashStatement
|
||||
attr_reader :hash
|
||||
|
||||
def initialize( )
|
||||
@hash = {}
|
||||
end
|
||||
|
||||
def add(key , value)
|
||||
@hash[key] = value
|
||||
end
|
||||
|
||||
def length
|
||||
@hash.length
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user