Search in sources :

Example 1 with Yield

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

the class AbstractASTManager method getCompletionFromFuncDefReturn.

@Override
public TokensList getCompletionFromFuncDefReturn(ICompletionState state, IModule module, IDefinition definition, boolean considerYieldTheReturnType) throws CompletionRecursionException {
    TokensList ret = new TokensList();
    if (!(module instanceof SourceModule)) {
        return ret;
    }
    if (!(definition instanceof Definition)) {
        return ret;
    }
    Definition def = (Definition) definition;
    FunctionDef functionDef = (FunctionDef) def.ast;
    ITypeInfo type = NodeUtils.getReturnTypeFromFuncDefAST(functionDef);
    if (type != null) {
        ICompletionState copy = state.getCopy();
        copy.setActivationToken(type.getActTok());
        try (NoExceptionCloseable x = copy.pushLookingFor(LookingFor.LOOKING_FOR_INSTANCED_VARIABLE)) {
            stmtType[] body = functionDef.body;
            if (body.length > 0) {
                copy.setLine(body[0].beginLine - 1);
                copy.setCol(body[0].beginColumn - 1);
            }
            IModule definitionModule = def.module;
            state.checkDefinitionMemory(definitionModule, def);
            TokensList tks = this.getCompletionsForModule(definitionModule, copy);
            if (tks.notEmpty()) {
                // TODO: This is not ideal... ideally, we'd return this info along instead of setting
                // it in the token, but this may be hard as we have to touch LOTS of places for
                // this information to get to the needed place.
                tks.setGeneratorType(type);
                ret.addAll(tks);
                // Ok, resolved rtype!
                return ret;
            } else {
                // Try to deal with some token that's not imported
                List<IPyDevCompletionParticipant> participants = ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_COMPLETION);
                for (IPyDevCompletionParticipant participant : participants) {
                    TokensList collection = participant.getCompletionsForType(copy);
                    if (collection != null && collection.notEmpty()) {
                        ret.addAll(collection);
                        // Ok, resolved rtype!
                        return ret;
                    }
                }
            }
        }
    }
    List<Return> returns = ReturnVisitor.findReturns(functionDef);
    Stream<exprType> map = returns.stream().map(r -> r.value);
    if (considerYieldTheReturnType) {
        List<Yield> yields = YieldVisitor.findYields(functionDef);
        map = Stream.concat(map, yields.stream().map(yield -> yield.value));
    }
    for (Iterator<exprType> it = map.iterator(); it.hasNext(); ) {
        exprType value = it.next();
        if (value == null) {
            continue;
        }
        String act = NodeUtils.getFullRepresentationString(value);
        if (act == null) {
            // may happen if the return we're seeing is a return without anything (keep on going to check other returns)
            continue;
        }
        ITokenCompletionRequest request = new TokenCompletionRequest(act, def.module, state.getNature(), "", def.line - 1, def.col - 1);
        TokensList tokensList = new TokensList();
        ICompletionState copy = state.getCopy();
        copy.setActivationToken(act);
        copy.setLine(value.beginLine - 1);
        copy.setCol(value.beginColumn - 1);
        LookingFor lookingFor = null;
        if (value instanceof Call) {
            lookingFor = ICompletionState.LookingFor.LOOKING_FOR_INSTANCED_VARIABLE;
        }
        try (NoExceptionCloseable x = state.pushLookingFor(lookingFor)) {
            IModule definitionModule = def.module;
            state.checkDefinitionMemory(definitionModule, def);
            try {
                PyCodeCompletion.doTokenCompletion(request, this, tokensList, act, copy);
            } catch (MisconfigurationException | IOException | CoreException | PythonNatureWithoutProjectException e) {
                throw new RuntimeException(e);
            }
            if (lookingFor != null) {
                tokensList.setLookingFor(lookingFor);
            }
            ret.addAll(tokensList);
        }
    }
    return ret;
}
Also used : IPyDevCompletionParticipant(org.python.pydev.ast.codecompletion.IPyDevCompletionParticipant) org.python.pydev.parser.jython.ast.exprType(org.python.pydev.parser.jython.ast.exprType) TokenCompletionRequest(org.python.pydev.ast.codecompletion.TokenCompletionRequest) ITokenCompletionRequest(org.python.pydev.core.ITokenCompletionRequest) IModule(org.python.pydev.core.IModule) MisconfigurationException(org.python.pydev.core.MisconfigurationException) LookingFor(org.python.pydev.core.ICompletionState.LookingFor) FunctionDef(org.python.pydev.parser.jython.ast.FunctionDef) NoExceptionCloseable(org.python.pydev.core.NoExceptionCloseable) ICompletionState(org.python.pydev.core.ICompletionState) PythonNatureWithoutProjectException(org.python.pydev.core.PythonNatureWithoutProjectException) ITokenCompletionRequest(org.python.pydev.core.ITokenCompletionRequest) TokensList(org.python.pydev.core.TokensList) SourceModule(org.python.pydev.ast.codecompletion.revisited.modules.SourceModule) Call(org.python.pydev.parser.jython.ast.Call) Return(org.python.pydev.parser.jython.ast.Return) org.python.pydev.parser.jython.ast.stmtType(org.python.pydev.parser.jython.ast.stmtType) IDefinition(org.python.pydev.core.IDefinition) Definition(org.python.pydev.ast.codecompletion.revisited.visitors.Definition) PyRefactoringFindDefinition(org.python.pydev.ast.refactoring.PyRefactoringFindDefinition) AssignDefinition(org.python.pydev.ast.codecompletion.revisited.visitors.AssignDefinition) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) ITypeInfo(org.python.pydev.core.ITypeInfo) Yield(org.python.pydev.parser.jython.ast.Yield)

