Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mvdan/gogrep
Search for Go code using syntax trees
https://github.com/mvdan/gogrep
code go search syntax
Last synced: about 1 month ago
JSON representation
Search for Go code using syntax trees
- Host: GitHub
- URL: https://github.com/mvdan/gogrep
- Owner: mvdan
- License: bsd-3-clause
- Archived: true
- Created: 2017-09-17T11:49:23.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-06-09T09:03:30.000Z (over 3 years ago)
- Last Synced: 2024-08-03T17:17:08.744Z (4 months ago)
- Topics: code, go, search, syntax
- Language: Go
- Homepage:
- Size: 250 KB
- Stars: 475
- Watchers: 11
- Forks: 16
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- go-awesome - gogrep - Browse the Go source code using the syntax tree (Open source library / Word Processing)
README
# gogrep
GO111MODULE=on go get mvdan.cc/gogrep
Search for Go code using syntax trees.
gogrep -x 'if $x != nil { return $x, $*_ }'
Note that this project is **no longer being developed**.
See https://github.com/mvdan/gogrep/issues/64 for more details.### Instructions
usage: gogrep commands [packages]
A command is of the form "-A pattern", where -A is one of:
-x find all nodes matching a pattern
-g discard nodes not matching a pattern
-v discard nodes matching a pattern
-a filter nodes by certain attributes
-s substitute with a given syntax tree
-w write source back to disk or stdoutA pattern is a piece of Go code which may include wildcards. It can be:
a statement (many if split by semicolons)
an expression (many if split by commas)
a type expression
a top-level declaration (var, func, const)
an entire fileWildcards consist of `$` and a name. All wildcards with the same name
within an expression must match the same node, excluding "_". Example:$x.$_ = $x // assignment of self to a field in self
If `*` is before the name, it will match any number of nodes. Example:
fmt.Fprintf(os.Stdout, $*_) // all Fprintfs on stdout
`*` can also be used to match optional nodes, like:
for $*_ { $*_ } // will match all for loops
if $*_; $b { $*_ } // will match all ifs with condition $bThe nodes resulting from applying the commands will be printed line by
line to standard output.Here are two simple examples of the -a operand:
gogrep -x '$x + $y' // will match both numerical and string "+" operations
gogrep -x '$x + $y' -a 'type(string)' // matches only string concatenations