adds collect for the statements

This commit is contained in:
Torsten Ruger
2017-04-08 12:10:42 +03:00
parent 0fe5685ad4
commit 8942f42310
10 changed files with 85 additions and 1 deletions

View File

@ -4,6 +4,10 @@ module Vool
def initialize(name , value )
@name , @value = name , value
end
def collect(arr)
@value.collect(arr)
super
end
end
class LocalAssignment < Assignment
end

View File

@ -9,6 +9,12 @@ module Vool
simplify_condition
end
def collect(arr)
@if_true.collect(arr)
@if_false.collect(arr)
super
end
def simplify_condition
return unless @condition.is_a?(ScopeStatement)
@condition = @condition.first if @condition.single?

View File

@ -1,11 +1,18 @@
module Vool
# Logical Statements are guaranteed to return boolean
# either :and or :or, which may be written as && and ||
# either :and or :or, which may be written as && and ||
class LogicalStatement < Statement
attr_reader :name , :left , :right
def initialize(name , left , right)
@name , @left , @right = name , left , right
end
def collect(arr)
@receiver.collect(arr)
@arguments.collect(arr)
super
end
end
end

View File

@ -6,5 +6,11 @@ module Vool
@name , @args , @body = name , args , (body || [])
end
def collect(arr)
@args.collect(arr)
@body.collect(arr)
super
end
end
end

View File

@ -5,5 +5,10 @@ module Vool
def initialize(value)
@return_value = value
end
def collect(arr)
@return_value.collect(arr)
super
end
end
end

View File

@ -5,5 +5,12 @@ module Vool
def initialize(name , receiver , arguments = [])
@name , @receiver , @arguments = name , receiver , arguments
end
def collect(arr)
@receiver.collect(arr)
@arguments.collect(arr)
super
end
end
end

View File

@ -16,6 +16,11 @@ module Vool
def length
@statements.length
end
def collect(arr)
@statements.each { |s| s.collect(arr) }
super
end
end
class ScopeStatement < Statements

View File

@ -13,5 +13,11 @@ module Vool
@condition = @condition.first if @condition.single?
end
def collect(arr)
@condition.collect(arr)
@statements.collect(arr)
super
end
end
end