Example 2 with Yield

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

the class AbstractASTManager method getCompletionsUnpackingAST.

private TokensList getCompletionsUnpackingAST(SimpleNode ast, final IModule module, ICompletionState state, UnpackInfo unpackPos) throws CompletionRecursionException {
    if (ast instanceof FunctionDef) {
        // let's try to find as an annotation first
        ITypeInfo type = NodeUtils.getReturnTypeFromFuncDefAST(ast);
        if (type != null) {
            TokensList completionsUnpackingType = getCompletionsUnpackingType(module, state, unpackPos, type);
            if (completionsUnpackingType != null && completionsUnpackingType.size() > 0) {
                return completionsUnpackingType;
            }
        }
        TokensList tokens = getCompletionsUnpackingDocstring(module, state, unpackPos, NodeUtils.getNodeDocString(ast));
        if (tokens != null && tokens.size() > 0) {
            return tokens;
        }
        List<Yield> findYields = YieldVisitor.findYields((FunctionDef) ast);
        for (Yield yield : findYields) {
            // what we should complete on.
            if (yield.value != null) {
                String rep = NodeUtils.getFullRepresentationString(yield.value);
                if (rep != null) {
                    ICompletionState copyWithActTok = state.getCopyWithActTok(rep);
                    copyWithActTok.setLookingFor(ICompletionState.LookingFor.LOOKING_FOR_INSTANCED_VARIABLE);
                    TokensList completionsForModule = getCompletionsForModule(module, copyWithActTok);
                    if (completionsForModule.size() > 0) {
                        return completionsForModule;
                    }
                }
            }
        }
        List<Return> findReturns = ReturnVisitor.findReturns((FunctionDef) ast);
        for (Return return1 : findReturns) {
            // Return types have to be unpacked...
            if (return1.value != null) {
                exprType[] elts = NodeUtils.getEltsFromCompoundObject(return1.value);
                if (elts != null) {
                    TokensList ret = getCompletionsFromUnpackedCompoundObject(module, state, elts, unpackPos);
                    if (ret != null && ret.size() > 0) {
                        return ret;
                    }
                } else {
                    String rep = NodeUtils.getFullRepresentationString(return1.value);
                    if (rep != null) {
                        TokensList completionsUnpackingObject = getCompletionsUnpackingObject(module, state.getCopyWithActTok(rep), null, unpackPos);
                        if (completionsUnpackingObject != null && completionsUnpackingObject.size() > 0) {
                            return completionsUnpackingObject;
                        }
                    }
                }
            }
        }
    } else if (ast instanceof ClassDef) {
        String rep = NodeUtils.getFullRepresentationString(ast);
        if (rep != null) {
            TokensList completionsForModule = this.getCompletionsForModule(module, state.getCopyWithActTok(rep));
            IToken getItemToken = null;
            for (IterTokenEntry entry : completionsForModule) {
                IToken iToken = entry.getToken();
                switch(iToken.getRepresentation()) {
                    case "__getitem__":
                        getItemToken = iToken;
                        break;
                    case "__iter__":
                    case "__next__":
                    case "__enter__":
                        // If we find it we'll try to unpack completions from it.
                        if (iToken instanceof SourceToken) {
                            SourceToken sourceToken = (SourceToken) iToken;
                            IModule useModule = null;
                            if (module.getName().equals(sourceToken.getParentPackage())) {
                                useModule = module;
                            }
                            if (useModule == null) {
                                String parentPackage = sourceToken.getParentPackage();
                                useModule = getModule(parentPackage, state.getNature(), true, state);
                            }
                            TokensList ret = getCompletionsUnpackingAST(sourceToken.getAst(), useModule, state, unpackPos);
                            if (ret != null && ret.size() > 0) {
                                return ret;
                            }
                        }
                        break;
                }
            }
            if (getItemToken instanceof SourceToken) {
                // The __getitem__ is already unpacked (i.e.: __iter__ returns a generator
                // and __getitem__ already returns the value we're iterating through).
                SourceToken sourceToken = (SourceToken) getItemToken;
                IModule useModule = null;
                if (module.getName().equals(sourceToken.getParentPackage())) {
                    useModule = module;
                } else {
                    String parentPackage = getItemToken.getParentPackage();
                    useModule = getModule(parentPackage, state.getNature(), true, state);
                }
                TokensList ret = getCompletionsNotUnpackingToken(sourceToken, useModule, state);
                if (ret != null && ret.size() > 0) {
                    return ret;
                }
            }
        }
    }
    return null;
}
Also used : org.python.pydev.parser.jython.ast.exprType(org.python.pydev.parser.jython.ast.exprType) IModule(org.python.pydev.core.IModule) Return(org.python.pydev.parser.jython.ast.Return) FunctionDef(org.python.pydev.parser.jython.ast.FunctionDef) IterTokenEntry(org.python.pydev.core.IterTokenEntry) ClassDef(org.python.pydev.parser.jython.ast.ClassDef) IToken(org.python.pydev.core.IToken) ITypeInfo(org.python.pydev.core.ITypeInfo) ICompletionState(org.python.pydev.core.ICompletionState) Yield(org.python.pydev.parser.jython.ast.Yield) TokensList(org.python.pydev.core.TokensList) SourceToken(org.python.pydev.ast.codecompletion.revisited.modules.SourceToken)

