ASTVisitor with stub functions for all of the ast.Node types list in the compiler.ast documentation, with comments describing Node attributes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | import compiler.visitor
class NotImplementedException(Exception): pass
class VisitorSkeleton(compiler.visitor.ASTVisitor):
def visitAdd(self, node):
# Add attributes
# left left operand
# right right operand
raise NotImplementedException('visitAdd')
def visitAnd(self, node):
# And attributes
# nodes list of operands
raise NotImplementedException('visitAnd')
def visitAssAttr(self, node):
# AssAttr attributes
# expr expression on the left-hand side of the dot
# attrname the attribute name, a string
# flags XXX
raise NotImplementedException('visitAssAttr')
def visitAssList(self, node):
# AssList attributes
# nodes list of list elements being assigned to
raise NotImplementedException('visitAssList')
def visitAssName(self, node):
# AssName attributes
# name name being assigned to
# flags XXX
raise NotImplementedException('visitAssName')
def visitAssTuple(self, node):
# AssTuple attributes
# nodes list of tuple elements being assigned to
raise NotImplementedException('visitAssTuple')
def visitAssert(self, node):
# Assert attributes
# test the expression to be tested
# fail the value of the <tt class="exception">AssertionError</tt>
raise NotImplementedException('visitAssert')
def visitAssign(self, node):
# Assign attributes
# nodes a list of assignment targets, one per equal sign
# expr the value being assigned
raise NotImplementedException('visitAssign')
def visitAugAssign(self, node):
# AugAssign attributes
# node
# op
# expr
raise NotImplementedException('visitAugAssign')
def visitBackquote(self, node):
# Backquote attributes
# expr
raise NotImplementedException('visitBackquote')
def visitBitand(self, node):
# Bitand attributes
# nodes
raise NotImplementedException('visitBitand')
def visitBitor(self, node):
# Bitor attributes
# nodes
raise NotImplementedException('visitBitor')
def visitBitxor(self, node):
# Bitxor attributes
# nodes
raise NotImplementedException('visitBitxor')
def visitBreak(self, node):
# Break attributes
raise NotImplementedException('visitBreak')
def visitCallFunc(self, node):
# CallFunc attributes
# node expression for the callee
# args a list of arguments
# star_args the extended *-arg value
# dstar_args the extended **-arg value
raise NotImplementedException('visitCallFunc')
def visitClass(self, node):
# Class attributes
# name the name of the class, a string
# bases a list of base classes
# doc doc string, a string or <code>None</code>
# code the body of the class statement
raise NotImplementedException('visitClass')
def visitCompare(self, node):
# Compare attributes
# expr
# ops
raise NotImplementedException('visitCompare')
def visitConst(self, node):
# Const attributes
# value
raise NotImplementedException('visitConst')
def visitContinue(self, node):
# Continue attributes
raise NotImplementedException('visitContinue')
def visitDict(self, node):
# Dict attributes
# items
raise NotImplementedException('visitDict')
def visitDiscard(self, node):
# Discard attributes
# expr
raise NotImplementedException('visitDiscard')
def visitDiv(self, node):
# Div attributes
# left
# right
raise NotImplementedException('visitDiv')
def visitEllipsis(self, node):
# Ellipsis attributes
raise NotImplementedException('visitEllipsis')
def visitExec(self, node):
# Exec attributes
# expr
# locals
# globals
raise NotImplementedException('visitExec')
def visitFor(self, node):
# For attributes
# assign
# list
# body
# else_
raise NotImplementedException('visitFor')
def visitFrom(self, node):
# From attributes
# modname
# names
raise NotImplementedException('visitFrom')
def visitFunction(self, node):
# Function attributes
# name name used in def, a string
# argnames list of argument names, as strings
# defaults list of default values
# flags xxx
# doc doc string, a string or <code>None</code>
# code the body of the function
raise NotImplementedException('visitFunction')
def visitGetattr(self, node):
# Getattr attributes
# expr
# attrname
raise NotImplementedException('visitGetattr')
def visitGlobal(self, node):
# Global attributes
# names
raise NotImplementedException('visitGlobal')
def visitIf(self, node):
# If attributes
# tests
# else_
raise NotImplementedException('visitIf')
def visitImport(self, node):
# Import attributes
# names
raise NotImplementedException('visitImport')
def visitInvert(self, node):
# Invert attributes
# expr
raise NotImplementedException('visitInvert')
def visitKeyword(self, node):
# Keyword attributes
# name
# expr
raise NotImplementedException('visitKeyword')
def visitLambda(self, node):
# Lambda attributes
# argnames
# defaults
# flags
# code
raise NotImplementedException('visitLambda')
def visitLeftShift(self, node):
# LeftShift attributes
# left
# right
raise NotImplementedException('visitLeftShift')
def visitList(self, node):
# List attributes
# nodes
raise NotImplementedException('visitList')
def visitListComp(self, node):
# ListComp attributes
# expr
# quals
raise NotImplementedException('visitListComp')
def visitListCompFor(self, node):
# ListCompFor attributes
# assign
# list
# ifs
raise NotImplementedException('visitListCompFor')
def visitListCompIf(self, node):
# ListCompIf attributes
# test
raise NotImplementedException('visitListCompIf')
def visitMod(self, node):
# Mod attributes
# left
# right
raise NotImplementedException('visitMod')
def visitModule(self, node):
# Module attributes
# doc doc string, a string or <code>None</code>
# node body of the module, a <tt class="class">Stmt</tt>
raise NotImplementedException('visitModule')
def visitMul(self, node):
# Mul attributes
# left
# right
raise NotImplementedException('visitMul')
def visitName(self, node):
# Name attributes
# name
raise NotImplementedException('visitName')
def visitNot(self, node):
# Not attributes
# expr
raise NotImplementedException('visitNot')
def visitOr(self, node):
# Or attributes
# nodes
raise NotImplementedException('visitOr')
def visitPass(self, node):
# Pass attributes
raise NotImplementedException('visitPass')
def visitPower(self, node):
# Power attributes
# left
# right
raise NotImplementedException('visitPower')
def visitPrint(self, node):
# Print attributes
# nodes
# dest
raise NotImplementedException('visitPrint')
def visitPrintnl(self, node):
# Printnl attributes
# nodes
# dest
raise NotImplementedException('visitPrintnl')
def visitRaise(self, node):
# Raise attributes
# expr1
# expr2
# expr3
raise NotImplementedException('visitRaise')
def visitReturn(self, node):
# Return attributes
# value
raise NotImplementedException('visitReturn')
def visitRightShift(self, node):
# RightShift attributes
# left
# right
raise NotImplementedException('visitRightShift')
def visitSlice(self, node):
# Slice attributes
# expr
# flags
# lower
# upper
raise NotImplementedException('visitSlice')
def visitSliceobj(self, node):
# Sliceobj attributes
# nodes list of statements
raise NotImplementedException('visitSliceobj')
def visitStmt(self, node):
# Stmt attributes
# nodes
raise NotImplementedException('visitStmt')
def visitSub(self, node):
# Sub attributes
# left
# right
raise NotImplementedException('visitSub')
def visitSubscript(self, node):
# Subscript attributes
# expr
# flags
# subs
raise NotImplementedException('visitSubscript')
def visitTryExcept(self, node):
# TryExcept attributes
# body
# handlers
# else_
raise NotImplementedException('visitTryExcept')
def visitTryFinally(self, node):
# TryFinally attributes
# body
# final
raise NotImplementedException('visitTryFinally')
def visitTuple(self, node):
# Tuple attributes
# nodes
raise NotImplementedException('visitTuple')
def visitUnaryAdd(self, node):
# UnaryAdd attributes
# expr
raise NotImplementedException('visitUnaryAdd')
def visitUnarySub(self, node):
# UnarySub attributes
# expr
raise NotImplementedException('visitUnarySub')
def visitWhile(self, node):
# While attributes
# test
# body
# else_
raise NotImplementedException('visitWhile')
def visitYield(self, node):
# Yield attributes
# value
raise NotImplementedException('visitYield')
|
A handy starting point for aspiring authors of ASTVisitor subclasses. Current as of Python 2.3.4.
Tags: oop