Search in sources :

Example 6 with ErrorMessage

use of ast.ErrorMessage in project L42 by ElvisResearchGroup.

the class DeploySimpleLib method testLibCreation.

public static void testLibCreation() {
    try {
        FinalResult res = L42.runSlow(null, TestHelper.multiLine("", "          {reuse L42.is/deployMini", "            Main:Deploy[S\"Top\", fileName:S\"localhost/SimpleLib.L42\"]<{reuse L42.is/templateBNS", "              Top:Generalize[]<{reuse L42.is/miniBase", "                Exported:{", "                  class method Void printHelloWorld()", "                    Debug(S\"Hello World \"++42N)", "                  }", "                }", "              }", "            }"));
        System.out.println("------------------------------");
        System.out.println("END: " + res.getErrCode());
    } catch (ErrorMessage msg) {
        //System.out.println(L42.record.toString());
        msg.printStackTrace();
        //Executor.reportError(msg);
        System.out.println(ErrorFormatter.formatError(Program.empty(), msg).getErrorTxt());
    }
}
Also used : FinalResult(ast.ErrorMessage.FinalResult) ErrorMessage(ast.ErrorMessage)

Example 7 with ErrorMessage

use of ast.ErrorMessage in project L42 by ElvisResearchGroup.

the class DeploySimpleLib method testLibUse.

private static void testLibUse() {
    try {
        FinalResult res = L42.runSlow(null, TestHelper.multiLine("", "          {reuse L42.is/miniBase", "            Lib:Load[]<{reuse L42.is/SimpleLib}", "            Main:{", "              Lib.printHelloWorld()", "              return ExitCode.normal()", "              }", "          }"));
        System.out.println("------------------------------");
        System.out.println("END: " + res.getErrCode());
    } catch (ErrorMessage msg) {
        //System.out.println(L42.record.toString());
        msg.printStackTrace();
        //Executor.reportError(msg);
        System.out.println(ErrorFormatter.formatError(Program.empty(), msg).getErrorTxt());
    }
}
Also used : FinalResult(ast.ErrorMessage.FinalResult) ErrorMessage(ast.ErrorMessage)

Example 8 with ErrorMessage

use of ast.ErrorMessage in project L42 by ElvisResearchGroup.

the class ReplState method add.

