Permalink
Browse files

added unary operators for compilation into algebra

  • Loading branch information...
1 parent 42cd1bc commit a9e83756ee97474987334fe86ebb07af9e393e01 Manuel Mayr committed Apr 4, 2011
@@ -3,3 +3,6 @@
require "switch/query_language/queryables/arithmetic/minus"
require "switch/query_language/queryables/arithmetic/multiplication"
require "switch/query_language/queryables/arithmetic/plus"
+require "switch/query_language/queryables/arithmetic/unary_arith"
+require "switch/query_language/queryables/arithmetic/unary_plus"
+require "switch/query_language/queryables/arithmetic/unary_minus"
@@ -0,0 +1,11 @@
+module Switch
+
+ module UnaryArith
+ attributes :queryable
+
+ def initialize(queryable)
+ @queryable = StandardWrapper::wrap(queryable)
+ end
+ end
+
+end
@@ -0,0 +1,7 @@
+module Switch
+
+ class UnaryMinus < Queryable
+ include UnaryArith
+ end
+
+end
@@ -0,0 +1,7 @@
+module Switch
+
+ class UnaryPlus < Queryable
+ include UnaryArith
+ end
+
+end
@@ -7,3 +7,5 @@
require "switch/query_language/queryables/comparables/greater_than_or_equal"
require "switch/query_language/queryables/comparables/or"
require "switch/query_language/queryables/comparables/and"
+require "switch/query_language/queryables/comparables/unary_comp"
+require "switch/query_language/queryables/comparables/not"
@@ -0,0 +1,7 @@
+module Switch
+
+ class Not < Queryable
+ include UnaryComparable
+ end
+
+end
@@ -0,0 +1,11 @@
+module Switch
+
+ module UnaryComparable
+ attributes :queryable
+
+ def initialize(queryable)
+ @queryable = StandardWrapper::wrap(queryable)
+ end
+ end
+
+end
@@ -83,13 +83,20 @@ module Combinators
module Arithmetic
[:+, :-, :*, :/].each do |method|
define_method(method) do |right_op|
- methods = { :+ => :Plus,
- :- => :Minus,
- :* => :Multiplication,
- :/ => :Division }
+ methods = { :+ => :Plus,
+ :- => :Minus,
+ :* => :Multiplication,
+ :/ => :Division }
Switch.const_get(methods[method]).new(self, right_op)
end
end
+ [:+@, :-@].each do |method|
+ define_method(method) do
+ methods = { :+@ => :UnaryPlus,
+ :-@ => :UnaryMinus }
+ Switch.const_get(methods[method]).new(self)
+ end
+ end
end
include Arithmetic
@@ -108,6 +115,9 @@ module Comparables
Switch.const_get(methods[method]).new(self, right_op)
end
end
+ def !
+ Switch.const_get(:Not).new(self)
+ end
end
include Comparables
View
@@ -85,6 +85,9 @@ Gem::Specification.new do |s|
"lib/switch/query_language/queryables/arithmetic/minus.rb",
"lib/switch/query_language/queryables/arithmetic/multiplication.rb",
"lib/switch/query_language/queryables/arithmetic/division.rb",
+ "lib/switch/query_language/queryables/arithmetic/unary_arith.rb",
+ "lib/switch/query_language/queryables/arithmetic/unary_plus.rb",
+ "lib/switch/query_language/queryables/arithmetic/unary_minus.rb",
"lib/switch/query_language/queryables/comparables.rb",
"lib/switch/query_language/queryables/comparables/binary_comp.rb",
"lib/switch/query_language/queryables/comparables/equal.rb",
@@ -95,6 +98,8 @@ Gem::Specification.new do |s|
"lib/switch/query_language/queryables/comparables/greater_than_or_equal.rb",
"lib/switch/query_language/queryables/comparables/or.rb",
"lib/switch/query_language/queryables/comparables/and.rb",
+ "lib/switch/query_language/queryables/comparables/unary_comp.rb",
+ "lib/switch/query_language/queryables/comparables/not.rb",
"lib/switch/query_language/queryables/table.rb",
"lib/switch/query_language/queryables/table/attribute.rb",
"lib/switch/query_language/queryables/table/attribute_accessor.rb",

0 comments on commit a9e8375

Please sign in to comment.