MCPcopy
hub / github.com/expr-lang/expr / builtinNode

Method builtinNode

checker/checker.go:695–946  ·  view source on GitHub ↗
(node *ast.BuiltinNode)

Source from the content-addressed store, hash-verified

693}
694
695func (v *Checker) builtinNode(node *ast.BuiltinNode) Nature {
696 switch node.Name {
697 case "all", "none", "any", "one":
698 collection := v.visit(node.Arguments[0])
699 collection = collection.Deref(&v.config.NtCache)
700 if !collection.IsArray() && !collection.IsUnknown(&v.config.NtCache) {
701 return v.error(node.Arguments[0], "builtin %v takes only array (got %v)", node.Name, collection.String())
702 }
703
704 v.begin(collection)
705 predicate := v.visit(node.Arguments[1])
706 v.end()
707
708 if predicate.IsFunc() &&
709 predicate.NumOut() == 1 &&
710 predicate.NumIn() == 1 && predicate.IsFirstArgUnknown(&v.config.NtCache) {
711
712 predicateOut := predicate.Out(&v.config.NtCache, 0)
713 if !predicateOut.IsBool() && !predicateOut.IsUnknown(&v.config.NtCache) {
714 return v.error(node.Arguments[1], "predicate should return boolean (got %s)", predicateOut.String())
715 }
716 return v.config.NtCache.FromType(boolType)
717 }
718 return v.error(node.Arguments[1], "predicate should has one input and one output param")
719
720 case "filter":
721 collection := v.visit(node.Arguments[0])
722 collection = collection.Deref(&v.config.NtCache)
723 if !collection.IsArray() && !collection.IsUnknown(&v.config.NtCache) {
724 return v.error(node.Arguments[0], "builtin %v takes only array (got %v)", node.Name, collection.String())
725 }
726
727 v.begin(collection)
728 predicate := v.visit(node.Arguments[1])
729 v.end()
730
731 if predicate.IsFunc() &&
732 predicate.NumOut() == 1 &&
733 predicate.NumIn() == 1 && predicate.IsFirstArgUnknown(&v.config.NtCache) {
734
735 predicateOut := predicate.Out(&v.config.NtCache, 0)
736 if !predicateOut.IsBool() && !predicateOut.IsUnknown(&v.config.NtCache) {
737 return v.error(node.Arguments[1], "predicate should return boolean (got %s)", predicateOut.String())
738 }
739 if collection.IsUnknown(&v.config.NtCache) {
740 return v.config.NtCache.FromType(arrayType)
741 }
742 collection = collection.Elem(&v.config.NtCache)
743 return collection.MakeArrayOf(&v.config.NtCache)
744 }
745 return v.error(node.Arguments[1], "predicate should has one input and one output param")
746
747 case "map":
748 collection := v.visit(node.Arguments[0])
749 collection = collection.Deref(&v.config.NtCache)
750 if !collection.IsArray() && !collection.IsUnknown(&v.config.NtCache) {
751 return v.error(node.Arguments[0], "builtin %v takes only array (got %v)", node.Name, collection.String())
752 }

Callers 1

visitMethod · 0.95

Implementers 3

Configconf/config.go
Checkerchecker/checker.go
OperatorOverloadingpatcher/operator_override.go

Calls 15

visitMethod · 0.95
errorMethod · 0.95
beginMethod · 0.95
endMethod · 0.95
checkBuiltinGetMethod · 0.95
checkFunctionMethod · 0.95
DerefMethod · 0.80
IsArrayMethod · 0.80
IsUnknownMethod · 0.80
IsFuncMethod · 0.80
NumOutMethod · 0.80
NumInMethod · 0.80

Tested by

no test coverage detected