a start on conditionals
This commit is contained in:
@ -127,11 +127,14 @@ module Vool
|
||||
w
|
||||
end
|
||||
|
||||
def on_if_statement statement
|
||||
branch_type , condition , if_true , if_false = *statement
|
||||
def on_if statement
|
||||
# puts "IF #{statement}"
|
||||
condition , if_true , if_false = *statement
|
||||
w = IfStatement.new()
|
||||
w.branch_type = branch_type
|
||||
w.condition = process(condition)
|
||||
if(w.condition.is_a?(ScopeStatement) and w.condition.single?)
|
||||
w.condition = w.condition.first
|
||||
end
|
||||
w.if_true = process(if_true)
|
||||
w.if_false = process(if_false)
|
||||
w
|
||||
|
@ -1,5 +1,19 @@
|
||||
module Vool
|
||||
class IfStatement < Statement
|
||||
attr_accessor :branch_type , :condition , :if_true , :if_false
|
||||
attr_accessor :condition , :if_true , :if_false
|
||||
|
||||
def initialize( cond = nil)
|
||||
@condition = cond
|
||||
@if_true = []
|
||||
@if_false = []
|
||||
end
|
||||
|
||||
def has_false?
|
||||
@if_false != nil
|
||||
end
|
||||
|
||||
def has_true?
|
||||
@if_true != nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,6 +4,15 @@ module Vool
|
||||
def initialize(statements)
|
||||
@statements = statements
|
||||
end
|
||||
def empty?
|
||||
@statements.empty?
|
||||
end
|
||||
def single?
|
||||
@statements.length == 1
|
||||
end
|
||||
def first
|
||||
@statements.first
|
||||
end
|
||||
end
|
||||
|
||||
class ScopeStatement < Statements
|
||||
|
Reference in New Issue
Block a user