Example 3 with Yield

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

the class TreeBuilder27 method onCloseNode.

@Override
public final SimpleNode onCloseNode(SimpleNode n, int arity) throws Exception {
    exprType value;
    exprType[] exprs;
    Suite orelseSuite;
    stmtType[] body;
    Suite suite;
    int l;
    switch(n.getId()) {
        case JJTEXPR_STMT:
            value = (exprType) stack.popNode();
            if (arity > 1) {
                exprs = makeExprs(arity - 1);
                ctx.setStore(exprs);
                return new Assign(exprs, value, null);
            } else {
                return new Expr(value);
            }
        case JJTINDEX_OP:
            sliceType slice = (sliceType) stack.popNode();
            value = (exprType) stack.popNode();
            return new Subscript(value, slice, Subscript.Load);
        case JJTPRINT_STMT:
            boolean nl = true;
            if (stack.nodeArity() == 0) {
                Print p = new Print(null, null, true);
                return p;
            }
            if (stack.peekNode().getId() == JJTCOMMA) {
                stack.popNode();
                nl = false;
            }
            Print p = new Print(null, makeExprs(), nl);
            return p;
        case JJTPRINTEXT_STMT:
            nl = true;
            if (stack.peekNode().getId() == JJTCOMMA) {
                stack.popNode();
                nl = false;
            }
            exprs = makeExprs(stack.nodeArity() - 1);
            p = new Print(((exprType) stack.popNode()), exprs, nl);
            return p;
        case JJTBEGIN_FOR_ELSE_STMT:
            return new Suite(null);
        case JJTBEGIN_ELSE_STMT:
            return new Suite(null);
        case JJTBEGIN_WHILE_STMT:
            return new While(null, null, null);
        case JJTWHILE_STMT:
            orelseSuite = null;
            if (stack.nodeArity() == 5) {
                orelseSuite = popSuiteAndSuiteType();
            }
            body = popSuite();
            exprType test = (exprType) stack.popNode();
            While w = (While) stack.popNode();
            w.test = test;
            w.body = body;
            w.orelse = orelseSuite;
            return w;
        case JJTDECORATED:
            if (stack.nodeArity() != 2) {
                throw new RuntimeException("Expected 2 nodes at this context, found: " + arity);
            }
            SimpleNode def = stack.popNode();
            Decorators decorators = (Decorators) stack.popNode();
            if (def instanceof ClassDef) {
                ClassDef classDef = (ClassDef) def;
                classDef.decs = decorators.exp;
            } else {
                FunctionDef fDef = (FunctionDef) def;
                fDef.decs = decorators.exp;
            }
            return def;
        case JJTCALL_OP:
            exprType starargs = null;
            exprType kwargs = null;
            java.util.List<exprType> args = new ArrayList<exprType>();
            java.util.List<keywordType> keywords = new ArrayList<keywordType>();
            for (int i = arity - 2; i >= 0; i--) {
                SimpleNode node = stack.popNode();
                if (node instanceof keywordType) {
                    keywords.add(0, (keywordType) node);
                } else if (node.getId() == JJTEXTRAARGVALUELIST) {
                    ExtraArgValue nstarargs = (ExtraArgValue) node;
                    starargs = nstarargs.value;
                    this.addSpecialsAndClearOriginal(nstarargs, starargs);
                } else if (node.getId() == JJTEXTRAKEYWORDVALUELIST) {
                    ExtraArgValue nkwargs = (ExtraArgValue) node;
                    kwargs = nkwargs.value;
                    this.addSpecialsAndClearOriginal(nkwargs, kwargs);
                } else if (node instanceof ComprehensionCollection) {
                    // what can happen is something like print sum(x for x in y), where we have already passed x in the args, and then get 'for x in y'
                    args.add(0, new ListComp((exprType) stack.popNode(), ((ComprehensionCollection) node).getGenerators(), ListComp.EmptyCtx));
                    // popped node
                    i--;
                } else {
                    args.add(0, (exprType) node);
                }
            }
            exprType func = (exprType) stack.popNode();
            Call c = new Call(func, args.toArray(new exprType[args.size()]), keywords.toArray(new keywordType[keywords.size()]), starargs, kwargs);
            addSpecialsAndClearOriginal(n, c);
            return c;
        case JJTFUNCDEF:
            suite = (Suite) stack.popNode();
            body = suite.body;
            argumentsType arguments = makeArguments(stack.nodeArity() - 1);
            NameTok nameTok = makeNameTok(NameTok.FunctionName);
            // decorator is always null at this point... it's decorated later on
            FunctionDef funcDef = new FunctionDef(nameTok, arguments, body, null, null, false);
            addSpecialsAndClearOriginal(suite, funcDef);
            setParentForFuncOrClass(body, funcDef);
            return funcDef;
        case JJTDEFAULTARG:
            value = (arity == 1) ? null : ((exprType) stack.popNode());
            return new DefaultArg(((exprType) stack.popNode()), value, n.getId());
        case JJTEXTRAARGLIST:
            return new ExtraArg(makeNameTok(NameTok.VarArg), JJTEXTRAARGLIST);
        case JJTEXTRAKEYWORDLIST:
            return new ExtraArg(makeNameTok(NameTok.KwArg), JJTEXTRAKEYWORDLIST);
        case JJTCLASSDEF:
            suite = (Suite) stack.popNode();
            body = suite.body;
            exprType[] bases = makeExprs(stack.nodeArity() - 1);
            nameTok = makeNameTok(NameTok.ClassName);
            ClassDef classDef = new ClassDef(nameTok, bases, body, null, null, null, null);
            addSpecialsAndClearOriginal(suite, classDef);
            setParentForFuncOrClass(body, classDef);
            return classDef;
        case JJTBEGIN_RETURN_STMT:
            return new Return(null);
        case JJTRETURN_STMT:
            value = arity == 2 ? ((exprType) stack.popNode()) : null;
            Return ret = (Return) stack.popNode();
            ret.value = value;
            return ret;
        case JJTYIELD_STMT:
            return stack.popNode();
        case JJTYIELD_EXPR:
            exprType yieldExpr = null;
            if (arity > 0) {
                // we may have an empty yield, so, we have to check it before
                yieldExpr = (exprType) stack.popNode();
            }
            return new Yield(yieldExpr, false);
        case JJTRAISE_STMT:
            exprType tback = arity >= 3 ? ((exprType) stack.popNode()) : null;
            exprType inst = arity >= 2 ? ((exprType) stack.popNode()) : null;
            exprType type = arity >= 1 ? ((exprType) stack.popNode()) : null;
            return new Raise(type, inst, tback, null);
        case JJTGLOBAL_STMT:
            Global global = new Global(makeIdentifiers(NameTok.GlobalName), null);
            return global;
        case JJTASSERT_STMT:
            exprType msg = arity == 2 ? ((exprType) stack.popNode()) : null;
            test = (exprType) stack.popNode();
            return new Assert(test, msg);
        case JJTBEGIN_TRY_STMT:
            // we do that just to get the specials
            return new TryExcept(null, null, null);
        case JJTTRYELSE_STMT:
            orelseSuite = popSuiteAndSuiteType();
            return orelseSuite;
        case JJTTRYFINALLY_OUTER_STMT:
            orelseSuite = popSuiteAndSuiteType();
            // it does not have a body at this time... it will be filled with the inner try..except
            return new TryFinally(null, orelseSuite);
        case JJTTRY_STMT:
            TryFinally outer = null;
            if (stack.peekNode() instanceof TryFinally) {
                outer = (TryFinally) stack.popNode();
                arity--;
            }
            orelseSuite = null;
            if (stack.peekNode() instanceof suiteType) {
                orelseSuite = (Suite) stack.popNode();
                arity--;
            }
            l = arity;
            excepthandlerType[] handlers = new excepthandlerType[l];
            for (int i = l - 1; i >= 0; i--) {
                handlers[i] = (excepthandlerType) stack.popNode();
            }
            suite = (Suite) stack.popNode();
            TryExcept tryExc = (TryExcept) stack.popNode();
            if (outer != null) {
                outer.beginLine = tryExc.beginLine;
            }
            tryExc.body = suite.body;
            tryExc.handlers = handlers;
            tryExc.orelse = orelseSuite;
            addSpecials(suite, tryExc);
            if (outer == null) {
                return tryExc;
            } else {
                if (outer.body != null) {
                    throw new RuntimeException("Error. Expecting null body to be filled on try..except..finally");
                }
                outer.body = new stmtType[] { tryExc };
                return outer;
            }
        case JJTBEGIN_TRY_ELSE_STMT:
            // we do that just to get the specials
            return new Suite(null);
        case JJTBEGIN_EXCEPT_CLAUSE:
            return new excepthandlerType(null, null, null);
        case JJTEXCEPT_CLAUSE:
            suite = (Suite) stack.popNode();
            body = suite.body;
            exprType excname = arity == 4 ? ((exprType) stack.popNode()) : null;
            if (excname != null) {
                ctx.setStore(excname);
            }
            type = arity >= 3 ? ((exprType) stack.popNode()) : null;
            excepthandlerType handler = (excepthandlerType) stack.popNode();
            handler.type = type;
            handler.name = excname;
            handler.body = body;
            addSpecials(suite, handler);
            return handler;
        case JJTBEGIN_FINALLY_STMT:
            // we do that just to get the specials
            return new Suite(null);
        case JJTTRYFINALLY_STMT:
            suiteType finalBody = popSuiteAndSuiteType();
            body = popSuite();
            // We have a try..except in the stack, but we will change it for a try..finally
            // This is because we recognize a try..except in the 'try:' token, but actually end up with a try..finally
            TryExcept tryExcept = (TryExcept) stack.popNode();
            TryFinally tryFinally = new TryFinally(body, finalBody);
            tryFinally.beginLine = tryExcept.beginLine;
            tryFinally.beginColumn = tryExcept.beginColumn;
            addSpecialsAndClearOriginal(tryExcept, tryFinally);
            return tryFinally;
        case JJTWITH_STMT:
            return makeWithStmt(arity);
        case JJTWITH_ITEM:
            return makeWithItem(arity);
        case JJTEXTRAKEYWORDVALUELIST:
            return new ExtraArgValue(((exprType) stack.popNode()), JJTEXTRAKEYWORDVALUELIST);
        case JJTEXTRAARGVALUELIST:
            return new ExtraArgValue(((exprType) stack.popNode()), JJTEXTRAARGVALUELIST);
        case JJTKEYWORD:
            value = (exprType) stack.popNode();
            nameTok = makeNameTok(NameTok.KeywordName);
            return new keywordType(nameTok, value, false);
        case JJTTUPLE:
            if (stack.nodeArity() > 0) {
                SimpleNode peeked = stack.peekNode();
                if (peeked instanceof ComprehensionCollection) {
                    ComprehensionCollection col = (ComprehensionCollection) stack.popNode();
                    return new ListComp(((exprType) stack.popNode()), col.getGenerators(), ListComp.TupleCtx);
                }
            }
            return makeTuple(n);
        case JJTLIST:
            if (stack.nodeArity() > 0 && stack.peekNode() instanceof ComprehensionCollection) {
                ComprehensionCollection col = (ComprehensionCollection) stack.popNode();
                return new ListComp(((exprType) stack.popNode()), col.getGenerators(), ListComp.ListCtx);
            }
            return new List(makeExprs(), List.Load);
        case JJTSET:
            return new Set(null);
        case JJTDICTIONARY:
            return makeDictionaryOrSet(arity);
        case JJTSTR_1OP:
            return new Repr(((exprType) stack.popNode()));
        case JJTTEST:
            if (arity == 2) {
                IfExp node = (IfExp) stack.popNode();
                node.body = (exprType) stack.popNode();
                return node;
            } else {
                return stack.popNode();
            }
        case JJTIF_EXP:
            exprType ifExprOrelse = (exprType) stack.popNode();
            exprType ifExprTest = (exprType) stack.popNode();
            return new IfExp(ifExprTest, null, ifExprOrelse);
        case JJTOLD_LAMBDEF:
        case JJTLAMBDEF:
            test = (exprType) stack.popNode();
            arguments = makeArguments(arity - 1);
            Lambda lambda = new Lambda(arguments, test);
            // }
            return lambda;
        case JJTELLIPSIS:
            return new Ellipsis();
        case JJTSLICE:
            SimpleNode[] arr = new SimpleNode[arity];
            for (int i = arity - 1; i >= 0; i--) {
                arr[i] = stack.popNode();
            }
            exprType[] values = new exprType[3];
            int k = 0;
            java.util.List<Object> specialsBefore = new ArrayList<Object>();
            java.util.List<Object> specialsAfter = new ArrayList<Object>();
            for (int j = 0; j < arity; j++) {
                if (arr[j].getId() == JJTCOLON) {
                    if (arr[j].specialsBefore != null) {
                        specialsBefore.addAll(arr[j].specialsBefore);
                        // this nodes may be reused among parses, so, we have to erase the specials
                        arr[j].specialsBefore.clear();
                    }
                    if (arr[j].specialsAfter != null) {
                        specialsAfter.addAll(arr[j].specialsAfter);
                        arr[j].specialsAfter.clear();
                    }
                    k++;
                } else {
                    values[k] = (exprType) arr[j];
                    if (specialsBefore.size() > 0) {
                        values[k].getSpecialsBefore().addAll(specialsBefore);
                        specialsBefore.clear();
                    }
                    if (specialsAfter.size() > 0) {
                        values[k].getSpecialsBefore().addAll(specialsAfter);
                        specialsAfter.clear();
                    }
                }
            }
            SimpleNode sliceRet;
            if (k == 0) {
                sliceRet = new Index(values[0]);
            } else {
                sliceRet = new Slice(values[0], values[1], values[2]);
            }
            // this may happen if we have no values
            sliceRet.getSpecialsBefore().addAll(specialsBefore);
            sliceRet.getSpecialsAfter().addAll(specialsAfter);
            specialsBefore.clear();
            specialsAfter.clear();
            return sliceRet;
        case JJTCOMP_FOR:
            return makeCompFor(arity);
        case JJTIMPORTFROM:
            return makeImportFrom25Onwards(arity);
        case JJTSTAR_EXPR:
            Starred starred = (Starred) n;
            starred.value = (exprType) this.stack.popNode();
            ctx.setStore(starred);
            return starred;
        default:
            Log.log(("Error at TreeBuilder: default not treated:" + n.getId()));
            return null;
    }
}
Also used : org.python.pydev.parser.jython.ast.exprType(org.python.pydev.parser.jython.ast.exprType) TryExcept(org.python.pydev.parser.jython.ast.TryExcept) ArrayList(java.util.ArrayList) FunctionDef(org.python.pydev.parser.jython.ast.FunctionDef) Index(org.python.pydev.parser.jython.ast.Index) Global(org.python.pydev.parser.jython.ast.Global) SimpleNode(org.python.pydev.parser.jython.SimpleNode) Suite(org.python.pydev.parser.jython.ast.Suite) Print(org.python.pydev.parser.jython.ast.Print) ClassDef(org.python.pydev.parser.jython.ast.ClassDef) Assert(org.python.pydev.parser.jython.ast.Assert) IfExp(org.python.pydev.parser.jython.ast.IfExp) List(org.python.pydev.parser.jython.ast.List) ArrayList(java.util.ArrayList) org.python.pydev.parser.jython.ast.argumentsType(org.python.pydev.parser.jython.ast.argumentsType) org.python.pydev.parser.jython.ast.stmtType(org.python.pydev.parser.jython.ast.stmtType) DefaultArg(org.python.pydev.parser.grammarcommon.DefaultArg) Repr(org.python.pydev.parser.jython.ast.Repr) Expr(org.python.pydev.parser.jython.ast.Expr) TryFinally(org.python.pydev.parser.jython.ast.TryFinally) Slice(org.python.pydev.parser.jython.ast.Slice) org.python.pydev.parser.jython.ast.sliceType(org.python.pydev.parser.jython.ast.sliceType) Set(org.python.pydev.parser.jython.ast.Set) ExtraArg(org.python.pydev.parser.grammarcommon.ExtraArg) Decorators(org.python.pydev.parser.grammarcommon.Decorators) Subscript(org.python.pydev.parser.jython.ast.Subscript) org.python.pydev.parser.jython.ast.keywordType(org.python.pydev.parser.jython.ast.keywordType) Lambda(org.python.pydev.parser.jython.ast.Lambda) Call(org.python.pydev.parser.jython.ast.Call) Return(org.python.pydev.parser.jython.ast.Return) Ellipsis(org.python.pydev.parser.jython.ast.Ellipsis) ListComp(org.python.pydev.parser.jython.ast.ListComp) While(org.python.pydev.parser.jython.ast.While) org.python.pydev.parser.jython.ast.suiteType(org.python.pydev.parser.jython.ast.suiteType) Print(org.python.pydev.parser.jython.ast.Print) ExtraArgValue(org.python.pydev.parser.grammarcommon.ExtraArgValue) org.python.pydev.parser.jython.ast.excepthandlerType(org.python.pydev.parser.jython.ast.excepthandlerType) ComprehensionCollection(org.python.pydev.parser.grammarcommon.ComprehensionCollection) Assign(org.python.pydev.parser.jython.ast.Assign) Yield(org.python.pydev.parser.jython.ast.Yield) Starred(org.python.pydev.parser.jython.ast.Starred) Raise(org.python.pydev.parser.jython.ast.Raise) NameTok(org.python.pydev.parser.jython.ast.NameTok)

