Search in sources :

Example 6 with BeetlException

use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.

the class BeetlAntlrErrorStrategy method reportNoViableAlternative.

protected void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e) {
    TokenStream tokens = recognizer.getInputStream();
    String input;
    if (tokens instanceof TokenStream) {
        if (e.getStartToken().getType() == Token.EOF)
            input = "<文件尾>";
        else
            input = tokens.getText(e.getStartToken(), e.getOffendingToken());
    } else {
        input = "<未知输入>";
    }
    BeetlException exception = null;
    if (keys.contains(e.getOffendingToken().getText())) {
        exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR, "不允许" + e.getOffendingToken().getText() + "关键出现在这里" + ":" + escapeWSAndQuote(input), e);
    } else {
        exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR, escapeWSAndQuote(input), e);
    }
    // String msg = "no viable alternative at input " + escapeWSAndQuote(input);
    exception.pushToken(this.getGrammarToken(e.getOffendingToken()));
    throw exception;
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) TokenStream(org.antlr.v4.runtime.TokenStream) BeetlParserException(org.beetl.core.exception.BeetlParserException)

Example 7 with BeetlException

use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.

the class BeetlAntlrErrorStrategy method reportError.

@Override
public void reportError(Parser recognizer, RecognitionException e) {
    // yet successfully, don't report any errors.
    if (inErrorRecoveryMode(recognizer)) {
        // don't report spurious errors
        return;
    }
    beginErrorCondition(recognizer);
    if (e instanceof NoViableAltException) {
        reportNoViableAlternative(recognizer, (NoViableAltException) e);
    } else if (e instanceof InputMismatchException) {
        reportInputMismatch(recognizer, (InputMismatchException) e);
    } else if (e instanceof FailedPredicateException) {
        reportFailedPredicate(recognizer, (FailedPredicateException) e);
    } else {
        // System.err.println("unknown recognition error type: " + e.getClass().getName());
        BeetlException exception = new BeetlException(BeetlException.PARSER_UNKNOW_ERROR, e.getClass().getName(), e);
        // exception.token = this.getGrammarToken(e.getOffendingToken());
        exception.pushToken(this.getGrammarToken(e.getOffendingToken()));
        throw exception;
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) NoViableAltException(org.antlr.v4.runtime.NoViableAltException) FailedPredicateException(org.antlr.v4.runtime.FailedPredicateException) InputMismatchException(org.antlr.v4.runtime.InputMismatchException)

Example 8 with BeetlException

use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.

the class SyntaxErrorListener method syntaxError.

public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
    BeetlException be = new BeetlException(BeetlException.TOKEN_ERROR);
    be.token = new GrammarToken(BeetlUtil.reportChineseTokenError(msg), line, charPositionInLine);
    throw be;
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) GrammarToken(org.beetl.core.statement.GrammarToken)

Example 9 with BeetlException

use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.

the class ClasspathResource method openReader.

@Override
public Reader openReader() {
    ClasspathResourceLoader loader = ((ClasspathResourceLoader) resourceLoader);
    ClassLoader cs = loader.getClassLoader();
    URL url = cs.getResource(path);
    if (url == null) {
        // 兼容以前的写法
        url = resourceLoader.getClass().getResource(path);
    }
    if (url == null) {
        BeetlException be = new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR);
        be.pushResource(this);
        throw be;
    }
    InputStream is;
    try {
        is = url.openStream();
    } catch (IOException e1) {
        BeetlException be = new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR);
        be.pushResource(this);
        throw be;
    }
    if (is == null) {
        BeetlException be = new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR);
        be.pushResource(this);
        throw be;
    }
    if (url.getProtocol().equals("file")) {
        file = new File(url.getFile());
        lastModified = file.lastModified();
    }
    Reader br;
    try {
        br = new BufferedReader(new InputStreamReader(is, ((ClasspathResourceLoader) this.resourceLoader).charset));
        return br;
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 10 with BeetlException

use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.

the class TypeBindingProbe method check.

@Override
public void check(Context ctx) {
    if (isCompleted)
        return;
    int y = 0;
    for (int i = 0; i < program.metaData.tempVarStartIndex; i++) {
        if (types[i] == null) {
            if (ctx.vars[i] != ctx.NOT_EXIST_OBJECT && ctx.vars[i] != null) {
                Object o = ctx.vars[i];
                if (isDynamicObject(ctx, i)) {
                    types[i] = Type.ObjectType;
                    y++;
                    continue;
                }
                Type c = getType(o);
                if (c == null)
                    continue;
                else {
                    types[i] = c;
                    y++;
                }
            } else {
                continue;
            }
        } else {
            y++;
        }
    }
    // 推测完毕
    if (y == program.metaData.tempVarStartIndex) {
        try {
            infer();
            isCompleted = true;
            // 调用下一个filter
            nextFilter.setProgram(this.program);
            nextFilter.check(ctx);
        } catch (BeetlException bex) {
            // bex.printStackTrace();
            ProgramReplaceErrorEvent event = new ProgramReplaceErrorEvent(program.res.getId(), bex.getMessage(), bex);
            program.gt.fireEvent(event);
            isCompleted = true;
        }
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) Type(org.beetl.core.statement.Type)

Aggregations

BeetlException (org.beetl.core.exception.BeetlException)60 GrammarToken (org.beetl.core.statement.GrammarToken)10 IOException (java.io.IOException)7 BeetlParserException (org.beetl.core.exception.BeetlParserException)6 Expression (org.beetl.core.statement.Expression)6 AndExpression (org.beetl.core.statement.AndExpression)5 ArthExpression (org.beetl.core.statement.ArthExpression)5 CompareExpression (org.beetl.core.statement.CompareExpression)5 ContentBodyExpression (org.beetl.core.statement.ContentBodyExpression)5 FormatExpression (org.beetl.core.statement.FormatExpression)5 FunctionExpression (org.beetl.core.statement.FunctionExpression)5 IncDecExpression (org.beetl.core.statement.IncDecExpression)5 JsonArrayExpression (org.beetl.core.statement.JsonArrayExpression)5 JsonMapExpression (org.beetl.core.statement.JsonMapExpression)5 NativeCallExpression (org.beetl.core.statement.NativeCallExpression)5 NegExpression (org.beetl.core.statement.NegExpression)5 NotBooleanExpression (org.beetl.core.statement.NotBooleanExpression)5 OrExpression (org.beetl.core.statement.OrExpression)5 StatementExpression (org.beetl.core.statement.StatementExpression)5 TernaryExpression (org.beetl.core.statement.TernaryExpression)5