Search in sources :

Example 1 with ParseException

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

the class GenCythonAstImpl method jsonToParseOutput.

private ParseOutput jsonToParseOutput(ParserInfo p, String cythonJson, long modifiedTime) {
    JsonValue json = JsonValue.readFrom(cythonJson);
    JsonObject asObject = json.asObject();
    JsonValue errors = asObject.get("errors");
    ParseException exc = null;
    for (JsonValue v : errors.asArray()) {
        JsonObject objError = v.asObject();
        JsonValue lineValue = objError.get("line");
        JsonValue colValue = objError.get("col");
        JsonValue messageValue = objError.get("message_only");
        exc = new ParseException(messageValue.asString(), lineValue.asInt(), colValue.asInt());
    }
    JsonValue ast = asObject.get("ast");
    if (ast == null || !ast.isObject()) {
        ParseOutput parseOutput = new ParseOutput(null, exc, modifiedTime);
        parseOutput.isCython = true;
        return parseOutput;
    } else {
        JsonValue body = ast.asObject().get("stats");
        if (body != null && body.isArray()) {
            // System.out.println(body.toPrettyString());
            JsonToNodesBuilder builder = new JsonToNodesBuilder(p);
            JsonArray asArray = body.asArray();
            Iterator<JsonValue> iterator = asArray.iterator();
            while (iterator.hasNext()) {
                JsonValue node = iterator.next();
                try {
                    builder.addStatement(node);
                } catch (Exception e) {
                    log("Error converting cython json to ast: " + node, e);
                }
            }
            ISimpleNode mod = builder.createModule();
            ParseOutput parseOutput = new ParseOutput(mod, null, modifiedTime);
            parseOutput.isCython = true;
            return parseOutput;
        }
    }
    return null;
}
Also used : JsonArray(org.python.pydev.json.eclipsesource.JsonArray) ParseOutput(org.python.pydev.shared_core.parsing.BaseParser.ParseOutput) JsonValue(org.python.pydev.json.eclipsesource.JsonValue) JsonObject(org.python.pydev.json.eclipsesource.JsonObject) ParseException(org.python.pydev.parser.jython.ParseException) ISimpleNode(org.python.pydev.shared_core.model.ISimpleNode) ParseException(org.python.pydev.parser.jython.ParseException)

Example 2 with ParseException

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

the class PythonGrammar25 method atomtrailer.

// trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
public final void atomtrailer() throws ParseException {
    Object spStr;
    Object spStr2;
    atom();
    label_30: while (true) {
        switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
            case LPAREN:
            case LBRACKET:
            case DOT:
                ;
                break;
            default:
                jj_la1[94] = jj_gen;
                break label_30;
        }
        if (jj_2_13(2)) {
            SimpleNode jjtn001 = builder.openNode(JJTCALL_OP);
            boolean jjtc001 = true;
            jjtree.openNodeScope(jjtn001);
            jjtreeOpenNodeScope(jjtn001);
            try {
                spStr = grammarActions.createSpecialStr("(", false);
                jj_consume_token(LPAREN);
                spStr2 = grammarActions.createSpecialStr(")", false);
                jj_consume_token(RPAREN);
            } finally {
                if (jjtc001) {
                    jjtree.closeNodeScope(jjtn001, 1);
                    jjtreeCloseNodeScope(jjtn001);
                }
            }
            grammarActions.addToPeekCallFunc(spStr, true);
            grammarActions.addToPeek(spStr2, true);
        } else if (jj_2_14(2)) {
            SimpleNode jjtn002 = builder.openNode(JJTCALL_OP);
            boolean jjtc002 = true;
            jjtree.openNodeScope(jjtn002);
            jjtreeOpenNodeScope(jjtn002);
            try {
                spStr = grammarActions.createSpecialStr("(", false);
                jj_consume_token(LPAREN);
                insidetuporcall();
                spStr2 = grammarActions.createSpecialStr(")", false);
                jj_consume_token(RPAREN);
            } catch (Throwable jjte002) {
                if (jjtc002) {
                    jjtree.clearNodeScope(jjtn002);
                    jjtc002 = false;
                } else {
                    jjtree.popNode();
                }
                if (jjte002 instanceof RuntimeException) {
                    {
                        if (true)
                            throw (RuntimeException) jjte002;
                    }
                }
                if (jjte002 instanceof ParseException) {
                    {
                        if (true)
                            throw (ParseException) jjte002;
                    }
                }
                {
                    if (true)
                        throw (Error) jjte002;
                }
            } finally {
                if (jjtc002) {
                    jjtree.closeNodeScope(jjtn002, jjtree.nodeArity() + 1);
                    jjtreeCloseNodeScope(jjtn002);
                }
            }
            grammarActions.addToPeekCallFunc(spStr, true);
            grammarActions.addToPeek(spStr2, true);
        } else {
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case LBRACKET:
                    spStr = grammarActions.createSpecialStr("[", false);
                    jj_consume_token(LBRACKET);
                    subscriptlist();
                    spStr2 = grammarActions.createSpecialStr("]", false);
                    SimpleNode jjtn003 = builder.openNode(JJTINDEX_OP);
                    boolean jjtc003 = true;
                    jjtree.openNodeScope(jjtn003);
                    jjtreeOpenNodeScope(jjtn003);
                    try {
                        jj_consume_token(RBRACKET);
                    } finally {
                        if (jjtc003) {
                            jjtree.closeNodeScope(jjtn003, 2);
                            jjtreeCloseNodeScope(jjtn003);
                        }
                    }
                    grammarActions.addToPeek(spStr, false);
                    grammarActions.addToPeek(spStr2, true);
                    break;
                case DOT:
                    jj_consume_token(DOT);
                    SimpleNode jjtn004 = builder.openNode(JJTDOT_OP);
                    boolean jjtc004 = true;
                    jjtree.openNodeScope(jjtn004);
                    jjtreeOpenNodeScope(jjtn004);
                    try {
                        Name2();
                    } catch (Throwable jjte004) {
                        if (jjtc004) {
                            jjtree.clearNodeScope(jjtn004);
                            jjtc004 = false;
                        } else {
                            jjtree.popNode();
                        }
                        if (jjte004 instanceof RuntimeException) {
                            {
                                if (true)
                                    throw (RuntimeException) jjte004;
                            }
                        }
                        if (jjte004 instanceof ParseException) {
                            {
                                if (true)
                                    throw (ParseException) jjte004;
                            }
                        }
                        {
                            if (true)
                                throw (Error) jjte004;
                        }
                    } finally {
                        if (jjtc004) {
                            jjtree.closeNodeScope(jjtn004, 2);
                            jjtreeCloseNodeScope(jjtn004);
                        }
                    }
                    break;
                default:
                    jj_la1[95] = jj_gen;
                    jj_consume_token(-1);
                    throw new ParseException();
            }
        }
    }
}
Also used : ParseException(org.python.pydev.parser.jython.ParseException) SimpleNode(org.python.pydev.parser.jython.SimpleNode)

