Search in sources :

Example 1 with TryCatchStatement

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

the class AntlrProgramBuilder method parseTryCatch.

protected TryCatchStatement parseTryCatch(TryStContext tryStCtx) {
    BlockContext tryBlockCtx = tryStCtx.block(0);
    BlockStatement tryPart = (BlockStatement) this.parseBlock(tryBlockCtx.statement(), tryBlockCtx);
    BlockStatement catchPart = null;
    VarDefineNode errorNode = null;
    if (tryStCtx.Catch() != null) {
        this.pbCtx.enterBlock();
        if (tryStCtx.Identifier() != null) {
            Token errorToken = tryStCtx.Identifier().getSymbol();
            errorNode = new VarDefineNode(this.getBTToken(errorToken));
            this.pbCtx.addVarAndPostion(errorNode);
        }
        BlockContext catchBlockCtx = tryStCtx.block(1);
        catchPart = (BlockStatement) this.parseBlock(catchBlockCtx.statement(), catchBlockCtx);
        this.pbCtx.exitBlock();
    }
    TryCatchStatement statement = new TryCatchStatement(tryPart, catchPart, errorNode, this.getBTToken(tryStCtx.Try().getSymbol()));
    return statement;
}
Also used : BlockContext(org.beetl.core.parser.BeetlParser.BlockContext) VarDefineNode(org.beetl.core.statement.VarDefineNode) TryCatchStatement(org.beetl.core.statement.TryCatchStatement) BlockStatement(org.beetl.core.statement.BlockStatement) Token(org.antlr.v4.runtime.Token) GrammarToken(org.beetl.core.statement.GrammarToken)

Aggregations

Token (org.antlr.v4.runtime.Token)1 BlockContext (org.beetl.core.parser.BeetlParser.BlockContext)1 BlockStatement (org.beetl.core.statement.BlockStatement)1 GrammarToken (org.beetl.core.statement.GrammarToken)1 TryCatchStatement (org.beetl.core.statement.TryCatchStatement)1 VarDefineNode (org.beetl.core.statement.VarDefineNode)1