Search in sources :

Example 11 with GrammarToken

use of org.beetl.core.statement.GrammarToken in project beetl2.0 by javamonkey.

the class AntlrProgramBuilder method parseOneIncDecContext.

protected IncDecExpression parseOneIncDecContext(OneIncDecContext ctx) {
    IncDecExpression exp = null;
    boolean isInc = ctx.INCREASE() != null;
    GrammarToken t = this.getBTToken(ctx.Identifier().getSymbol());
    exp = new IncDecExpression(isInc, true, t);
    this.pbCtx.setVarPosition(t.text, exp);
    return exp;
}
Also used : IncDecExpression(org.beetl.core.statement.IncDecExpression) GrammarToken(org.beetl.core.statement.GrammarToken)

Example 12 with GrammarToken

use of org.beetl.core.statement.GrammarToken in project beetl2.0 by javamonkey.

the class Template method renderTo.

public void renderTo(ByteWriter byteWriter) {
    try {
        ctx.byteWriter = byteWriter;
        ctx.byteOutputMode = cf.directByteOutput;
        ctx.gt = this.gt;
        ctx.template = this;
        if (gt.sharedVars != null) {
            for (Entry<String, Object> entry : gt.sharedVars.entrySet()) {
                ctx.set(entry.getKey(), entry.getValue());
            }
        }
        program.metaData.initContext(ctx);
        if (ajaxId != null) {
            AjaxStatement ajax = program.metaData.getAjax(ajaxId);
            if (ajax == null) {
                BeetlException be = new BeetlException(BeetlException.AJAX_NOT_FOUND);
                be.pushToken(new GrammarToken(ajaxId, 0, 0));
                throw be;
            }
            ajax.execute(ctx);
        } else {
            program.execute(ctx);
        }
        if (isRoot) {
            byteWriter.flush();
        }
    } catch (BeetlException e) {
        if (!(program instanceof ErrorGrammarProgram)) {
            e.pushResource(this.program.res);
        }
        // 是否打印异常,只有根模板才能打印异常
        if (!isRoot)
            throw e;
        if (e.detailCode == BeetlException.CLIENT_IO_ERROR_ERROR && ctx.gt.conf.isIgnoreClientIOError) {
            return;
        }
        Writer w = BeetlUtil.getWriterByByteWriter(ctx.byteWriter);
        e.gt = this.program.gt;
        e.cr = this.program.metaData.lineSeparator;
        ErrorHandler errorHandler = this.gt.getErrorHandler();
        if (errorHandler == null) {
            throw e;
        }
        errorHandler.processExcption(e, w);
        try {
            ctx.byteWriter.flush();
        } catch (IOException e1) {
        // 输出到客户端
        }
    } catch (IOException e) {
        if (!ctx.gt.conf.isIgnoreClientIOError) {
            BeetlException be = new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, e.getMessage(), e);
            be.pushResource(this.program.res);
            be.pushToken(new GrammarToken(this.program.res.id, 0, 0));
            ErrorHandler errorHandler = this.gt.getErrorHandler();
            if (errorHandler == null) {
                throw be;
            }
            Writer w = BeetlUtil.getWriterByByteWriter(ctx.byteWriter);
            errorHandler.processExcption(be, w);
            try {
                ctx.byteWriter.flush();
            } catch (IOException e1) {
            // 输出到客户端
            }
        } else {
        // do  nothing ,just ignore
        }
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) IOException(java.io.IOException) ErrorGrammarProgram(org.beetl.core.statement.ErrorGrammarProgram) AjaxStatement(org.beetl.core.statement.AjaxStatement) GrammarToken(org.beetl.core.statement.GrammarToken) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 13 with GrammarToken

use of org.beetl.core.statement.GrammarToken in project beetl2.0 by javamonkey.

the class LineStatus method transform.

public Reader transform(Reader orginal) throws IOException, HTMLTagParserException {
    StringBuilder temp = new StringBuilder();
    int bufSzie = 1024;
    cs = new char[bufSzie];
    int len = -1;
    while ((len = orginal.read(cs)) != -1) {
        temp.append(cs, 0, len);
    }
    cs = temp.toString().toCharArray();
    // 找到回车换行符号
    findCR();
    checkAppendCR();
    parser();
    if (this.isSupportHtmlTag && this.htmlTagStack.size() != 0) {
        String tagName = (String) htmlTagStack.peek();
        GrammarToken token = GrammarToken.createToken(tagName, this.totalLineCount + 1);
        HTMLTagParserException ex = new HTMLTagParserException("解析html tag 标签出错,未找到匹配结束标签 " + tagName);
        ex.pushToken(token);
        ex.line = totalLineCount + 1;
        this.clear();
        throw ex;
    }
    orginal.close();
    return new StringReader(sb.toString());
}
Also used : StringReader(java.io.StringReader) HTMLTagParserException(org.beetl.core.exception.HTMLTagParserException) GrammarToken(org.beetl.core.statement.GrammarToken)

Aggregations

GrammarToken (org.beetl.core.statement.GrammarToken)13 BeetlException (org.beetl.core.exception.BeetlException)6 HTMLTagParserException (org.beetl.core.exception.HTMLTagParserException)4 IncDecExpression (org.beetl.core.statement.IncDecExpression)4 AjaxStatement (org.beetl.core.statement.AjaxStatement)3 StringReader (java.io.StringReader)2 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)2 AndExpression (org.beetl.core.statement.AndExpression)2 ArthExpression (org.beetl.core.statement.ArthExpression)2 BlockStatement (org.beetl.core.statement.BlockStatement)2 CompareExpression (org.beetl.core.statement.CompareExpression)2 ContentBodyExpression (org.beetl.core.statement.ContentBodyExpression)2 Expression (org.beetl.core.statement.Expression)2 FormatExpression (org.beetl.core.statement.FormatExpression)2 FunctionExpression (org.beetl.core.statement.FunctionExpression)2 JsonArrayExpression (org.beetl.core.statement.JsonArrayExpression)2 JsonMapExpression (org.beetl.core.statement.JsonMapExpression)2 NativeCallExpression (org.beetl.core.statement.NativeCallExpression)2 NegExpression (org.beetl.core.statement.NegExpression)2 NotBooleanExpression (org.beetl.core.statement.NotBooleanExpression)2