lib/expressive.rb in expressive-0.0.13 vs lib/expressive.rb in expressive-0.0.14
- old
+ new
@@ -22,29 +22,29 @@
def self.all_symbols
%w(+ - * / = set sum post >= > < <= and or if date get put lookup round)
end
module Boolean
- def eval(scope)
+ def eval(scope = nil)
'true' == text_value
end
end
module IntegerValue
- def eval(scope)
+ def eval(scope = nil)
text_value.to_i
end
end
module FloatValue
- def eval(scope)
+ def eval(scope = nil)
text_value.to_f
end
end
module StringValue
- def eval(scope)
+ def eval(scope = nil)
text_value.gsub('"', '')
end
end
class Program < Treetop::Runtime::SyntaxNode
@@ -59,11 +59,15 @@
def statements
elements[1].elements.map {|e| e.data }
end
def eval(scope)
- function = statements.first.eval(scope)
- function.call(scope, statements[1..-1])
+ first_elem = statements.first.eval(scope)
+ if first_elem.is_a? Function
+ first_elem.call(scope, statements[1..-1])
+ else
+ statements.map {|stat| stat.eval(scope) }
+ end
end
end
class Statement < Treetop::Runtime::SyntaxNode
def data