(pred dag.Expr)
| 160 | } |
| 161 | |
| 162 | func newMetadataPruner(pred dag.Expr) dag.Expr { |
| 163 | switch e := pred.(type) { |
| 164 | case *dag.BinaryExpr: |
| 165 | return metaPrunerBinaryExpr(e) |
| 166 | case *dag.RegexpSearchExpr: |
| 167 | this, ok := e.Expr.(*dag.ThisExpr) |
| 168 | if !ok { |
| 169 | return nil |
| 170 | } |
| 171 | prefix := regexpPrefix(e.Pattern) |
| 172 | maxPrefix := regexpMaxPrefix(prefix) |
| 173 | if prefix == "" || maxPrefix == "" { |
| 174 | return nil |
| 175 | } |
| 176 | min := &dag.PrimitiveExpr{Kind: "PrimitiveExpr", Value: sup.QuotedString(prefix)} |
| 177 | max := &dag.PrimitiveExpr{Kind: "PrimitiveExpr", Value: sup.QuotedString(maxPrefix)} |
| 178 | return dag.NewBinaryExpr("and", |
| 179 | compare("<=", min, dag.NewThis(append(slices.Clone(this.Path), "max"))), |
| 180 | compare(">", max, dag.NewThis(append(slices.Clone(this.Path), "min")))) |
| 181 | default: |
| 182 | return nil |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // regexpPrefix returns the prefix of the provided regular expression (if one |
| 187 | // exists) only if the regular expression matches the beginning of a string. |
no test coverage detected