-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
signaling ADLs in selectors #301
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ed1d924
first pass at signaling ADLs
willscott e8b780d
Merge remote-tracking branch 'origin/master' into feat/adlselection
willscott 2e6e1f7
Respond to code review
willscott da0b8e6
add test for exploreInterpretAs
willscott 6f3ea54
Update traversal/walk_test.go
willscott 5312b3e
better error wrapping
willscott bef2a38
Merge branch 'feat/adlselection' of github.com:ipld/go-ipld-prime int…
willscott ccb336c
consistent test case
willscott aba58f1
Update traversal/selector/exploreInterpretAs.go
willscott 73fc35f
Update traversal/selector/exploreInterpretAs.go
willscott 0b2f841
Merge branch 'master' of github.com:ipld/go-ipld-prime into feat/adls…
willscott f97c150
Merge branch 'feat/adlselection' of github.com:ipld/go-ipld-prime int…
willscott 838d340
update fieldkey per @warpfork request
willscott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package selector | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ipld/go-ipld-prime/datamodel" | ||
) | ||
|
||
type ExploreInterpretAs struct { | ||
next Selector // selector for element we're interested in | ||
adl string // reifier for the ADL we're interested in | ||
} | ||
|
||
// Interests for ExploreIndex is just the index specified by the selector node | ||
func (s ExploreInterpretAs) Interests() []datamodel.PathSegment { | ||
return s.next.Interests() | ||
} | ||
|
||
// Explore returns the node's selector if | ||
// the path matches the index for this selector or nil if not | ||
func (s ExploreInterpretAs) Explore(n datamodel.Node, p datamodel.PathSegment) (Selector, error) { | ||
return s.next, nil | ||
} | ||
|
||
// Decide always returns false because this is not a matcher | ||
func (s ExploreInterpretAs) Decide(n datamodel.Node) bool { | ||
return false | ||
} | ||
|
||
// NamedReifier indicates how this selector expects to Reify the current datamodel.Node. | ||
func (s ExploreInterpretAs) NamedReifier() string { | ||
return s.adl | ||
} | ||
|
||
// Reifiable provides a feature detection interface on selectors to understand when | ||
// and if Reification of the datamodel.node should be attempted when performing traversals. | ||
type Reifiable interface { | ||
NamedReifier() string | ||
} | ||
|
||
// ParseExploreInterpretAs assembles a Selector | ||
// from a ExploreInterpretAs selector node | ||
func (pc ParseContext) ParseExploreInterpretAs(n datamodel.Node) (Selector, error) { | ||
if n.Kind() != datamodel.Kind_Map { | ||
return nil, fmt.Errorf("selector spec parse rejected: selector body must be a map") | ||
} | ||
adlNode, err := n.LookupByString(SelectorKey_As) | ||
if err != nil { | ||
return nil, fmt.Errorf("selector spec parse rejected: the 'as' field must be present in ExploreInterpretAs clause") | ||
} | ||
next, err := n.LookupByString(SelectorKey_Next) | ||
if err != nil { | ||
return nil, fmt.Errorf("selector spec parse rejected: the 'next' field must be present in ExploreInterpretAs clause") | ||
} | ||
selector, err := pc.ParseSelector(next) | ||
if err != nil { | ||
return nil, err | ||
} | ||
adl, err := adlNode.AsString() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return ExploreInterpretAs{selector, adl}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Reviewing out loud, not a change request) This interface is implemented only once and used in only one place, so I wonder if it's necessary. Since the set of types for the compiled selectors[^1] is considered closed, it seems like we could just as well use a concrete type switch?
I'm okay leaving it this way too, because it certainly works, and I don't think it gets in the way, and perhaps someone has an idea that there will be more than one selector clause in the future which asks for a reification to be performed.
[^1] - (I wish we had done #236 by now so I could refer to what I mean by
selectorengine.*
...)