Example 4 with Yield

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

the class PythonGrammar30 method yield_expr.

// Change in Python 3.3: yield from 'xxx'
// yield_expr: 'yield' [yield_arg]
public final void yield_expr() throws ParseException {
    /*@bgen(jjtree) yield_expr */
    SimpleNode jjtn000 = builder.openNode(JJTYIELD_EXPR);
    boolean jjtc000 = true;
    jjtree.openNodeScope(jjtn000);
    jjtreeOpenNodeScope(jjtn000);
    Token spStr;
    boolean isYieldFrom = false;
    try {
        spStr = jj_consume_token(YIELD);
        switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
            case LPAREN:
            case LBRACE:
            case LBRACKET:
            case DOT:
            case PLUS:
            case MINUS:
            case NOT:
            case NOT_BOOL:
            case LAMBDA:
            case ASYNC:
            case AWAIT:
            case FROM:
            case FALSE:
            case TRUE:
            case NONE:
            case NAME:
            case DECNUMBER:
            case HEXNUMBER:
            case OCTNUMBER:
            case BINNUMBER:
            case FLOAT:
            case COMPLEX:
            case SINGLE_STRING:
            case SINGLE_STRING2:
            case TRIPLE_STRING:
            case TRIPLE_STRING2:
            case SINGLE_BSTRING:
            case SINGLE_BSTRING2:
            case TRIPLE_BSTRING:
            case TRIPLE_BSTRING2:
            case SINGLE_USTRING:
            case SINGLE_USTRING2:
            case TRIPLE_USTRING:
            case TRIPLE_USTRING2:
                isYieldFrom = yield_arg();
                break;
            default:
                jj_la1[49] = jj_gen;
                ;
        }
        jjtree.closeNodeScope(jjtn000, true);
        jjtc000 = false;
        jjtreeCloseNodeScope(jjtn000);
        Yield yield = (Yield) this.grammarActions.addToPeek(spStr, false, Yield.class);
        if (yield != null) {
            yield.yield_from = isYieldFrom;
        }
    } catch (Throwable jjte000) {
        if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
        } else {
            jjtree.popNode();
        }
        if (jjte000 instanceof RuntimeException) {
            {
                if (true)
                    throw (RuntimeException) jjte000;
            }
        }
        if (jjte000 instanceof ParseException) {
            {
                if (true)
                    throw (ParseException) jjte000;
            }
        }
        {
            if (true)
                throw (Error) jjte000;
        }
    } finally {
        if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
            jjtreeCloseNodeScope(jjtn000);
        }
    }
}
Also used : Token(org.python.pydev.parser.jython.Token) Yield(org.python.pydev.parser.jython.ast.Yield) ParseException(org.python.pydev.parser.jython.ParseException) SimpleNode(org.python.pydev.parser.jython.SimpleNode)