public ReplState add(String code) {
    Expression.ClassB cbEmpty = new ClassB(Doc.empty(), new ast.Ast.InterfaceHeader(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Position.noInfo);
    try {
        //parse
        Expression.ClassB codeTmp = (ClassB) Parser.parse("Repl", "{" + code + "}");
        //new original
        ClassReuse newOriginal = this.originalL;
        List<ast.Expression.ClassB.Member> newOriginalMs = newOriginal.getInner().getMs();
        newOriginalMs.addAll(codeTmp.getMs());
        newOriginal.withInner(newOriginal.getInner().withMs(newOriginalMs));
        //new src to desugar
        List<ClassB.Member> newMs = new ArrayList<>();
        int nestedAdded = 0;
        for (Member m : this.desugaredL.getMs()) {
            if (!(m instanceof NestedClass)) {
                continue;
            }
            NestedClass nc = (NestedClass) m;
            newMs.add(new ClassB.NestedClass(Doc.empty(), nc.getName(), cbEmpty, nc.getP()));
            nestedAdded += 1;
        }
        newMs.addAll(codeTmp.getMs());
        codeTmp = codeTmp.withMs(newMs);
        Expression code2 = Desugar.of(codeTmp);
        ExpCore.ClassB code3 = (ExpCore.ClassB) code2.accept(new InjectionOnCore());
        // TODO: will die after new reduction Refresh of position identities, it is used to generate correct Java code.
        code3 = (ExpCore.ClassB) code3.accept(new CloneVisitor() {

            @Override
            public ExpCore visit(ExpCore.ClassB cb) {
                Position p = cb.getP();
                cb = cb.withP(new Position(p.getFile(), p.getLine1(), p.getPos1(), p.getLine2(), p.getPos2(), p.get_next()));
                return super.visit(cb);
            }
        });
        //integrate new desugared src with old desugared code
        List<Member> resultMs = new ArrayList<>(this.desugaredL.getMs());
        for (int i = nestedAdded; i < code3.getMs().size(); i++) {
            resultMs.add(code3.getMs().get(i));
        }
        code3 = code3.withMs(resultMs);
        //call the repl and return
        ExpCore.ClassB result = ProgramReduction.allSteps(code3);
        return new ReplState(this.originalS + "\n" + code, newOriginal, result);
    } catch (ParseCancellationException parser) {
        System.out.println(parser.getMessage());
        return null;
    } catch (ErrorMessage msg) {
        ErrorFormatter.topFormatErrorMessage(msg);
        return null;
    }
}
Also used : ExpCore(ast.ExpCore) Position(ast.Ast.Position) ClassB(ast.Expression.ClassB) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) CloneVisitor(coreVisitors.CloneVisitor) NestedClass(ast.ExpCore.ClassB.NestedClass) Expression(ast.Expression) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) ClassReuse(ast.Expression.ClassReuse) ErrorMessage(ast.ErrorMessage) Member(ast.ExpCore.ClassB.Member) ClassB(ast.Expression.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 9 with ErrorMessage

use of ast.ErrorMessage in project L42 by ElvisResearchGroup.

the class ErrorFormatter method formatError.

public static ErrorMessage.UserLevelError formatError(Program p, ErrorMessage msg, Class<?> c) throws IllegalAccessException, NoSuchFieldException, SecurityException {
    String errorStart = "\n\n\n------------------------------------\n";
    ArrayList<Ast.Position> ps = new ArrayList<Ast.Position>();
    String errorTxt = "";
    errorTxt += infoFields(msg, c, ps);
    try {
        errorTxt += "Surrounding context:\n";
        errorTxt += envs(msg, c, ps);
        ArrayList<Position> ps2 = ps;
        if (!ps.isEmpty()) {
            ps2 = new ArrayList<>();
        }
        try {
            errorTxt += ctxP(msg, c, ps2);
        } catch (NoSuchFieldException ignored) {
        }
    } catch (NoSuchFieldException ignored) {
    }
    pos(msg, c, ps);
    Position pos = positionsFilter(ps);
    if (c == ErrorMessage.DotDotDotCanNotBeResolved.class) {
    //        ErrorMessage.DotDotDotCanNotBeResolved ddd=(ErrorMessage.DotDotDotCanNotBeResolved)msg;
    }
    errorTxt = "Error kind: " + c.getSimpleName() + "\nPosition:" + ((pos == null) ? "unknown" : pos.toString()) + "\n" + errorTxt;
    //ps+"\n"+errorTxt;
    ErrorMessage.UserLevelError.Kind kind = findKind(msg);
    switch(kind) {
        case TypeError:
            errorTxt = errorStart + "runStatus: " + kind.name() + "\n" + errorTxt;
            break;
        case MetaError:
            errorTxt = errorStart + "runStatus: " + kind.name() + "\n" + "Error in generating the following class: \n" + reportPlaceOfMetaError(p, msg) + /*.replace(".\n","\n")*/
            "\n----------\n" + errorTxt;
        default:
            break;
    }
    Throwable cause = null;
    if (msg.getCause() != null) {
        if (msg.getCause() instanceof ErrorMessage) {
            ErrorMessage.UserLevelError uleCause = formatError(p, (ErrorMessage) msg.getCause());
            cause = uleCause;
            errorTxt += "\n-------- caused by -----\n" + uleCause.getErrorTxt();
        } else {
            cause = msg.getCause();
        }
    }
    ErrorMessage.UserLevelError result = new ErrorMessage.UserLevelError(kind, pos, msg, errorTxt);
    result.initCause(cause);
    return result;
}
Also used : Ast(ast.Ast) Position(ast.Ast.Position) ArrayList(java.util.ArrayList) Kind(ast.ErrorMessage.UserLevelError.Kind) ErrorMessage(ast.ErrorMessage)

Example 10 with ErrorMessage

use of ast.ErrorMessage in project L42 by ElvisResearchGroup.

the class L42 method main.

public static void main(String[] arg) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    //assert false;
    setClassPath(Paths.get("Plugins"));
    L42.programArgs = arg;
    try {
        Configuration.loadAll();
        Path path = Paths.get(arg[arg.length - 1]);
        String code = null;
        if (Files.isDirectory(path)) {
            L42.setRootPath(path);
            code = L42.pathToString(path.resolve("This.L42"));
        } else {
            L42.setRootPath(path.getParent());
            code = L42.pathToString(path);
        }
        FinalResult res = L42.runSlow(path.toString(), code);
        System.out.println("------------------------------");
        System.out.println("END (zero for success): " + res.getErrCode());
    } catch (ParseCancellationException parser) {
        System.out.println(parser.getMessage());
    //parser.printStackTrace(System.out);
    } catch (ErrorMessage msg) {
        ErrorFormatter.topFormatErrorMessage(msg);
    } finally {
        if (L42.profilerPrintOn) {
            System.out.print(Timer.report());
        }
    }
}
Also used : Path(java.nio.file.Path) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) FinalResult(ast.ErrorMessage.FinalResult) ErrorMessage(ast.ErrorMessage)

Aggregations

ErrorMessage (ast.ErrorMessage)17 FinalResult (ast.ErrorMessage.FinalResult)12 Test (org.junit.Test)5 ExpCore (ast.ExpCore)4 Position (ast.Ast.Position)3 ClassB (ast.ExpCore.ClassB)3 ArrayList (java.util.ArrayList)3 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)3 InjectionOnCore (sugarVisitors.InjectionOnCore)3 Expression (ast.Expression)2 ClassB (ast.Expression.ClassB)2 ClassReuse (ast.Expression.ClassReuse)2 CloneVisitor (coreVisitors.CloneVisitor)2 Path (java.nio.file.Path)2 Ast (ast.Ast)1 Path (ast.Ast.Path)1 Kind (ast.ErrorMessage.UserLevelError.Kind)1 Member (ast.ExpCore.ClassB.Member)1 NestedClass (ast.ExpCore.ClassB.NestedClass)1