admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | <?xml version="1.0" encoding="ascii"?> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| 3 | "DTD/xhtml1-transitional.dtd"> |
| 4 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 5 | <head> |
| 6 | <title>TestON.core.ast.NodeTransformer</title> |
| 7 | <link rel="stylesheet" href="epydoc.css" type="text/css" /> |
| 8 | <script type="text/javascript" src="epydoc.js"></script> |
| 9 | </head> |
| 10 | |
| 11 | <body bgcolor="white" text="black" link="blue" vlink="#204080" |
| 12 | alink="#204080"> |
| 13 | <!-- ==================== NAVIGATION BAR ==================== --> |
| 14 | <table class="navbar" border="0" width="100%" cellpadding="0" |
| 15 | bgcolor="#a0c0ff" cellspacing="0"> |
| 16 | <tr valign="middle"> |
| 17 | <!-- Home link --> |
| 18 | <th> <a |
| 19 | href="TestON-module.html">Home</a> </th> |
| 20 | |
| 21 | <!-- Tree link --> |
| 22 | <th> <a |
| 23 | href="module-tree.html">Trees</a> </th> |
| 24 | |
| 25 | <!-- Index link --> |
| 26 | <th> <a |
| 27 | href="identifier-index.html">Indices</a> </th> |
| 28 | |
| 29 | <!-- Help link --> |
| 30 | <th> <a |
| 31 | href="help.html">Help</a> </th> |
| 32 | |
| 33 | <th class="navbar" width="100%"></th> |
| 34 | </tr> |
| 35 | </table> |
| 36 | <table width="100%" cellpadding="0" cellspacing="0"> |
| 37 | <tr valign="top"> |
| 38 | <td width="100%"> |
| 39 | <span class="breadcrumbs"> |
| 40 | <a href="TestON-module.html">Package TestON</a> :: |
| 41 | <a href="TestON.core-module.html">Package core</a> :: |
| 42 | <a href="TestON.core.ast-module.html">Module ast</a> :: |
| 43 | Class NodeTransformer |
| 44 | </span> |
| 45 | </td> |
| 46 | <td> |
| 47 | <table cellpadding="0" cellspacing="0"> |
| 48 | <!-- hide/show private --> |
| 49 | <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink" |
| 50 | onclick="toggle_private();">hide private</a>]</span></td></tr> |
| 51 | <tr><td align="right"><span class="options" |
| 52 | >[<a href="frames.html" target="_top">frames</a |
| 53 | >] | <a href="TestON.core.ast.NodeTransformer-class.html" |
| 54 | target="_top">no frames</a>]</span></td></tr> |
| 55 | </table> |
| 56 | </td> |
| 57 | </tr> |
| 58 | </table> |
| 59 | <!-- ==================== CLASS DESCRIPTION ==================== --> |
| 60 | <h1 class="epydoc">Class NodeTransformer</h1><p class="nomargin-top"><span class="codelink"><a href="TestON.core.ast-pysrc.html#NodeTransformer">source code</a></span></p> |
| 61 | <pre class="base-tree"> |
| 62 | object --+ |
| 63 | | |
| 64 | <a href="TestON.core.ast.NodeVisitor-class.html">NodeVisitor</a> --+ |
| 65 | | |
| 66 | <strong class="uidshort">NodeTransformer</strong> |
| 67 | </pre> |
| 68 | |
| 69 | <hr /> |
| 70 | <p>A :class:`NodeVisitor` subclass that walks the abstract syntax tree |
| 71 | and allows modification of nodes.</p> |
| 72 | <p>The `NodeTransformer` will walk the AST and use the return value of |
| 73 | the visitor methods to replace or remove the old node. If the return |
| 74 | value of the visitor method is ``None``, the node will be removed from |
| 75 | its location, otherwise it is replaced with the return value. The return |
| 76 | value may be the original node in which case no replacement takes |
| 77 | place.</p> |
| 78 | <p>Here is an example transformer that rewrites all occurrences of name |
| 79 | lookups (``foo``) to ``data['foo']``:</p> |
| 80 | <pre class="literalblock"> |
| 81 | class RewriteName(NodeTransformer): |
| 82 | |
| 83 | def visit_Name(self, node): |
| 84 | return copy_location(Subscript( |
| 85 | value=Name(id='data', ctx=Load()), |
| 86 | slice=Index(value=Str(s=node.id)), |
| 87 | ctx=node.ctx |
| 88 | ), node) |
| 89 | </pre> |
| 90 | <p>Keep in mind that if the node you're operating on has child nodes you |
| 91 | must either transform the child nodes yourself or call the |
| 92 | :meth:`generic_visit` method for the node first.</p> |
| 93 | <p>For nodes that were part of a collection of statements (that applies |
| 94 | to all statement nodes), the visitor may also return a list of nodes |
| 95 | rather than just a single node.</p> |
| 96 | <p>Usually you use the transformer like this:</p> |
| 97 | <pre class="literalblock"> |
| 98 | node = YourTransformer().visit(node) |
| 99 | </pre> |
| 100 | |
| 101 | <!-- ==================== INSTANCE METHODS ==================== --> |
| 102 | <a name="section-InstanceMethods"></a> |
| 103 | <table class="summary" border="1" cellpadding="3" |
| 104 | cellspacing="0" width="100%" bgcolor="white"> |
| 105 | <tr bgcolor="#70b0f0" class="table-header"> |
| 106 | <td colspan="2" class="table-header"> |
| 107 | <table border="0" cellpadding="0" cellspacing="0" width="100%"> |
| 108 | <tr valign="top"> |
| 109 | <td align="left"><span class="table-header">Instance Methods</span></td> |
| 110 | <td align="right" valign="top" |
| 111 | ><span class="options">[<a href="#section-InstanceMethods" |
| 112 | class="privatelink" onclick="toggle_private();" |
| 113 | >hide private</a>]</span></td> |
| 114 | </tr> |
| 115 | </table> |
| 116 | </td> |
| 117 | </tr> |
| 118 | <tr> |
| 119 | <td width="15%" align="right" valign="top" class="summary"> |
| 120 | <span class="summary-type"> </span> |
| 121 | </td><td class="summary"> |
| 122 | <table width="100%" cellpadding="0" cellspacing="0" border="0"> |
| 123 | <tr> |
| 124 | <td><span class="summary-sig"><a href="TestON.core.ast.NodeTransformer-class.html#generic_visit" class="summary-sig-name">generic_visit</a>(<span class="summary-sig-arg">self</span>, |
| 125 | <span class="summary-sig-arg">node</span>)</span><br /> |
| 126 | Called if no explicit visitor function exists for a node.</td> |
| 127 | <td align="right" valign="top"> |
| 128 | <span class="codelink"><a href="TestON.core.ast-pysrc.html#NodeTransformer.generic_visit">source code</a></span> |
| 129 | |
| 130 | </td> |
| 131 | </tr> |
| 132 | </table> |
| 133 | |
| 134 | </td> |
| 135 | </tr> |
| 136 | <tr> |
| 137 | <td colspan="2" class="summary"> |
| 138 | <p class="indent-wrapped-lines"><b>Inherited from <code><a href="TestON.core.ast.NodeVisitor-class.html">NodeVisitor</a></code></b>: |
| 139 | <code><a href="TestON.core.ast.NodeVisitor-class.html#visit">visit</a></code> |
| 140 | </p> |
| 141 | <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>: |
| 142 | <code>__delattr__</code>, |
| 143 | <code>__format__</code>, |
| 144 | <code>__getattribute__</code>, |
| 145 | <code>__hash__</code>, |
| 146 | <code>__init__</code>, |
| 147 | <code>__new__</code>, |
| 148 | <code>__reduce__</code>, |
| 149 | <code>__reduce_ex__</code>, |
| 150 | <code>__repr__</code>, |
| 151 | <code>__setattr__</code>, |
| 152 | <code>__sizeof__</code>, |
| 153 | <code>__str__</code>, |
| 154 | <code>__subclasshook__</code> |
| 155 | </p> |
| 156 | </td> |
| 157 | </tr> |
| 158 | </table> |
| 159 | <!-- ==================== PROPERTIES ==================== --> |
| 160 | <a name="section-Properties"></a> |
| 161 | <table class="summary" border="1" cellpadding="3" |
| 162 | cellspacing="0" width="100%" bgcolor="white"> |
| 163 | <tr bgcolor="#70b0f0" class="table-header"> |
| 164 | <td colspan="2" class="table-header"> |
| 165 | <table border="0" cellpadding="0" cellspacing="0" width="100%"> |
| 166 | <tr valign="top"> |
| 167 | <td align="left"><span class="table-header">Properties</span></td> |
| 168 | <td align="right" valign="top" |
| 169 | ><span class="options">[<a href="#section-Properties" |
| 170 | class="privatelink" onclick="toggle_private();" |
| 171 | >hide private</a>]</span></td> |
| 172 | </tr> |
| 173 | </table> |
| 174 | </td> |
| 175 | </tr> |
| 176 | <tr> |
| 177 | <td colspan="2" class="summary"> |
| 178 | <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>: |
| 179 | <code>__class__</code> |
| 180 | </p> |
| 181 | </td> |
| 182 | </tr> |
| 183 | </table> |
| 184 | <!-- ==================== METHOD DETAILS ==================== --> |
| 185 | <a name="section-MethodDetails"></a> |
| 186 | <table class="details" border="1" cellpadding="3" |
| 187 | cellspacing="0" width="100%" bgcolor="white"> |
| 188 | <tr bgcolor="#70b0f0" class="table-header"> |
| 189 | <td colspan="2" class="table-header"> |
| 190 | <table border="0" cellpadding="0" cellspacing="0" width="100%"> |
| 191 | <tr valign="top"> |
| 192 | <td align="left"><span class="table-header">Method Details</span></td> |
| 193 | <td align="right" valign="top" |
| 194 | ><span class="options">[<a href="#section-MethodDetails" |
| 195 | class="privatelink" onclick="toggle_private();" |
| 196 | >hide private</a>]</span></td> |
| 197 | </tr> |
| 198 | </table> |
| 199 | </td> |
| 200 | </tr> |
| 201 | </table> |
| 202 | <a name="generic_visit"></a> |
| 203 | <div> |
| 204 | <table class="details" border="1" cellpadding="3" |
| 205 | cellspacing="0" width="100%" bgcolor="white"> |
| 206 | <tr><td> |
| 207 | <table width="100%" cellpadding="0" cellspacing="0" border="0"> |
| 208 | <tr valign="top"><td> |
| 209 | <h3 class="epydoc"><span class="sig"><span class="sig-name">generic_visit</span>(<span class="sig-arg">self</span>, |
| 210 | <span class="sig-arg">node</span>)</span> |
| 211 | </h3> |
| 212 | </td><td align="right" valign="top" |
| 213 | ><span class="codelink"><a href="TestON.core.ast-pysrc.html#NodeTransformer.generic_visit">source code</a></span> |
| 214 | </td> |
| 215 | </tr></table> |
| 216 | |
| 217 | <p>Called if no explicit visitor function exists for a node.</p> |
| 218 | <dl class="fields"> |
| 219 | <dt>Overrides: |
| 220 | <a href="TestON.core.ast.NodeVisitor-class.html#generic_visit">NodeVisitor.generic_visit</a> |
| 221 | <dd><em class="note">(inherited documentation)</em></dd> |
| 222 | </dt> |
| 223 | </dl> |
| 224 | </td></tr></table> |
| 225 | </div> |
| 226 | <br /> |
| 227 | <!-- ==================== NAVIGATION BAR ==================== --> |
| 228 | <table class="navbar" border="0" width="100%" cellpadding="0" |
| 229 | bgcolor="#a0c0ff" cellspacing="0"> |
| 230 | <tr valign="middle"> |
| 231 | <!-- Home link --> |
| 232 | <th> <a |
| 233 | href="TestON-module.html">Home</a> </th> |
| 234 | |
| 235 | <!-- Tree link --> |
| 236 | <th> <a |
| 237 | href="module-tree.html">Trees</a> </th> |
| 238 | |
| 239 | <!-- Index link --> |
| 240 | <th> <a |
| 241 | href="identifier-index.html">Indices</a> </th> |
| 242 | |
| 243 | <!-- Help link --> |
| 244 | <th> <a |
| 245 | href="help.html">Help</a> </th> |
| 246 | |
| 247 | <th class="navbar" width="100%"></th> |
| 248 | </tr> |
| 249 | </table> |
| 250 | <table border="0" cellpadding="0" cellspacing="0" width="100%%"> |
| 251 | <tr> |
| 252 | <td align="left" class="footer"> |
| 253 | Generated by Epydoc 3.0.1 on Mon Mar 11 12:56:26 2013 |
| 254 | </td> |
| 255 | <td align="right" class="footer"> |
| 256 | <a target="mainFrame" href="http://epydoc.sourceforge.net" |
| 257 | >http://epydoc.sourceforge.net</a> |
| 258 | </td> |
| 259 | </tr> |
| 260 | </table> |
| 261 | |
| 262 | <script type="text/javascript"> |
| 263 | <!-- |
| 264 | // Private objects are initially displayed (because if |
| 265 | // javascript is turned off then we want them to be |
| 266 | // visible); but by default, we want to hide them. So hide |
| 267 | // them unless we have a cookie that says to show them. |
| 268 | checkCookie(); |
| 269 | // --> |
| 270 | </script> |
| 271 | </body> |
| 272 | </html> |