github.com/ipld/go-ipld-prime@v0.21.0/traversal/selector/exploreRecursiveEdge.go (about) 1 package selector 2 3 import ( 4 "fmt" 5 6 "github.com/ipld/go-ipld-prime/datamodel" 7 ) 8 9 // ExploreRecursiveEdge is a special sentinel value which is used to mark 10 // the end of a sequence started by an ExploreRecursive selector: the recursion 11 // goes back to the initial state of the earlier ExploreRecursive selector, 12 // and proceeds again (with a decremented maxDepth value). 13 // 14 // An ExploreRecursive selector that doesn't contain an ExploreRecursiveEdge 15 // is nonsensical. Containing more than one ExploreRecursiveEdge is valid. 16 // An ExploreRecursiveEdge without an enclosing ExploreRecursive is an error. 17 type ExploreRecursiveEdge struct{} 18 19 // Interests should almost never get called for an ExploreRecursiveEdge selector 20 func (s ExploreRecursiveEdge) Interests() []datamodel.PathSegment { 21 return []datamodel.PathSegment{} 22 } 23 24 // Explore should ultimately never get called for an ExploreRecursiveEdge selector 25 func (s ExploreRecursiveEdge) Explore(n datamodel.Node, p datamodel.PathSegment) (Selector, error) { 26 panic("Traversed Explore Recursive Edge Node With No Parent") 27 } 28 29 // Decide should almost never get called for an ExploreRecursiveEdge selector 30 func (s ExploreRecursiveEdge) Decide(n datamodel.Node) bool { 31 return false 32 } 33 34 // Match always returns false because this is not a matcher 35 func (s ExploreRecursiveEdge) Match(node datamodel.Node) (datamodel.Node, error) { 36 return nil, nil 37 } 38 39 // ParseExploreRecursiveEdge assembles a Selector 40 // from a exploreRecursiveEdge selector node 41 func (pc ParseContext) ParseExploreRecursiveEdge(n datamodel.Node) (Selector, error) { 42 if n.Kind() != datamodel.Kind_Map { 43 return nil, fmt.Errorf("selector spec parse rejected: selector body must be a map") 44 } 45 s := ExploreRecursiveEdge{} 46 for _, parent := range pc.parentStack { 47 if parent.Link(s) { 48 return s, nil 49 } 50 } 51 return nil, fmt.Errorf("selector spec parse rejected: ExploreRecursiveEdge must be beneath ExploreRecursive") 52 }