Example 3 with ParseException

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

the class PythonGrammar25 method print_stmt.

// print_stmt: 'print' (test ',')* [test] | 'print' '>>' test (, test)+ [,]
public final void print_stmt() throws ParseException {
    if (jj_2_9(2)) {
        jj_consume_token(PRINT);
        jj_consume_token(RSHIFT);
        SimpleNode jjtn001 = builder.openNode(JJTPRINTEXT_STMT);
        boolean jjtc001 = true;
        jjtree.openNodeScope(jjtn001);
        jjtreeOpenNodeScope(jjtn001);
        try {
            test();
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case COMMA:
                    label_7: while (true) {
                        grammarActions.findTokenAndAdd(",");
                        jj_consume_token(COMMA);
                        test();
                        if (jj_2_7(2)) {
                            ;
                        } else {
                            break label_7;
                        }
                    }
                    switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                        case COMMA:
                            Comma();
                            break;
                        default:
                            jj_la1[31] = jj_gen;
                            ;
                    }
                    break;
                default:
                    jj_la1[32] = jj_gen;
                    ;
            }
        } catch (Throwable jjte001) {
            if (jjtc001) {
                jjtree.clearNodeScope(jjtn001);
                jjtc001 = false;
            } else {
                jjtree.popNode();
            }
            if (jjte001 instanceof RuntimeException) {
                {
                    if (true)
                        throw (RuntimeException) jjte001;
                }
            }
            if (jjte001 instanceof ParseException) {
                {
                    if (true)
                        throw (ParseException) jjte001;
                }
            }
            {
                if (true)
                    throw (Error) jjte001;
            }
        } finally {
            if (jjtc001) {
                jjtree.closeNodeScope(jjtn001, true);
                jjtreeCloseNodeScope(jjtn001);
            }
        }
    } else if (jj_2_10(2)) {
        jj_consume_token(PRINT);
        SimpleNode jjtn002 = builder.openNode(JJTPRINT_STMT);
        boolean jjtc002 = true;
        jjtree.openNodeScope(jjtn002);
        jjtreeOpenNodeScope(jjtn002);
        try {
            test();
            label_8: while (true) {
                if (jj_2_8(2)) {
                    ;
                } else {
                    break label_8;
                }
                grammarActions.findTokenAndAdd(",");
                jj_consume_token(COMMA);
                test();
            }
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case COMMA:
                    Comma();
                    break;
                default:
                    jj_la1[33] = jj_gen;
                    ;
            }
        } catch (Throwable jjte002) {
            if (jjtc002) {
                jjtree.clearNodeScope(jjtn002);
                jjtc002 = false;
            } else {
                jjtree.popNode();
            }
            if (jjte002 instanceof RuntimeException) {
                {
                    if (true)
                        throw (RuntimeException) jjte002;
                }
            }
            if (jjte002 instanceof ParseException) {
                {
                    if (true)
                        throw (ParseException) jjte002;
                }
            }
            {
                if (true)
                    throw (Error) jjte002;
            }
        } finally {
            if (jjtc002) {
                jjtree.closeNodeScope(jjtn002, true);
                jjtreeCloseNodeScope(jjtn002);
            }
        }
    } else {
        switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
            case PRINT:
                SimpleNode jjtn003 = builder.openNode(JJTPRINT_STMT);
                boolean jjtc003 = true;
                jjtree.openNodeScope(jjtn003);
                jjtreeOpenNodeScope(jjtn003);
                try {
                    jj_consume_token(PRINT);
                } finally {
                    if (jjtc003) {
                        jjtree.closeNodeScope(jjtn003, true);
                        jjtreeCloseNodeScope(jjtn003);
                    }
                }
                break;
            default:
                jj_la1[34] = jj_gen;
                jj_consume_token(-1);
                throw new ParseException();
        }
    }
}
Also used : TokenMgrError(org.python.pydev.parser.jython.TokenMgrError) ParseException(org.python.pydev.parser.jython.ParseException) SimpleNode(org.python.pydev.parser.jython.SimpleNode)

