paul@2 | 1 | .TH "ASTGREP" "1" |
paul@2 | 2 | |
paul@2 | 3 | .\" Manual page prepared by: |
paul@2 | 4 | .\" |
paul@2 | 5 | .\" Paul Boddie <paul@boddie.org.uk> |
paul@2 | 6 | .\" |
paul@2 | 7 | .\" To view this file while editing, run it through groff: |
paul@2 | 8 | .\" groff -Tascii -man astgrep.1 | less |
paul@2 | 9 | |
paul@2 | 10 | .SH NAME |
paul@2 | 11 | astgrep \- grep/search through Python abstract syntax trees |
paul@2 | 12 | .SH SYNOPSIS |
paul@2 | 13 | .B astgrep |
paul@2 | 14 | [options] \-t TERM_TYPE [ \-e PATTERN ] ( \-r DIRECTORY | FILE ) |
paul@2 | 15 | .SH DESCRIPTION |
paul@2 | 16 | \fBastgrep\fR is a program which searches through Python source files for |
paul@2 | 17 | textual information of a specific type. Instead of matching a search term or |
paul@2 | 18 | expression, \fIPATTERN\fR, to all text in a program, as \fBgrep\fR would do, |
paul@2 | 19 | \fBastgrep\fR matches only tokens in the program having a particular type, |
paul@2 | 20 | specified using \fITERM_TYPE\fR, such as names or constants. |
paul@2 | 21 | |
paul@2 | 22 | Like \fBgrep\fR, a single \fIFILE\fR or a number of files within a directory |
paul@2 | 23 | hierarchy, \fIDIRECTORY\fR, can be searched, with the occurrences listed from |
paul@2 | 24 | each file. |
paul@2 | 25 | .SH COMMAND LINE OPTIONS |
paul@2 | 26 | .TP |
paul@2 | 27 | .BR \-n , " \-\-line-number" |
paul@2 | 28 | Show the line number of each match. |
paul@2 | 29 | .TP |
paul@2 | 30 | .BR \-p , " \-\-print-token" |
paul@2 | 31 | Show the matching token for each match. |
paul@2 | 32 | .TP |
paul@2 | 33 | \fB\-t\fR, \fB\-\-type\fR=\fITERM_TYPE\fR |
paul@2 | 34 | Indicate the type of token to be matched. |
paul@2 | 35 | .TP |
paul@2 | 36 | \fB\-e\fR, \fB\-\-regexp\fR=\fIPATTERN\fR |
paul@2 | 37 | Use \fIPATTERN\fR as the term to search for. |
paul@2 | 38 | .TP |
paul@2 | 39 | \fB\-r\fR, \fB\-R\fR, \fB\-\-recursive\fR \fIDIRECTORY\fR |
paul@2 | 40 | Search Python files within \fIDIRECTORY\fR, recursively. |
paul@2 | 41 | .SH TERM TYPES |
paul@2 | 42 | Details of term types can be found in the "AST Nodes" section of the Python |
paul@2 | 43 | Library Reference or by using \fBpydoc\fR to inspect the node classes in the |
paul@2 | 44 | \fBcompiler.ast\fR Python module: |
paul@2 | 45 | .RS 4 |
paul@2 | 46 | .PP |
paul@2 | 47 | .PD 0 |
paul@2 | 48 | .B pydoc compiler.ast |
paul@2 | 49 | .RE |
paul@2 | 50 | .PD |
paul@2 | 51 | .SH EXAMPLES |
paul@2 | 52 | Search for classes whose name contains \fINode\fR in a particular file: |
paul@2 | 53 | .RS 4 |
paul@2 | 54 | .PP |
paul@2 | 55 | .PD 0 |
paul@2 | 56 | .B astgrep -t Class -e Node libxml2dom/__init__.py |
paul@2 | 57 | .RE |
paul@2 | 58 | .PD |
paul@2 | 59 | .PP |
paul@2 | 60 | Search for functions or methods whose name starts with \fIvisit\fR in a |
paul@2 | 61 | particular directory hierarchy, \fImicropython\fR, showing the name of the |
paul@2 | 62 | matching functions in the output: |
paul@2 | 63 | .RS 4 |
paul@2 | 64 | .PP |
paul@2 | 65 | .PD 0 |
paul@2 | 66 | .B astgrep -p -t Function -e '^visit' -r micropython |
paul@2 | 67 | .RE |
paul@2 | 68 | .PD |
paul@2 | 69 | .PP |
paul@2 | 70 | Search for accesses of attributes having the exact name \fI_node\fR in a |
paul@2 | 71 | particular directory hierarchy, \fIlibxml2dom\fR, showing the line number of |
paul@2 | 72 | each match in the output: |
paul@2 | 73 | .RS 4 |
paul@2 | 74 | .PP |
paul@2 | 75 | .PD 0 |
paul@2 | 76 | .B astgrep -n -t Getattr -e '^_node$' -r libxml2dom |
paul@2 | 77 | .RE |
paul@2 | 78 | .PD |
paul@2 | 79 | .SH SEE ALSO |
paul@2 | 80 | .BR python (1), |
paul@2 | 81 | .BR grep (1) |
paul@2 | 82 | .PP |
paul@2 | 83 | astgrep |
paul@2 | 84 | .I http://www.boddie.org.uk/python/astgrep.html |
paul@2 | 85 | .PD |
paul@2 | 86 | .SH COPYRIGHT |
paul@2 | 87 | Copyright \(co 2008 Paul Boddie; License GNU GPL version 3 |