Search in sources :

Example 1 with WithItem

use of org.python.pydev.parser.jython.ast.WithItem in project Pydev by fabioz.

the class PyParser25Test method testNewWithStmt2.

public void testNewWithStmt2() {
    setDefaultVersion(IPythonNature.GRAMMAR_PYTHON_VERSION_2_5);
    String str = "" + "from __future__ import with_statement\n" + "with foo as x:\n" + "    print 'bla'\n" + "";
    // we'll actually treat this as a try..finally with a body with try..except..else
    Module mod = (Module) parseLegalDocStr(str);
    assertEquals(2, mod.body.length);
    assertTrue(mod.body[1] instanceof With);
    With w = (With) mod.body[1];
    assertTrue(((WithItem) w.with_item[0]).optional_vars != null);
}
Also used : WithItem(org.python.pydev.parser.jython.ast.WithItem) Module(org.python.pydev.parser.jython.ast.Module) With(org.python.pydev.parser.jython.ast.With)

Example 2 with WithItem

use of org.python.pydev.parser.jython.ast.WithItem in project Pydev by fabioz.

the class PyParser25Test method testNewWithStmt.

public void testNewWithStmt() {
    setDefaultVersion(IPythonNature.GRAMMAR_PYTHON_VERSION_2_5);
    String str = "" + "from __future__ import with_statement\n" + "with foo:\n" + "    print 'bla'\n" + "";
    // we'll actually treat this as a try..finally with a body with try..except..else
    Module mod = (Module) parseLegalDocStr(str);
    assertEquals(2, mod.body.length);
    assertTrue(mod.body[1] instanceof With);
    With w = (With) mod.body[1];
    assertTrue(((WithItem) w.with_item[0]).optional_vars == null);
}
Also used : WithItem(org.python.pydev.parser.jython.ast.WithItem) Module(org.python.pydev.parser.jython.ast.Module) With(org.python.pydev.parser.jython.ast.With)

Example 3 with WithItem

use of org.python.pydev.parser.jython.ast.WithItem in project Pydev by fabioz.

the class AbstractTreeBuilder method makeWithItem.

protected final SimpleNode makeWithItem(int arity) throws Exception {
    // expr
    exprType expr = (exprType) stack.popNode();
    arity--;
    exprType asExpr = null;
    if (arity > 0) {
        asExpr = expr;
        expr = (exprType) stack.popNode();
        ctx.setStore(asExpr);
    }
    return new WithItem(expr, asExpr);
}
Also used : org.python.pydev.parser.jython.ast.exprType(org.python.pydev.parser.jython.ast.exprType) WithItem(org.python.pydev.parser.jython.ast.WithItem)

Example 4 with WithItem

use of org.python.pydev.parser.jython.ast.WithItem in project Pydev by fabioz.

the class AbstractTreeBuilder method makeWithStmt.

protected final SimpleNode makeWithStmt(int arity) {
    Suite suite = (Suite) stack.popNode();
    arity--;
    WithItem[] items = new WithItem[arity];
    while (arity > 0) {
        items[arity - 1] = (WithItem) stack.popNode();
        arity--;
    }
    suiteType s = new Suite(suite.body);
    addSpecialsAndClearOriginal(suite, s);
    return new With(items, s, stack.getGrammar().getInsideAsync());
}
Also used : Suite(org.python.pydev.parser.jython.ast.Suite) WithItem(org.python.pydev.parser.jython.ast.WithItem) org.python.pydev.parser.jython.ast.suiteType(org.python.pydev.parser.jython.ast.suiteType) With(org.python.pydev.parser.jython.ast.With)

Example 5 with WithItem

use of org.python.pydev.parser.jython.ast.WithItem in project Pydev by fabioz.

the class PrettyPrinterVisitorV2 method visitWith.

@Override
public Object visitWith(With node) throws Exception {
    startStatementPart();
    beforeNode(node);
    if (node.async) {
        doc.addRequire("async ", node);
    }
    doc.addRequire("with", node);
    if (node.with_item != null) {
        for (int i = 0; i < node.with_item.length; i++) {
            if (i > 0) {
                doc.addRequire(",", lastNode);
            }
            WithItem withItem = (WithItem) node.with_item[i];
            withItem.accept(this);
        }
    }
    doc.addRequire(":", lastNode);
    this.doc.addRequireIndent(":", lastNode);
    endStatementPart(node);
    if (node.body != null) {
        node.body.accept(this);
    }
    dedent();
    afterNode(node);
    return null;
}
Also used : WithItem(org.python.pydev.parser.jython.ast.WithItem) Print(org.python.pydev.parser.jython.ast.Print)

Aggregations

WithItem (org.python.pydev.parser.jython.ast.WithItem)10 With (org.python.pydev.parser.jython.ast.With)7 Module (org.python.pydev.parser.jython.ast.Module)4 Print (org.python.pydev.parser.jython.ast.Print)3 Suite (org.python.pydev.parser.jython.ast.Suite)3 org.python.pydev.parser.jython.ast.exprType (org.python.pydev.parser.jython.ast.exprType)3 ArrayList (java.util.ArrayList)2 ComprehensionCollection (org.python.pydev.parser.grammarcommon.ComprehensionCollection)2 Decorators (org.python.pydev.parser.grammarcommon.Decorators)2 DefaultArg (org.python.pydev.parser.grammarcommon.DefaultArg)2 ExtraArg (org.python.pydev.parser.grammarcommon.ExtraArg)2 ExtraArgValue (org.python.pydev.parser.grammarcommon.ExtraArgValue)2 SimpleNode (org.python.pydev.parser.jython.SimpleNode)2 Assert (org.python.pydev.parser.jython.ast.Assert)2 Assign (org.python.pydev.parser.jython.ast.Assign)2 Call (org.python.pydev.parser.jython.ast.Call)2 ClassDef (org.python.pydev.parser.jython.ast.ClassDef)2 Comprehension (org.python.pydev.parser.jython.ast.Comprehension)2 Ellipsis (org.python.pydev.parser.jython.ast.Ellipsis)2 Expr (org.python.pydev.parser.jython.ast.Expr)2