Comments (4)
Sorry that I never replied here. To be honest, I've gotten tired of working on the gogrep project for now, and I don't know when I'll actively get back to it. I assume you already saw the refactor branch linked in #32; that was my latest thinking when it comes to a reusable API.
If you want anything other than that, I would suggest to fork or copy code, as that will be the fastest and simplest way. I will probably resurrect/redesign this project at some point in the future, but it's not going to be in the immediate future.
from gogrep.
As an example usage, I have a linter that wants to flag cases where methods of certain types don't call out to their "super" -- that is, where you have a declaration
func (recv *SomeType) SomeMethod(...) ...
which does not call
recv.<something>.SomeMethod(...)
So one part of that is to look for expressions of the form $x.$y.SomeMethod(...)
, but then we want to get back $x
so we can check if it's a reverence to recv
(easy, using go/types
); and more importantly we only want to do the entire search within some function-declaration. Ideally, we might even vary look for a specific $y
depending on the type we're looking at. (Right now we're just doing manual ast traversal -- call, ok := node.(*ast.CallExpr); if !ok { return false }
and repeat -- and it's kind of a mess, which is why I'm looking at gogrep
.)
The former constraint we could do with some loss of fidelity (due to shadowing) with gogrep alone, something like func ($x $_) $y($*_) $*_ { $*_; $x.$_.$y($*_); $*_ }
. But the latter two we really just need types to figure out. I guess in principle we could call out to gogrep to search for each func ($x <specific type>) <specific method-name>($*_) ...
, but that seems at best very slow. Of course, we could ask for a way to search " within ", but that feels like a kludge on both sides: you have to add a bunch of syntax, and we are still very constrained in what we can do.
from gogrep.
Totally understandable and appreciate the guidance! I'll post here if I end up forking.
from gogrep.
@benjaminjkraft I would love to have an API, too.
We might be able to work together on it.
from gogrep.
Related Issues (20)
- Support for searching struct types HOT 2
- Switch to go/packages for module support
- Panic when gogrep is used with "-a 'package/lib/type'" and "-x '$x, _ := $a.Method()'" HOT 3
- Can't match ` '(a << k) | (a >> (32 - k))' ` with wildcards HOT 3
- match constants based on value as well as syntax HOT 2
- Add a gogrep talk link into a readme? HOT 4
- $(_ /regexp/) syntax doesn't seem to be working HOT 1
- $*_ for function return values HOT 1
- Support for $*_ inside function params HOT 1
- Matching of the empty block HOT 1
- $*_ for import specs HOT 2
- $?<name> to match a single optional node HOT 1
- option to skip type checks
- feature request: -single-file param
- more examples HOT 2
- no Go files in ... HOT 2
- Suggestion: Add debug argument to print ast.Node type information
- internal error: go list gives conflicting information for package internal/bytealg HOT 1
- Freezing and deprecating this project HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gogrep.