lib/expressive.rb in expressive-0.0.3 vs lib/expressive.rb in expressive-0.0.5

- old
+ new

@@ -18,88 +18,82 @@ end def self.all_symbols %w(+ - * / = set sum post >= > < <= and or if) end -end -module Boolean - def eval(scope) - 'true' == text_value + module Boolean + def eval(scope) + 'true' == text_value + end end -end -module IntegerValue - def eval(scope) - text_value.to_i + module IntegerValue + def eval(scope) + text_value.to_i + end end -end -module FloatValue - def eval(scope) - text_value.to_f + module FloatValue + def eval(scope) + text_value.to_f + end end -end -module StringValue - def eval(scope) - text_value.gsub('"', '') + module StringValue + def eval(scope) + text_value.gsub('"', '') + end end -end -class Program < Treetop::Runtime::SyntaxNode - def eval(scope) - elements.map {|e| - e.eval(scope) - }.last + class Program < Treetop::Runtime::SyntaxNode + def eval(scope) + elements.map {|e| + e.eval(scope) + }.last + end end -end -class List < Treetop::Runtime::SyntaxNode - def statements - elements[1].elements.map {|e| e.data } - end + class List < Treetop::Runtime::SyntaxNode + def statements + elements[1].elements.map {|e| e.data } + end - def eval(scope) - function = statements.first.eval(scope) - function.call(scope, statements[1..-1]) + def eval(scope) + function = statements.first.eval(scope) + function.call(scope, statements[1..-1]) + end end -end -class Statement < Treetop::Runtime::SyntaxNode - def data - elements[1] - end + class Statement < Treetop::Runtime::SyntaxNode + def data + elements[1] + end - def eval(scope) - data.eval(scope) + def eval(scope) + data.eval(scope) + end end -end -# class SetNode < Treetop::Runtime::SyntaxNode -# def pieces -# [ :set, fieldname.text_value, value.text_value ] -# end -# end - -class Identifier < Treetop::Runtime::SyntaxNode - def eval(scope) - scope[text_value] + class Identifier < Treetop::Runtime::SyntaxNode + def eval(scope) + scope[text_value] + end end -end -class Function - def initialize(&block) - @block = block - end + class Function + def initialize(&block) + @block = block + end - def call(scope, statements) - parameters = statements.map {|c| c.eval(scope)} - @block.call(*parameters) + def call(scope, statements) + parameters = statements.map {|c| c.eval(scope)} + @block.call(*parameters) + end end -end -class Syntax < Function - def call(scope, statements) - @block.call(scope, statements) + class Syntax < Function + def call(scope, statements) + @block.call(scope, statements) + end end end