Package SloppyCell :: Package ExprManip :: Module AST
[hide private]

Module AST

source code

Functions [hide private]
 
_node_equal(self, other)
Return whether self and other represent the same expressions.
source code
 
strip_parse(expr)
Return an abstract syntax tree (AST) for an expression.
source code
 
ast2str(ast, outer=_FARTHEST_OUT, adjust=0)
Return the string representation of an AST.
source code
 
_need_parens(outer, inner, adjust)
Return whether or not the inner AST needs parentheses when enclosed by the outer.
source code
 
_collect_num_denom(ast, nums, denoms)
Append to nums and denoms, respectively, the nodes in the numerator and denominator of an AST.
source code
 
_collect_pos_neg(ast, poss, negs)
Append to poss and negs, respectively, the nodes in AST with positive and negative factors from a addition/subtraction chain.
source code
 
_make_product(terms)
Return an AST expressing the product of all the terms.
source code
 
recurse_down_tree(ast, func, args=()) source code
Variables [hide private]
  TINY = 1e-12
  _OP_ORDER = {Name: 0, Const: 0, CallFunc: 0, Subscript: 0, Sli...
  _FARTHEST_OUT = Discard(None)
  _node_attrs = {Name:(), Const:(), Add:('left', 'right'), Sub:(...

Imports: compiler, Slice, Const, Raise, For, AssTuple, Mul, Invert, RightShift, AssList, Add, Dict, flatten, UnaryAdd, Import, Print, Ellipsis, Sliceobj, Decorators, Subscript, Name, Node, Assert, Return, Power, Exec, CO_VARKEYWORDS, GenExprFor, Stmt, Or, Break, CO_VARARGS, Bitand, FloorDiv, Tuple, Bitxor, TryExcept, Not, nodes, EmptyNode, With, Class, Mod, Printnl, Function, TryFinally, GenExprIf, While, AssAttr, Keyword, GenExpr, Module, AugAssign, List, Yield, IfExp, AssName, From, Continue, Backquote, Discard, Div, Expression, Assign, Lambda, And, LeftShift, Compare, GenExprInner, CallFunc, Global, Getattr, ListCompIf, Sub, ListCompFor, flatten_nodes, Pass, UnarySub, Bitor, ListComp, If


Function Details [hide private]

_node_equal(self, other)

source code 

Return whether self and other represent the same expressions.

Unfortunately, the Node class in Python 2.3 doesn't define ==, so
we need to write our own.

strip_parse(expr)

source code 

Return an abstract syntax tree (AST) for an expression.

This removes the enclosing cruft from a call to compiler.parse(expr)

ast2str(ast, outer=_FARTHEST_OUT, adjust=0)

source code 

Return the string representation of an AST.

outer: The AST's 'parent' node, used to determine whether or not to 
    enclose the result in parentheses. The default of _FARTHEST_OUT will
    never enclose the result in parentheses.

adjust: A numerical value to adjust the priority of this ast for
    particular cases. For example, the denominator of a '/' needs 
    parentheses in more cases than does the numerator.

_need_parens(outer, inner, adjust)

source code 

Return whether or not the inner AST needs parentheses when enclosed by the
outer.

adjust: A numerical value to adjust the priority of this ast for
    particular cases. For example, the denominator of a '/' needs 
    parentheses in more cases than does the numerator.


Variables Details [hide private]

_OP_ORDER

Value:
{Name: 0, Const: 0, CallFunc: 0, Subscript: 0, Slice: 0, Sliceobj: 0, \
Power: 3, UnarySub: 4, UnaryAdd: 4, Mul: 5, Div: 5, Sub: 10, Add: 10, \
Compare: 11, Not: 11, And: 11, Or: 11, Discard: 100}

_node_attrs

Value:
{Name:(), Const:(), Add:('left', 'right'), Sub:('left', 'right'), Mul:\
('left', 'right'), Div:('left', 'right'), CallFunc:('args',), Power:('\
left', 'right'), UnarySub:('expr',), UnaryAdd:('expr',), Slice:('lower\
', 'upper'), Sliceobj:('nodes',), Subscript:('subs',), Compare:('expr'\
, 'ops'), Not:('expr',), Or:('nodes',), And:('nodes',),}