Example 4 with ParseException

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

the class PythonGrammar25 method exec_stmt.

// exec_stmt: 'exec' expr ['in' test [',' test]]
public final void exec_stmt() throws ParseException {
    /*@bgen(jjtree) exec_stmt */
    SimpleNode jjtn000 = builder.openNode(JJTEXEC_STMT);
    boolean jjtc000 = true;
    jjtree.openNodeScope(jjtn000);
    jjtreeOpenNodeScope(jjtn000);
    try {
        temporaryToken = jj_consume_token(EXEC);
        grammarActions.addSpecialTokenToLastOpened(temporaryToken);
        expr();
        switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
            case IN:
                temporaryToken = jj_consume_token(IN);
                grammarActions.addSpecialToken(temporaryToken);
                test();
                switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                    case COMMA:
                        grammarActions.findTokenAndAdd(",");
                        jj_consume_token(COMMA);
                        test();
                        break;
                    default:
                        jj_la1[53] = jj_gen;
                        ;
                }
                break;
            default:
                jj_la1[54] = jj_gen;
                ;
        }
    } 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 : ParseException(org.python.pydev.parser.jython.ParseException) SimpleNode(org.python.pydev.parser.jython.SimpleNode)

Example 5 with ParseException

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

the class PythonGrammar25 method with_var.

// with_var: 'as' expr
public final void with_var() throws ParseException {
    /*@bgen(jjtree) with_var */
    SimpleNode jjtn000 = builder.openNode(JJTWITH_VAR);
    boolean jjtc000 = true;
    jjtree.openNodeScope(jjtn000);
    jjtreeOpenNodeScope(jjtn000);
    try {
        temporaryToken = grammarActions.createSpecialStr("as");
        jj_consume_token(AS);
        grammarActions.addSpecialToken(temporaryToken, STRATEGY_BEFORE_NEXT);
        expr();
    } 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 : ParseException(org.python.pydev.parser.jython.ParseException) SimpleNode(org.python.pydev.parser.jython.SimpleNode)

Aggregations

ParseException (org.python.pydev.parser.jython.ParseException)538 SimpleNode (org.python.pydev.parser.jython.SimpleNode)512 TokenMgrError (org.python.pydev.parser.jython.TokenMgrError)78 Token (org.python.pydev.parser.jython.Token)62 Import (org.python.pydev.parser.jython.ast.Import)14 ArrayList (java.util.ArrayList)10 FastStringBuffer (org.python.pydev.shared_core.string.FastStringBuffer)10 NameTok (org.python.pydev.parser.jython.ast.NameTok)9 DefaultArg (org.python.pydev.parser.grammarcommon.DefaultArg)8 ExtraArg (org.python.pydev.parser.grammarcommon.ExtraArg)8 EmptySuiteException (org.python.pydev.parser.grammarcommon.EmptySuiteException)7 org.python.pydev.parser.jython.ast.exprType (org.python.pydev.parser.jython.ast.exprType)7 org.python.pydev.parser.jython.ast.modType (org.python.pydev.parser.jython.ast.modType)7 Yield (org.python.pydev.parser.jython.ast.Yield)6 ParseOutput (org.python.pydev.shared_core.parsing.BaseParser.ParseOutput)6 Expr (org.python.pydev.parser.jython.ast.Expr)5 org.python.pydev.parser.jython.ast.argumentsType (org.python.pydev.parser.jython.ast.argumentsType)5 Print (org.python.pydev.parser.jython.ast.Print)4 Document (org.eclipse.jface.text.Document)3 MisconfigurationException (org.python.pydev.core.MisconfigurationException)3