Ejemplo n.º 1
0
 def visit_atom_trailer(self, node, name, context):
     first = node.first_child
     if first.type == sym.arglist:
         args = self.visit(first)  # no empty arglist
         return AST.Call(name, args, node.context)
     else:
         assert first.value == '[', first
         index = self.visit(node.children[1], context)
         return AST.Subscript(name, index, context, node.context)
Ejemplo n.º 2
0
 def visit_stmt_trailer(self, node, name):
     first = node.first_child
     store = expr_context.Store
     if first.type == sym.arglist:
         args = self.visit(first)
         call = AST.Call(name.value, args, name.context)
         return AST.ExprStmt(call, name.context)
     elif first.value == '[':
         index = self.visit(node.children[1])  # Load
         value = self.visit(node.children[-1])  # Load
         subscript = AST.Subscript(name.value, index, store, node.context)
         return AST.Assign(subscript, value, name.context)
     else:
         assert first.value == '=', first
         value = self.visit(node.children[-1])  # Load
         target = AST.Name(name.value, store, name.context)
         return AST.Assign(target, value, name.context)
Ejemplo n.º 3
0
 def visit_stmt(self, node):
     first = node.first_child
     if first.type == sym.flow_stmt:
         # flow_stmt is always one stmt
         yield self.visit(node.first_child.first_child)
     elif first.type == sym.NAME:
         if len(node.children) == 2:
             # single Name is a Call
             call = AST.Call(first.value, [], first.context)
             yield AST.ExprStmt(call, node.context)
         else:  # stmt_trailer
             yield self.visit(node.children[1], first)
     elif first.value == '{':
         for child in node.children[1:-1]:
             yield from self.visit(child)
     else:
         # make sure we handle all cases.
         assert first.value == ';' and len(node.children) == 1, node