add vool hashes
This commit is contained in:
@ -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