# HG changeset patch # User Paul Boddie # Date 1488142076 -3600 # Node ID 89173ad54ae5d6b87b458ba9e43e063c99125a08 # Parent 67f2da40bb32603dc0e9eafd47a1d107f54e4d30 Removed the "with" statement from the grammar and AST support. diff -r 67f2da40bb32 -r 89173ad54ae5 compiler/ast.py --- a/compiler/ast.py Sun Feb 26 14:29:36 2017 +0100 +++ b/compiler/ast.py Sun Feb 26 21:47:56 2017 +0100 @@ -1592,38 +1592,6 @@ self.else_ and "\nelse:%s" % indent("\n%s" % self.else_) or "" ) -class With(Node): - def __init__(self, expr, vars, body, lineno=None): - self.expr = expr - self.vars = vars - self.body = body - self.lineno = lineno - - def getChildren(self): - children = [] - children.append(self.expr) - children.append(self.vars) - children.append(self.body) - return tuple(children) - - def getChildNodes(self): - nodelist = [] - nodelist.append(self.expr) - if self.vars is not None: - nodelist.append(self.vars) - nodelist.append(self.body) - return tuple(nodelist) - - def __repr__(self): - return "With(%r, %r, %r)" % (self.expr, self.vars, self.body) - - def __str__(self): - return "with %s%s:%s" % ( - self.expr, - self.vars and " as %s" % ", ".join(map(str, self.vars)), - indent("\n%s" % self.body), - ) - for name, obj in globals().items(): if isinstance(obj, type) and issubclass(obj, Node): nodes[name.lower()] = obj diff -r 67f2da40bb32 -r 89173ad54ae5 compiler/transformer.py --- a/compiler/transformer.py Sun Feb 26 14:29:36 2017 +0100 +++ b/compiler/transformer.py Sun Feb 26 21:47:56 2017 +0100 @@ -468,9 +468,6 @@ def try_stmt(self, nodelist): return self.com_try_except_finally(nodelist) - def with_stmt(self, nodelist): - return self.com_with(nodelist) - def suite(self, nodelist): # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT if len(nodelist) == 1: @@ -874,24 +871,6 @@ else: return try_except - def com_with(self, nodelist): - # with_stmt: 'with' with_item (',' with_item)* ':' suite - body = self.com_node(nodelist[-1]) - for i in range(len(nodelist) - 3, 0, -2): - ret = self.com_with_item(nodelist[i], body, nodelist[0][2]) - if i == 1: - return ret - body = ret - - def com_with_item(self, nodelist, body, lineno): - # with_item: test ['as' expr] - if len(nodelist) == 4: - var = self.com_assign(nodelist[3], OP_ASSIGN) - else: - var = None - expr = self.com_node(nodelist[1]) - return With(expr, var, body, lineno=lineno) - def com_augassign_op(self, node): assert node[0] == symbol["augassign"] return node[1] @@ -1268,7 +1247,6 @@ symbol["while_stmt"], symbol["for_stmt"], symbol["try_stmt"], - symbol["with_stmt"], symbol["suite"], symbol["testlist"], symbol["testlist_safe"], diff -r 67f2da40bb32 -r 89173ad54ae5 pyparser/data/Grammar-Lichen --- a/pyparser/data/Grammar-Lichen Sun Feb 26 14:29:36 2017 +0100 +++ b/pyparser/data/Grammar-Lichen Sun Feb 26 21:47:56 2017 +0100 @@ -48,7 +48,7 @@ exec_stmt: 'exec' expr ['in' test [',' test]] assert_stmt: 'assert' test [',' test] -compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef +compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] while_stmt: 'while' test ':' suite ['else' ':' suite] for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] @@ -57,8 +57,6 @@ ['else' ':' suite] ['finally' ':' suite] | 'finally' ':' suite)) -with_stmt: 'with' with_item (',' with_item)* ':' suite -with_item: test ['as' expr] # NB compile.c makes sure that the default except clause is last except_clause: 'except' [test [('as' | ',') test]] suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT