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