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

- old
+ new

@@ -1,8 +1,9 @@ require 'polyglot' require 'treetop' require 'awesome_print' +require 'rest_client' require File.join(File.dirname(__FILE__), 'scope') Treetop.load File.join(File.dirname(__FILE__), 'expressive_grammar.treetop') module Expressive @@ -13,34 +14,43 @@ def self.parse(expressions) @parser ||= ::ExpressiveParser.new @parser.parse(expressions) end + + def self.all_symbols + %w(+ - * / = set sum post >= > < <= and or if) + end end - -module Boolean +module Boolean def eval(scope) - 'true' == text_value + 'true' == text_value end end -module IntegerValue - def eval(scope) +module IntegerValue + def eval(scope) text_value.to_i end end -module FloatValue - def eval(scope) - text_value.to_f +module FloatValue + def eval(scope) + text_value.to_f end end +module StringValue + def eval(scope) + text_value.gsub('"', '') + end +end + class Program < Treetop::Runtime::SyntaxNode def eval(scope) - elements.map {|e| + elements.map {|e| e.eval(scope) }.last end end @@ -81,10 +91,10 @@ def initialize(&block) @block = block end def call(scope, statements) - parameters = statements.map {|c| c.eval(scope)} + parameters = statements.map {|c| c.eval(scope)} @block.call(*parameters) end end class Syntax < Function