Example 5 with Yield

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

the class PythonGrammar38 method yield_expr.

// Change in Python 3.3: yield from 'xxx'
// yield_expr: 'yield' [yield_arg]
public final void yield_expr() throws ParseException {
    /*@bgen(jjtree) yield_expr */
    SimpleNode jjtn000 = builder.openNode(JJTYIELD_EXPR);
    boolean jjtc000 = true;
    jjtree.openNodeScope(jjtn000);
    jjtreeOpenNodeScope(jjtn000);
    Token spStr;
    boolean isYieldFrom = false;
    try {
        spStr = jj_consume_token(YIELD);
        switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
            case LPAREN:
            case LBRACE:
            case LBRACKET:
            case DOT:
            case PLUS:
            case MINUS:
            case MULTIPLY:
            case NOT:
            case NOT_BOOL:
            case LAMBDA:
            case ASYNC:
            case AWAIT:
            case FROM:
            case FALSE:
            case TRUE:
            case NONE:
            case NAME:
            case DECNUMBER:
            case HEXNUMBER:
            case OCTNUMBER:
            case BINNUMBER:
            case FLOAT:
            case COMPLEX:
            case SINGLE_STRING:
            case SINGLE_STRING2:
            case TRIPLE_STRING:
            case TRIPLE_STRING2:
            case SINGLE_BSTRING:
            case SINGLE_BSTRING2:
            case TRIPLE_BSTRING:
            case TRIPLE_BSTRING2:
            case SINGLE_FSTRING:
            case SINGLE_FSTRING2:
            case TRIPLE_FSTRING:
            case TRIPLE_FSTRING2:
            case SINGLE_USTRING:
            case SINGLE_USTRING2:
            case TRIPLE_USTRING:
            case TRIPLE_USTRING2:
                isYieldFrom = yield_arg();
                break;
            default:
                jj_la1[63] = jj_gen;
                ;
        }
        jjtree.closeNodeScope(jjtn000, true);
        jjtc000 = false;
        jjtreeCloseNodeScope(jjtn000);
        Yield yield = (Yield) this.grammarActions.addToPeek(spStr, false, Yield.class);
        if (yield != null) {
            yield.yield_from = isYieldFrom;
        }
    } catch (Throwable jjte000) {
        if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
        } else {
            jjtree.popNode();
        }
        if (jjte000 instanceof RuntimeException) {
            {
                if (true)
                    throw (RuntimeException) jjte000;
            }
        }
        if (jjte000 instanceof ParseException) {
            {
                if (true)
                    throw (ParseException) jjte000;
            }
        }
        {
            if (true)
                throw (Error) jjte000;
        }
    } finally {
        if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
            jjtreeCloseNodeScope(jjtn000);
        }
    }
}
Also used : Token(org.python.pydev.parser.jython.Token) Yield(org.python.pydev.parser.jython.ast.Yield) ParseException(org.python.pydev.parser.jython.ParseException) SimpleNode(org.python.pydev.parser.jython.SimpleNode)

