Add type predicates support #31
Comments
Thanks for the suggestion - indeed, completely custom logic isn't supported at the moment. But you can do most of what you're after in two queries with the current program, I believe. At the moment, there are four type filters you can apply - So, in your case, these two queries should do it:
I ran the second and looked at some of the results, and it seems correct. I realise this is all poorly documented (you're going to have to look at |
Going back to custom logic - I had some ideas to add a bit more flexibility, like #26. But I think what I'll instead allow is using gogrep as a library. Then, you'd write a twenty line Go file, which would import gogrep and use it, and which would define its own logic. Think of it like writing a linter, but having to write much less code and having high-level funcs like However, I need to think really hard about what that API would look like, and what those twenty-line Go programs would look like. |
@mvdan, thank you. That's helpful.
About API. |
Apologies for the silence - I have been working on a refactor for weeks, which I have finally finished just now. It was mostly thinking about what design I'll want to have in the long run. I still think custom logic should be done via Go code. I've closed #26, and will work on that soon. As for your example above, I still think that what I gave you is the best that the command line tool should do. If we try to add certain logic into this pipe-like command line tool, such as logical ORs, it's quickly going to become complex. Whereas that logic will be very easy in Go code. After the refactor, here are your new queries:
I'm going to continue the work towards the goal above in the next few weeks. So I'd say this is not the best time to contribute, as the code will rapidly change. However, if you use the tool and find bugs or have ideas for features, please do bring them up :) I also didn't know you had written something similar! Glad to have your input on all this, and it's good that you think this design is decent :) |
Assuming that this issue was just about checking types, I think it can be closed. We can continue the discussion on advanced queries and custom logic in #32. |
It would be useful to search for
$x
of type that have a type that satisfies some predicate.For example, I would like to grep for slices with elements of type
$T
.More precisely, I wanted to find all slicing expressions of form
s[:]
wheres
is a string or slice.This works, but I need to manually substitute
string
with all other types I want to check.With type predicates, it would be possible to describe function that accepts node that is being matched with some kind of context object (that includes types info) and returns
bool
.I have no idea about how to enable user-defined predicates.
(Go plugins doesn't seem first class citizen.)
The text was updated successfully, but these errors were encountered: