Search in sources :

Example 1 with ArthExpression

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

the class AntlrProgramBuilder method parseMuldivmodExpression.

protected ArthExpression parseMuldivmodExpression(MuldivmodExpContext ctx) {
    Expression a = this.parseExpress(ctx.expression(0));
    Expression b = this.parseExpress(ctx.expression(1));
    TerminalNode tn = (TerminalNode) ctx.children.get(1);
    short mode = 0;
    if (ctx.MUlTIP() != null) {
        mode = ArthExpression.MUL;
    } else if (ctx.DIV() != null) {
        mode = ArthExpression.DIV;
    } else if (ctx.MOD() != null) {
        mode = ArthExpression.MOD;
    }
    return new ArthExpression(a, b, mode, this.getBTToken(tn.getSymbol()));
}
Also used : ArthExpression(org.beetl.core.statement.ArthExpression) 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) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode)

Example 2 with ArthExpression

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

the class AntlrProgramBuilder method parseExpress.

protected Expression parseExpress(ExpressionContext ctx) {
    if (ctx == null)
        return null;
    if (ctx instanceof LiteralExpContext) {
        return parseLiteralExpress(((LiteralExpContext) ctx).literal());
    } else if (ctx instanceof VarRefExpContext) {
        return this.parseVarRefExpression(((VarRefExpContext) ctx).varRef());
    } else if (ctx instanceof CompareExpContext) {
        CompareExpression compare = parseCompareExpression((CompareExpContext) ctx);
        if (gt.conf.isStrict) {
            throw new MVCStrictException(compare.token);
        }
        return compare;
    } else if (ctx instanceof TernaryExpContext) {
        return this.parseTernaryExpression((TernaryExpContext) ctx);
    } else if (ctx instanceof MuldivmodExpContext) {
        ArthExpression arth = this.parseMuldivmodExpression((MuldivmodExpContext) ctx);
        if (gt.conf.isStrict) {
            throw new MVCStrictException(arth.token);
        }
        return arth;
    } else if (ctx instanceof AddminExpContext) {
        return this.parsePlusMins((AddminExpContext) ctx);
    } else if (ctx instanceof ParExpContext) {
        ParExpContext par = (ParExpContext) ctx;
        return this.parseExpress(par.expression());
    } else if (ctx instanceof FunctionCallExpContext) {
        FunctionCallExpContext fceCtx = (FunctionCallExpContext) ctx;
        FunctionExpression fun = parseFunExp(fceCtx.functionCall());
        if (gt.conf.isStrict) {
            throw new MVCStrictException(fun.token);
        }
        return fun;
    } else if (ctx instanceof JsonExpContext) {
        JsonContext jc = ((JsonExpContext) ctx).json();
        return this.parseJson(jc);
    } else if (ctx instanceof NativeCallExpContext) {
        NativeCallContext ncc = ((NativeCallExpContext) ctx).nativeCall();
        NativeCallExpression nativeCall = this.parseNativeCallExpression(ncc);
        if (!gt.conf.nativeCall || gt.conf.isStrict) {
            throw new NativeNotAllowedException(nativeCall.token);
        }
        return nativeCall;
    } else if (ctx instanceof AndExpContext) {
        AndExpContext andCtx = (AndExpContext) ctx;
        return this.parseAndExpression(andCtx);
    } else if (ctx instanceof OrExpContext) {
        OrExpContext orExp = (OrExpContext) ctx;
        return this.parseOrExpression(orExp);
    } else if (ctx instanceof NotExpContext) {
        NotExpContext notCtx = (NotExpContext) ctx;
        return this.parseNotExpression(notCtx);
    } else if (ctx instanceof NegExpContext) {
        NegExpContext negCtx = (NegExpContext) ctx;
        return this.parseNegExpression(negCtx);
    } else if (ctx instanceof IncDecOneContext) {
        IncDecOneContext oneCtx = (IncDecOneContext) ctx;
        IncDecExpression exp = this.parseIncDecOneContext(oneCtx);
        if (gt.conf.isStrict) {
            throw new NativeNotAllowedException(exp.token);
        }
        return exp;
    } else if (ctx instanceof OneIncDecContext) {
        OneIncDecContext oneCtx = (OneIncDecContext) ctx;
        IncDecExpression exp = this.parseOneIncDecContext(oneCtx);
        if (gt.conf.isStrict) {
            throw new NativeNotAllowedException(exp.token);
        }
        return exp;
    } else if (ctx instanceof AssignGeneralInExpContext) {
        AssignGeneralInExpContext agc = (AssignGeneralInExpContext) ctx;
        VarRefAssignExpress vas = this.parseAssingInExp(agc);
        return vas;
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : CompareExpContext(org.beetl.core.parser.BeetlParser.CompareExpContext) NotExpContext(org.beetl.core.parser.BeetlParser.NotExpContext) NativeCallExpContext(org.beetl.core.parser.BeetlParser.NativeCallExpContext) OrExpContext(org.beetl.core.parser.BeetlParser.OrExpContext) CompareExpression(org.beetl.core.statement.CompareExpression) FunctionCallExpContext(org.beetl.core.parser.BeetlParser.FunctionCallExpContext) OneIncDecContext(org.beetl.core.parser.BeetlParser.OneIncDecContext) FunctionExpression(org.beetl.core.statement.FunctionExpression) VarRefExpContext(org.beetl.core.parser.BeetlParser.VarRefExpContext) NativeCallContext(org.beetl.core.parser.BeetlParser.NativeCallContext) NativeNotAllowedException(org.beetl.core.exception.NativeNotAllowedException) TernaryExpContext(org.beetl.core.parser.BeetlParser.TernaryExpContext) IncDecExpression(org.beetl.core.statement.IncDecExpression) AssignGeneralInExpContext(org.beetl.core.parser.BeetlParser.AssignGeneralInExpContext) MVCStrictException(org.beetl.core.exception.MVCStrictException) ParExpContext(org.beetl.core.parser.BeetlParser.ParExpContext) ArthExpression(org.beetl.core.statement.ArthExpression) LiteralExpContext(org.beetl.core.parser.BeetlParser.LiteralExpContext) MuldivmodExpContext(org.beetl.core.parser.BeetlParser.MuldivmodExpContext) AndExpContext(org.beetl.core.parser.BeetlParser.AndExpContext) JsonExpContext(org.beetl.core.parser.BeetlParser.JsonExpContext) VarRefAssignExpress(org.beetl.core.statement.VarRefAssignExpress) NativeCallExpression(org.beetl.core.statement.NativeCallExpression) JsonContext(org.beetl.core.parser.BeetlParser.JsonContext) NegExpContext(org.beetl.core.parser.BeetlParser.NegExpContext) AddminExpContext(org.beetl.core.parser.BeetlParser.AddminExpContext) IncDecOneContext(org.beetl.core.parser.BeetlParser.IncDecOneContext)

Example 3 with ArthExpression

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

the class AntlrProgramBuilder method parsePlusMins.

protected Expression parsePlusMins(AddminExpContext ctx) {
    Expression a = this.parseExpress(ctx.expression(0));
    Expression b = this.parseExpress(ctx.expression(1));
    TerminalNode tn = (TerminalNode) ctx.children.get(1);
    short mode = 0;
    if (ctx.ADD() != null) {
        mode = ArthExpression.PLUS;
    } else if (ctx.MIN() != null) {
        mode = ArthExpression.MIN;
    }
    return new ArthExpression(a, b, mode, this.getBTToken(tn.getSymbol()));
}
Also used : ArthExpression(org.beetl.core.statement.ArthExpression) 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) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode)

