gogrep

利用语法树搜索Go代码。(Search for Go code using syntax trees)

  • 所有者: mvdan/gogrep
  • 平台: Linux, Mac, Windows
  • 許可證: BSD 3-Clause "New" or "Revised" License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

gogrep

GO111MODULE=on go get mvdan.cc/gogrep

Search for Go code using syntax trees. Work in progress.

gogrep -x 'if $x != nil { return $x, $*_ }'

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 stdout

A 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 file

Wildcards 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 $b

The 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

概覽

名稱與所有者mvdan/gogrep
主編程語言Go
編程語言Go (語言數: 1)
平台Linux, Mac, Windows
許可證BSD 3-Clause "New" or "Revised" License
發布數0
創建於2017-09-17 11:49:23
推送於2021-06-09 09:03:30
最后一次提交2021-06-09 10:03:16
星數473
關注者數11
派生數16
提交數197
已啟用問題?
問題數51
打開的問題數14
拉請求數11
打開的拉請求數1
關閉的拉請求數1
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?
去到頂部