predicator 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +3 -2
- data/HISTORY.md +9 -0
- data/README.md +7 -8
- data/Rakefile +14 -5
- data/lib/predicator.rb +18 -10
- data/lib/predicator/ast.rb +138 -0
- data/lib/predicator/context.rb +7 -63
- data/lib/predicator/evaluator.rb +108 -0
- data/lib/predicator/lexer.rex +51 -0
- data/lib/predicator/lexer.rex.rb +160 -0
- data/lib/predicator/parser.rb +291 -7
- data/lib/predicator/parser.y +66 -40
- data/lib/predicator/version.rb +1 -1
- data/lib/predicator/visitors.rb +5 -0
- data/lib/predicator/visitors/dot.rb +100 -0
- data/lib/predicator/visitors/each.rb +16 -0
- data/lib/predicator/visitors/instructions.rb +117 -0
- data/lib/predicator/visitors/string.rb +60 -0
- data/lib/predicator/visitors/visitor.rb +48 -0
- data/predicator.gemspec +3 -2
- metadata +29 -32
- data/lib/predicator/errors.rb +0 -5
- data/lib/predicator/generated_parser.rb +0 -335
- data/lib/predicator/lexer.rb +0 -125
- data/lib/predicator/nodes.rb +0 -6
- data/lib/predicator/nodes/base_node.rb +0 -53
- data/lib/predicator/nodes/date_node.rb +0 -13
- data/lib/predicator/nodes/fixnum_node.rb +0 -9
- data/lib/predicator/nodes/float_node.rb +0 -9
- data/lib/predicator/nodes/nil_class_node.rb +0 -25
- data/lib/predicator/nodes/string_node.rb +0 -13
- data/lib/predicator/predicates.rb +0 -14
- data/lib/predicator/predicates/and.rb +0 -20
- data/lib/predicator/predicates/between.rb +0 -31
- data/lib/predicator/predicates/equal.rb +0 -9
- data/lib/predicator/predicates/false.rb +0 -13
- data/lib/predicator/predicates/greater_than.rb +0 -9
- data/lib/predicator/predicates/greater_than_or_equal.rb +0 -9
- data/lib/predicator/predicates/less_than.rb +0 -9
- data/lib/predicator/predicates/less_than_or_equal.rb +0 -9
- data/lib/predicator/predicates/method.rb +0 -17
- data/lib/predicator/predicates/not.rb +0 -20
- data/lib/predicator/predicates/not_equal.rb +0 -9
- data/lib/predicator/predicates/or.rb +0 -20
- data/lib/predicator/predicates/relation.rb +0 -31
- data/lib/predicator/predicates/true.rb +0 -13
- data/lib/predicator/variable.rb +0 -26
@@ -1,20 +0,0 @@
|
|
1
|
-
module Predicator
|
2
|
-
module Predicates
|
3
|
-
class Or
|
4
|
-
attr_reader :predicates
|
5
|
-
|
6
|
-
def initialize predicates
|
7
|
-
@predicates = predicates
|
8
|
-
end
|
9
|
-
|
10
|
-
def satisfied? context=Predicator::Context.new
|
11
|
-
predicates.any?{ |pred| pred.satisfied? context }
|
12
|
-
end
|
13
|
-
|
14
|
-
def == other
|
15
|
-
other.kind_of?(self.class) &&
|
16
|
-
other.predicates == predicates
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Predicator
|
2
|
-
module Predicates
|
3
|
-
class Relation
|
4
|
-
attr_reader :left, :right
|
5
|
-
|
6
|
-
def initialize left, right
|
7
|
-
@left, @right = left, right
|
8
|
-
end
|
9
|
-
|
10
|
-
def satisfied? context=Predicator::Context.new
|
11
|
-
lhs, rhs = values_for_comparison context
|
12
|
-
compare_values lhs, rhs
|
13
|
-
rescue NilValueError
|
14
|
-
return false
|
15
|
-
end
|
16
|
-
|
17
|
-
def values_for_comparison context=Context.new
|
18
|
-
left_node = context.node_for left
|
19
|
-
right_node = context.node_for right
|
20
|
-
method = "compare_to_#{left_node.type}"
|
21
|
-
[left_node.value, right_node.send(method)]
|
22
|
-
end
|
23
|
-
|
24
|
-
def == other
|
25
|
-
other.kind_of?(self.class) &&
|
26
|
-
other.left == left &&
|
27
|
-
other.right == right
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/lib/predicator/variable.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Predicator
|
2
|
-
class Variable
|
3
|
-
attr_reader :model, :attribute
|
4
|
-
|
5
|
-
def initialize model, attribute
|
6
|
-
@model = model
|
7
|
-
@attribute = attribute
|
8
|
-
end
|
9
|
-
|
10
|
-
def value_in context
|
11
|
-
entity_name = model.to_s
|
12
|
-
entity = context.bindings[entity_name]
|
13
|
-
if entity.nil?
|
14
|
-
raise ArgumentError, "Unknown entity #{entity_name}"
|
15
|
-
else
|
16
|
-
entity.send attribute
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def == other
|
21
|
-
other.kind_of?(self.class) &&
|
22
|
-
other.model == model &&
|
23
|
-
other.attribute == attribute
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|