Search in sources :

Example 1 with SwitchLabelContext

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

the class AntlrProgramBuilder method parseSwitch.

protected SwitchStatement parseSwitch(SiwchStContext sctx) {
    // this.pbCtx.enterBlock();
    // this.pbCtx.current.canStopContinueBreakFlag = true;
    ExpressionContext ect = sctx.parExpression().expression();
    Expression exp = this.parseExpress(ect);
    List<SwitchBlockStatementGroupContext> list = sctx.switchBlock().switchBlockStatementGroup();
    LinkedHashMap<Expression, BlockStatement> condtionsStatementsMap = new LinkedHashMap<Expression, BlockStatement>();
    List<Expression> conditionList = new ArrayList<Expression>();
    BlockStatement defaultBlock = null;
    for (SwitchBlockStatementGroupContext group : list) {
        List<SwitchLabelContext> labels = group.switchLabel();
        List<StatementContext> stats = group.statement();
        BlockStatement block = stats != null ? this.parseBlock(stats, group) : null;
        for (SwitchLabelContext label : labels) {
            Expression caseExp = this.parseExpress(label.expression());
            if (caseExp == null) {
                // default
                defaultBlock = block;
                break;
            } else {
                conditionList.add(caseExp);
                condtionsStatementsMap.put(caseExp, block);
            }
        }
    }
    SwitchStatement switchStat = new SwitchStatement(exp, condtionsStatementsMap, defaultBlock, this.getBTToken(sctx.getStart()));
    return switchStat;
}
Also used : ArrayList(java.util.ArrayList) BlockStatement(org.beetl.core.statement.BlockStatement) SwitchBlockStatementGroupContext(org.beetl.core.parser.BeetlParser.SwitchBlockStatementGroupContext) LinkedHashMap(java.util.LinkedHashMap) StatementContext(org.beetl.core.parser.BeetlParser.StatementContext) SwitchStatement(org.beetl.core.statement.SwitchStatement) 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) SwitchLabelContext(org.beetl.core.parser.BeetlParser.SwitchLabelContext)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 ExpressionContext (org.beetl.core.parser.BeetlParser.ExpressionContext)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 SwitchBlockStatementGroupContext (org.beetl.core.parser.BeetlParser.SwitchBlockStatementGroupContext)1 SwitchLabelContext (org.beetl.core.parser.BeetlParser.SwitchLabelContext)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