Prechádzať zdrojové kódy

Add ContradictionOp to v2.1 filters

Signed-off-by: Michael Dresser <michaelmdresser@gmail.com>
Michael Dresser 3 rokov pred
rodič
commit
b79c435c0a

+ 11 - 0
pkg/filter21/ast/ops.go

@@ -52,6 +52,9 @@ const (
 	// FilterOpVoid is base-depth operator that is used for an empty filter
 	FilterOpVoid = "void"
 
+	// FilterOpContradiction is a base-depth operator that filters all data.
+	FilterOpContradiction = "contradiction"
+
 	// FilterOpAnd is an operator that succeeds if all parameters succeed.
 	FilterOpAnd = "and"
 
@@ -70,6 +73,14 @@ func (_ *VoidOp) Op() FilterOp {
 	return FilterOpVoid
 }
 
+// ContradictionOp is a base-depth operator that filters all data.
+type ContradictionOp struct{}
+
+// Op returns the FilterOp enumeration value for the operator.
+func (_ *ContradictionOp) Op() FilterOp {
+	return FilterOpContradiction
+}
+
 // AndOp is a filter operation that contains a flat list of nodes which should all resolve
 // to true in order for the result to be true.
 type AndOp struct {

+ 6 - 2
pkg/filter21/ast/walker.go

@@ -220,7 +220,6 @@ func Clone(filter FilterNode) FilterNode {
 					result = currentOps.Pop()
 				}
 			}
-
 		case *NotOp:
 			if state == TraversalStateEnter {
 				currentOps.Push(&NotOp{})
@@ -232,7 +231,12 @@ func Clone(filter FilterNode) FilterNode {
 					result = currentOps.Pop()
 				}
 			}
-
+		case *ContradictionOp:
+			if currentOps.Length() == 0 {
+				result = &ContradictionOp{}
+			} else {
+				currentOps.Top().Add(&ContradictionOp{})
+			}
 		case *EqualOp:
 			var field Field = *n.Left.Field
 			sm := &EqualOp{

+ 6 - 1
pkg/filter21/matcher/compiler.go

@@ -100,7 +100,12 @@ func (mc *MatchCompiler[T]) Compile(filter ast.FilterNode) (Matcher[T], error) {
 					result = currentOps.Pop()
 				}
 			}
-
+		case *ast.ContradictionOp:
+			if currentOps.Length() == 0 {
+				result = &AllCut[T]{}
+			} else {
+				currentOps.Top().Add(&AllCut[T]{})
+			}
 		case *ast.EqualOp:
 			sm := mc.stringMatcher.NewStringMatcher(n.Op(), n.Left, n.Right)
 			if currentOps.Length() == 0 {