Aggregations

Yield (org.python.pydev.parser.jython.ast.Yield)15 SimpleNode (org.python.pydev.parser.jython.SimpleNode)12 FunctionDef (org.python.pydev.parser.jython.ast.FunctionDef)10 org.python.pydev.parser.jython.ast.exprType (org.python.pydev.parser.jython.ast.exprType)10 ParseException (org.python.pydev.parser.jython.ParseException)9 Expr (org.python.pydev.parser.jython.ast.Expr)9 Return (org.python.pydev.parser.jython.ast.Return)9 org.python.pydev.parser.jython.ast.stmtType (org.python.pydev.parser.jython.ast.stmtType)9 ArrayList (java.util.ArrayList)8 Call (org.python.pydev.parser.jython.ast.Call)8 ClassDef (org.python.pydev.parser.jython.ast.ClassDef)8 NameTok (org.python.pydev.parser.jython.ast.NameTok)8 Suite (org.python.pydev.parser.jython.ast.Suite)8 org.python.pydev.parser.jython.ast.sliceType (org.python.pydev.parser.jython.ast.sliceType)8 org.python.pydev.parser.jython.ast.suiteType (org.python.pydev.parser.jython.ast.suiteType)8 ComprehensionCollection (org.python.pydev.parser.grammarcommon.ComprehensionCollection)7 Decorators (org.python.pydev.parser.grammarcommon.Decorators)7 DefaultArg (org.python.pydev.parser.grammarcommon.DefaultArg)7 ExtraArg (org.python.pydev.parser.grammarcommon.ExtraArg)7 ExtraArgValue (org.python.pydev.parser.grammarcommon.ExtraArgValue)7