predicator 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +3 -2
  4. data/HISTORY.md +9 -0
  5. data/README.md +7 -8
  6. data/Rakefile +14 -5
  7. data/lib/predicator.rb +18 -10
  8. data/lib/predicator/ast.rb +138 -0
  9. data/lib/predicator/context.rb +7 -63
  10. data/lib/predicator/evaluator.rb +108 -0
  11. data/lib/predicator/lexer.rex +51 -0
  12. data/lib/predicator/lexer.rex.rb +160 -0
  13. data/lib/predicator/parser.rb +291 -7
  14. data/lib/predicator/parser.y +66 -40
  15. data/lib/predicator/version.rb +1 -1
  16. data/lib/predicator/visitors.rb +5 -0
  17. data/lib/predicator/visitors/dot.rb +100 -0
  18. data/lib/predicator/visitors/each.rb +16 -0
  19. data/lib/predicator/visitors/instructions.rb +117 -0
  20. data/lib/predicator/visitors/string.rb +60 -0
  21. data/lib/predicator/visitors/visitor.rb +48 -0
  22. data/predicator.gemspec +3 -2
  23. metadata +29 -32
  24. data/lib/predicator/errors.rb +0 -5
  25. data/lib/predicator/generated_parser.rb +0 -335
  26. data/lib/predicator/lexer.rb +0 -125
  27. data/lib/predicator/nodes.rb +0 -6
  28. data/lib/predicator/nodes/base_node.rb +0 -53
  29. data/lib/predicator/nodes/date_node.rb +0 -13
  30. data/lib/predicator/nodes/fixnum_node.rb +0 -9
  31. data/lib/predicator/nodes/float_node.rb +0 -9
  32. data/lib/predicator/nodes/nil_class_node.rb +0 -25
  33. data/lib/predicator/nodes/string_node.rb +0 -13
  34. data/lib/predicator/predicates.rb +0 -14
  35. data/lib/predicator/predicates/and.rb +0 -20
  36. data/lib/predicator/predicates/between.rb +0 -31
  37. data/lib/predicator/predicates/equal.rb +0 -9
  38. data/lib/predicator/predicates/false.rb +0 -13
  39. data/lib/predicator/predicates/greater_than.rb +0 -9
  40. data/lib/predicator/predicates/greater_than_or_equal.rb +0 -9
  41. data/lib/predicator/predicates/less_than.rb +0 -9
  42. data/lib/predicator/predicates/less_than_or_equal.rb +0 -9
  43. data/lib/predicator/predicates/method.rb +0 -17
  44. data/lib/predicator/predicates/not.rb +0 -20
  45. data/lib/predicator/predicates/not_equal.rb +0 -9
  46. data/lib/predicator/predicates/or.rb +0 -20
  47. data/lib/predicator/predicates/relation.rb +0 -31
  48. data/lib/predicator/predicates/true.rb +0 -13
  49. data/lib/predicator/variable.rb +0 -26
@@ -1,9 +0,0 @@
1
- module Predicator
2
- module Predicates
3
- class NotEqual < Predicator::Predicates::Relation
4
- def compare_values lhs, rhs
5
- lhs != rhs
6
- end
7
- end
8
- end
9
- end
@@ -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
@@ -1,13 +0,0 @@
1
- module Predicator
2
- module Predicates
3
- class True
4
- def satisfied? context=Predicator::Context.new
5
- true
6
- end
7
-
8
- def == other
9
- other.kind_of?(self.class)
10
- end
11
- end
12
- end
13
- end
@@ -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