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