Search in sources :

Example 1 with G_switchStatmentContext

use of org.beetl.core.parser.BeetlParser.G_switchStatmentContext in project beetl2.0 by javamonkey.

the class AntlrProgramBuilder method parseSelect.

protected SelectStatement parseSelect(SelectStContext selectCtx) {
    // this.pbCtx.enterBlock();
    // this.pbCtx.current.canStopContinueBreakFlag = true;
    G_switchStatmentContext ctx = selectCtx.g_switchStatment();
    ExpressionContext exp = ctx.expression();
    Expression base = exp != null ? this.parseExpress(exp) : null;
    List<G_caseStatmentContext> caseCtxList = ctx.g_caseStatment();
    List<Expression> condtionList = new LinkedList<Expression>();
    List<BlockStatement> blockList = new LinkedList<BlockStatement>();
    for (G_caseStatmentContext caseCtx : caseCtxList) {
        List<ExpressionContext> expCtxList = caseCtx.expression();
        List<StatementContext> statCtxList = caseCtx.statement();
        BlockStatement block = this.parseBlock(statCtxList, caseCtx);
        for (ExpressionContext expCtx : expCtxList) {
            Expression condition = this.parseExpress(expCtx);
            // select case 的条件是||的关系,只要任何一个条件满足,都可以执行block
            condtionList.add(condition);
            blockList.add(block);
        }
    }
    BlockStatement defaultStatement = null;
    G_defaultStatmentContext defaultCtx = ctx.g_defaultStatment();
    if (defaultCtx != null) {
        List<StatementContext> defaultCtxList = ctx.g_defaultStatment().statement();
        defaultStatement = this.parseBlock(defaultCtxList, ctx);
    }
    SelectStatement select = new SelectStatement(base, condtionList.toArray(new Expression[0]), blockList.toArray(new BlockStatement[0]), defaultStatement, this.getBTToken(selectCtx.Select().getSymbol()));
    return select;
}
Also used : BlockStatement(org.beetl.core.statement.BlockStatement) LinkedList(java.util.LinkedList) StatementContext(org.beetl.core.parser.BeetlParser.StatementContext) SelectStatement(org.beetl.core.statement.SelectStatement) G_switchStatmentContext(org.beetl.core.parser.BeetlParser.G_switchStatmentContext) G_defaultStatmentContext(org.beetl.core.parser.BeetlParser.G_defaultStatmentContext) G_caseStatmentContext(org.beetl.core.parser.BeetlParser.G_caseStatmentContext) StatementExpressionContext(org.beetl.core.parser.BeetlParser.StatementExpressionContext) ExpressionContext(org.beetl.core.parser.BeetlParser.ExpressionContext) ParExpressionContext(org.beetl.core.parser.BeetlParser.ParExpressionContext) ContentBodyExpression(org.beetl.core.statement.ContentBodyExpression) ArthExpression(org.beetl.core.statement.ArthExpression) JsonMapExpression(org.beetl.core.statement.JsonMapExpression) CompareExpression(org.beetl.core.statement.CompareExpression) FunctionExpression(org.beetl.core.statement.FunctionExpression) IncDecExpression(org.beetl.core.statement.IncDecExpression) Expression(org.beetl.core.statement.Expression) AndExpression(org.beetl.core.statement.AndExpression) StatementExpression(org.beetl.core.statement.StatementExpression) NativeCallExpression(org.beetl.core.statement.NativeCallExpression) NegExpression(org.beetl.core.statement.NegExpression) FormatExpression(org.beetl.core.statement.FormatExpression) TernaryExpression(org.beetl.core.statement.TernaryExpression) OrExpression(org.beetl.core.statement.OrExpression) JsonArrayExpression(org.beetl.core.statement.JsonArrayExpression) NotBooleanExpression(org.beetl.core.statement.NotBooleanExpression)

Aggregations

LinkedList (java.util.LinkedList)1 ExpressionContext (org.beetl.core.parser.BeetlParser.ExpressionContext)1 G_caseStatmentContext (org.beetl.core.parser.BeetlParser.G_caseStatmentContext)1 G_defaultStatmentContext (org.beetl.core.parser.BeetlParser.G_defaultStatmentContext)1 G_switchStatmentContext (org.beetl.core.parser.BeetlParser.G_switchStatmentContext)1 ParExpressionContext (org.beetl.core.parser.BeetlParser.ParExpressionContext)1 StatementContext (org.beetl.core.parser.BeetlParser.StatementContext)1 StatementExpressionContext (org.beetl.core.parser.BeetlParser.StatementExpressionContext)1 AndExpression (org.beetl.core.statement.AndExpression)1 ArthExpression (org.beetl.core.statement.ArthExpression)1 BlockStatement (org.beetl.core.statement.BlockStatement)1 CompareExpression (org.beetl.core.statement.CompareExpression)1 ContentBodyExpression (org.beetl.core.statement.ContentBodyExpression)1 Expression (org.beetl.core.statement.Expression)1 FormatExpression (org.beetl.core.statement.FormatExpression)1 FunctionExpression (org.beetl.core.statement.FunctionExpression)1 IncDecExpression (org.beetl.core.statement.IncDecExpression)1 JsonArrayExpression (org.beetl.core.statement.JsonArrayExpression)1 JsonMapExpression (org.beetl.core.statement.JsonMapExpression)1 NativeCallExpression (org.beetl.core.statement.NativeCallExpression)1