Recently I shared my Survey <https://github.com/MichaelTJones/survey>
program, saying that it was a sidestep from what I was working on but
interesting and hopefully useful to others. Here is the real thing, named
gg, that Survey was a test for. GG combines lexical analysis and Go-native
pattern matching to extend grep(1) for Go developers

GG is smart; the search is restricted, seeking matches only in chosen token
classes.  A search in number literals can match values in addition to
patterns: "v 255" matches the numeric value 255 in source code as
0b1111_1111, 0377, 0o377, 255, 0xff, etc.  Go's linear-time regular
expression engine is Unicode-aware and supports many extensions: numbers in
identifiers are found with "gg i [0-9]" or "gg i [\d]", find comments with
math symbols using "gg c \p{Sm}", and Greek in strings via "gg s \p{Greek}".

GG is fast, uses all cores, understands filesystem hierarchies, archives,
and compression schemes, and is general like grep while focused in a new
way: find within package names, identifiers, types, strings, comments, and
more.

Source code:
https://github.com/MichaelTJones/gg

Man page (all is explained here):
https://github.com/MichaelTJones/gg/blob/master/gg.pdf

Examples:

Search the Go 1.13 source code for strings containing Megalosaurus, but not
comments:

$ gg -r s Megalosaurus ~/go
/Users/mtj/go/src/cmd/link/link_test.go:`text:"London. Michaelmas term
lately over, and the Lord Chancellor sitting in Lincoln’s Inn Hall.
Implacable November weather. As much mud in the streets as if the waters
had but newly retired from the face of the earth, and it would not be
wonderful to meet a Megalosaurus, forty feet long or so, waddling like an
elephantine lizard up Holborn Hill. ...


Search the Go 1.13 source code for identifiers with greek letters (but not
strings or comments):

$ gg -r i '\p{Greek}' ~/go
/Users/mtj/go/src/encoding/json/encode_test.go: A0, À, Aβ int
/Users/mtj/go/src/math/cmplx/polar.go:func Polar(x complex128) (r, θ
float64) {
/Users/mtj/go/src/math/cmplx/rect.go:func Rect(r, θ float64) complex128 {
/Users/mtj/go/src/math/cmplx/rect.go: s, c := math.Sincos(θ)
/Users/mtj/go/src/math/rand/rand_test.go: var χ2 float64
:


Best to all,
Michael

-- 

*Michael T. jonesmichael.jo...@gmail.com <michael.jo...@gmail.com>*

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALoEmQz-KdFaWjS%2Bfyd-QQS4LEgYmnofiZNmugnoQ7sNaG0HEA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to