next up previous contents index
Next: 3.9.4 Exceptions and Error Up: 3.9 Built-in Module parser Previous: 3.9.2 Converting AST Objects

3.9.3 Queries on AST Objects

Two functions are provided which allow an application to determine if an AST was create as an expression or a suite. Neither of these functions can be used to determine if an AST was created from source code via expr() or suite() or from a parse tree via sequence2ast().

isexpr(ast)
When ast represents an 'eval' form, this function returns a true value (1), otherwise it returns false (0). This is useful, since code objects normally cannot be queried for this information using existing built-in functions. Note that the code objects created by compileast() cannot be queried like this either, and are identical to those created by the built-in compile() function.

issuite(ast)
This function mirrors isexpr() in that it reports whether an AST object represents an 'exec' form, commonly known as a ``suite.'' It is not safe to assume that this function is equivelent to not isexpr(ast), as additional syntactic fragments may be supported in the future.



guido@cnri.reston.va.us