Aggregations

ArthExpression (org.beetl.core.statement.ArthExpression)3 CompareExpression (org.beetl.core.statement.CompareExpression)3 FunctionExpression (org.beetl.core.statement.FunctionExpression)3 IncDecExpression (org.beetl.core.statement.IncDecExpression)3 NativeCallExpression (org.beetl.core.statement.NativeCallExpression)3 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)2 AndExpression (org.beetl.core.statement.AndExpression)2 ContentBodyExpression (org.beetl.core.statement.ContentBodyExpression)2 Expression (org.beetl.core.statement.Expression)2 FormatExpression (org.beetl.core.statement.FormatExpression)2 JsonArrayExpression (org.beetl.core.statement.JsonArrayExpression)2 JsonMapExpression (org.beetl.core.statement.JsonMapExpression)2 NegExpression (org.beetl.core.statement.NegExpression)2 NotBooleanExpression (org.beetl.core.statement.NotBooleanExpression)2 OrExpression (org.beetl.core.statement.OrExpression)2 StatementExpression (org.beetl.core.statement.StatementExpression)2 TernaryExpression (org.beetl.core.statement.TernaryExpression)2 MVCStrictException (org.beetl.core.exception.MVCStrictException)1 NativeNotAllowedException (org.beetl.core.exception.NativeNotAllowedException)1 AddminExpContext (org.beetl.core.parser.BeetlParser.AddminExpContext)1