HasMacroExpander expands the input call arguments into a presence test, e.g. has( .field)
(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr)
| 210 | |
| 211 | // HasMacroExpander expands the input call arguments into a presence test, e.g. has(<operand>.field) |
| 212 | func HasMacroExpander(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error) { |
| 213 | ph, err := toParserHelper(meh) |
| 214 | if err != nil { |
| 215 | return nil, err |
| 216 | } |
| 217 | arg, err := adaptToExpr(args[0]) |
| 218 | if err != nil { |
| 219 | return nil, err |
| 220 | } |
| 221 | if arg.Kind() == ast.SelectKind { |
| 222 | s := arg.AsSelect() |
| 223 | return adaptToProto(ph.NewPresenceTest(s.Operand(), s.FieldName())) |
| 224 | } |
| 225 | return nil, ph.NewError(arg.ID(), "invalid argument to has() macro") |
| 226 | } |
| 227 | |
| 228 | // ExistsMacroExpander expands the input call arguments into a comprehension that returns true if any of the |
| 229 | // elements in the range match the predicate expressions: |