a start on conditionals

This commit is contained in:
Torsten Ruger
2017-04-02 19:12:42 +03:00
parent 443fd13980
commit f343ad934c
4 changed files with 84 additions and 4 deletions

View File

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

View File

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

View File

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