Search in sources :

Example 21 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class AbstrCFMLExprTransformer method decsionOp.

/**
 * <font f>Transfomiert eine Vergleichs Operation.
 * <br />
 * EBNF:<br />
 * <code>concatOp {("neq"|"eq"|"gte"|"gt"|"lte"|"lt"|"ct"|
 *	                 "contains"|"nct"|"does not contain") spaces concatOp};
 *			(* "ct"=conatains und "nct"=does not contain; Existiert in CFMX nicht *)</code>
 * @return CFXD Element
 * @throws TemplateException
 */
private Expression decsionOp(ExprData data) throws TemplateException {
    Expression expr = concatOp(data);
    boolean hasChanged = false;
    // ct, contains
    do {
        hasChanged = false;
        if (data.srcCode.isCurrent('c')) {
            if (data.srcCode.forwardIfCurrent("ct", false, true)) {
                expr = decisionOpCreate(data, OPDecision.CT, expr);
                hasChanged = true;
            } else if (data.srcCode.forwardIfCurrent("contains", false, true)) {
                expr = decisionOpCreate(data, OPDecision.CT, expr);
                hasChanged = true;
            }
        } else // does not contain
        if (data.srcCode.forwardIfCurrent("does", "not", "contain", false, true)) {
            expr = decisionOpCreate(data, OPDecision.NCT, expr);
            hasChanged = true;
        } else // equal, eq
        if (data.srcCode.isCurrent("eq") && !data.srcCode.isCurrent("eqv")) {
            int plus = 2;
            data.srcCode.setPos(data.srcCode.getPos() + 2);
            if (data.srcCode.forwardIfCurrent("ual"))
                plus = 5;
            if (data.srcCode.isCurrentVariableCharacter()) {
                data.srcCode.setPos(data.srcCode.getPos() - plus);
            } else {
                expr = decisionOpCreate(data, OPDecision.EQ, expr);
                hasChanged = true;
            }
        } else // ==
        if (data.srcCode.forwardIfCurrent("==")) {
            if (data.srcCode.forwardIfCurrent('='))
                expr = decisionOpCreate(data, OPDecision.EEQ, expr);
            else
                expr = decisionOpCreate(data, OPDecision.EQ, expr);
            hasChanged = true;
        } else // !=
        if (data.srcCode.forwardIfCurrent("!=")) {
            if (data.srcCode.forwardIfCurrent('='))
                expr = decisionOpCreate(data, OPDecision.NEEQ, expr);
            else
                expr = decisionOpCreate(data, OPDecision.NEQ, expr);
            hasChanged = true;
        } else // <=/</<>
        if (data.srcCode.isCurrent('<')) {
            hasChanged = true;
            if (data.srcCode.isNext('=')) {
                data.srcCode.next();
                data.srcCode.next();
                expr = decisionOpCreate(data, OPDecision.LTE, expr);
            } else if (data.srcCode.isNext('>')) {
                data.srcCode.next();
                data.srcCode.next();
                expr = decisionOpCreate(data, OPDecision.NEQ, expr);
            } else if (data.srcCode.isNext('/')) {
                hasChanged = false;
            } else {
                data.srcCode.next();
                expr = decisionOpCreate(data, OPDecision.LT, expr);
            }
        } else // >=/>
        if (data.allowLowerThan && data.srcCode.forwardIfCurrent('>')) {
            if (data.srcCode.forwardIfCurrent('='))
                expr = decisionOpCreate(data, OPDecision.GTE, expr);
            else
                expr = decisionOpCreate(data, OPDecision.GT, expr);
            hasChanged = true;
        } else // gt, gte, greater than or equal to, greater than
        if (data.srcCode.isCurrent('g')) {
            if (data.srcCode.forwardIfCurrent("gt")) {
                if (data.srcCode.forwardIfCurrentAndNoWordAfter("e")) {
                    if (data.srcCode.isCurrentVariableCharacter()) {
                        data.srcCode.setPos(data.srcCode.getPos() - 3);
                    } else {
                        expr = decisionOpCreate(data, OPDecision.GTE, expr);
                        hasChanged = true;
                    }
                } else {
                    if (data.srcCode.isCurrentVariableCharacter()) {
                        data.srcCode.setPos(data.srcCode.getPos() - 2);
                    } else {
                        expr = decisionOpCreate(data, OPDecision.GT, expr);
                        hasChanged = true;
                    }
                }
            } else if (data.srcCode.forwardIfCurrent("greater", "than", false, true)) {
                if (data.srcCode.forwardIfCurrent("or", "equal", "to", true, true))
                    expr = decisionOpCreate(data, OPDecision.GTE, expr);
                else
                    expr = decisionOpCreate(data, OPDecision.GT, expr);
                hasChanged = true;
            } else if (data.srcCode.forwardIfCurrent("ge", false, true)) {
                expr = decisionOpCreate(data, OPDecision.GTE, expr);
                hasChanged = true;
            }
        } else // is, is not
        if (data.srcCode.forwardIfCurrent("is", false, true)) {
            if (data.srcCode.forwardIfCurrent("not", true, true))
                expr = decisionOpCreate(data, OPDecision.NEQ, expr);
            else
                expr = decisionOpCreate(data, OPDecision.EQ, expr);
            hasChanged = true;
        } else // lt, lte, less than, less than or equal to
        if (data.srcCode.isCurrent('l')) {
            if (data.srcCode.forwardIfCurrent("lt")) {
                if (data.srcCode.forwardIfCurrentAndNoWordAfter("e")) {
                    if (data.srcCode.isCurrentVariableCharacter()) {
                        data.srcCode.setPos(data.srcCode.getPos() - 3);
                    } else {
                        expr = decisionOpCreate(data, OPDecision.LTE, expr);
                        hasChanged = true;
                    }
                } else {
                    if (data.srcCode.isCurrentVariableCharacter()) {
                        data.srcCode.setPos(data.srcCode.getPos() - 2);
                    } else {
                        expr = decisionOpCreate(data, OPDecision.LT, expr);
                        hasChanged = true;
                    }
                }
            } else if (data.srcCode.forwardIfCurrent("less", "than", false, true)) {
                if (data.srcCode.forwardIfCurrent("or", "equal", "to", true, true))
                    expr = decisionOpCreate(data, OPDecision.LTE, expr);
                else
                    expr = decisionOpCreate(data, OPDecision.LT, expr);
                hasChanged = true;
            } else if (data.srcCode.forwardIfCurrent("le", false, true)) {
                expr = decisionOpCreate(data, OPDecision.LTE, expr);
                hasChanged = true;
            }
        } else // neq, not equal, nct
        if (data.srcCode.isCurrent('n')) {
            // Not Equal
            if (data.srcCode.forwardIfCurrent("neq", false, true)) {
                expr = decisionOpCreate(data, OPDecision.NEQ, expr);
                hasChanged = true;
            } else // Not Equal (Alias)
            if (data.srcCode.forwardIfCurrent("not", "equal", false, true)) {
                expr = decisionOpCreate(data, OPDecision.NEQ, expr);
                hasChanged = true;
            } else // nct
            if (data.srcCode.forwardIfCurrent("nct", false, true)) {
                expr = decisionOpCreate(data, OPDecision.NCT, expr);
                hasChanged = true;
            }
        }
    } while (hasChanged);
    return expr;
}
Also used : FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression)

Example 22 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class AbstrCFMLExprTransformer method orOp.

/**
 * Transfomiert eine  Or (or) Operation. Im Gegensatz zu CFMX ,
 * werden "||" Zeichen auch als Or Operatoren anerkannt.
 * <br />
 * EBNF:<br />
 * <code>andOp {("or" | "||") spaces andOp}; (* "||" Existiert in CFMX nicht *)</code>
 * @return CFXD Element
 * @throws TemplateException
 */
private Expression orOp(ExprData data) throws TemplateException {
    Expression expr = andOp(data);
    while (data.srcCode.forwardIfCurrent("||") || data.srcCode.forwardIfCurrentAndNoWordAfter("or")) {
        comments(data);
        expr = data.factory.opBool(expr, andOp(data), Factory.OP_BOOL_OR);
    }
    return expr;
}
Also used : FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression)

Example 23 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class AbstrCFMLExprTransformer method staticScope.

private Expression staticScope(ExprData data, Expression expr) throws TemplateException {
    if (data.srcCode.forwardIfCurrent("::")) {
        if (!(expr instanceof Variable))
            throw new TemplateException(data.srcCode, "invalid syntax before [::]");
        Variable old = (Variable) expr;
        // set back to read again as a component path
        data.srcCode.setPos(old.getStart().pos);
        // now we read the component path
        ExprString componentPath = readComponentPath(data);
        if (!data.srcCode.forwardIfCurrent("::"))
            throw new TemplateException(data.srcCode, "invalid syntax before [::]" + data.srcCode.getCurrent());
        comments(data);
        BIF bif = null;
        if (componentPath instanceof LitString) {
            LitString ls = (LitString) componentPath;
            if ("super".equalsIgnoreCase(ls.getString())) {
                bif = ASMUtil.createBif(data, GET_SUPER_STATIC_SCOPE);
            }
        }
        // now we generate a _getStaticScope function call with that path
        if (bif == null) {
            bif = ASMUtil.createBif(data, GET_STATIC_SCOPE);
            bif.addArgument(new Argument(componentPath, "string"));
        }
        Variable var = data.factory.createVariable(old.getStart(), data.srcCode.getPosition());
        var.addMember(bif);
        // now we are reading what is coming after ":::"
        Expression sd = subDynamic(data, var, false, true);
        return sd;
    }
    return null;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) NamedArgument(lucee.transformer.bytecode.expression.var.NamedArgument) Argument(lucee.transformer.bytecode.expression.var.Argument) TemplateException(lucee.runtime.exp.TemplateException) ExprString(lucee.transformer.expression.ExprString) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) BIF(lucee.transformer.bytecode.expression.var.BIF)

Example 24 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class AbstrCFMLExprTransformer method andOp.

/**
 * Transfomiert eine  And (and) Operation. Im Gegensatz zu CFMX ,
 * werden "&&" Zeichen auch als And Operatoren anerkannt.
 * <br />
 * EBNF:<br />
 * <code>notOp {("and" | "&&") spaces notOp}; (* "&&" Existiert in CFMX nicht *)</code>
 * @return CFXD Element
 * @throws TemplateException
 */
private Expression andOp(ExprData data) throws TemplateException {
    Expression expr = notOp(data);
    while (data.srcCode.forwardIfCurrent("&&") || data.srcCode.forwardIfCurrentAndNoWordAfter("and")) {
        comments(data);
        expr = data.factory.opBool(expr, notOp(data), Factory.OP_BOOL_AND);
    }
    return expr;
}
Also used : FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression)

Example 25 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class AbstrCFMLExprTransformer method divMultiOp.

/**
 * Transfomiert die mathematischen Operatoren Mal und Durch (*,/).
 * <br />
 * EBNF:<br />
 * <code>expoOp {("*"|"/") spaces expoOp};</code>
 * @return CFXD Element
 * @throws TemplateException
 */
private Expression divMultiOp(ExprData data) throws TemplateException {
    Expression expr = expoOp(data);
    while (!data.srcCode.isLast()) {
        // Multiply Operation
        if (data.srcCode.forwardIfCurrent('*')) {
            expr = _divMultiOp(data, expr, OpDouble.MULTIPLY);
        // comments(data);
        // expr=OpDouble.toExprDouble(expr, expoOp(), OpDouble.MULTIPLY);
        } else // Divide Operation
        if (data.srcCode.isCurrent('/') && (!data.srcCode.isCurrent('/', '>'))) {
            data.srcCode.next();
            expr = _divMultiOp(data, expr, OpDouble.DIVIDE);
        // comments(data);
        // expr=OpDouble.toExprDouble(expr, expoOp(), OpDouble.DIVIDE);
        } else // Divide Operation
        if (data.srcCode.isCurrent('\\')) {
            data.srcCode.next();
            expr = _divMultiOp(data, expr, OpDouble.INTDIV);
        // comments(data);
        // expr=OpDouble.toExprDouble(expr, expoOp(), OpDouble.INTDIV);
        } else {
            break;
        }
    }
    return expr;
}
Also used : FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression)

Aggregations

Expression (lucee.transformer.expression.Expression)74 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)34 LitString (lucee.transformer.expression.literal.LitString)25 TemplateException (lucee.runtime.exp.TemplateException)19 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)16 Variable (lucee.transformer.expression.var.Variable)16 Body (lucee.transformer.bytecode.Body)11 ExprString (lucee.transformer.expression.ExprString)11 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)11 Position (lucee.transformer.Position)10 OpVariable (lucee.transformer.bytecode.op.OpVariable)10 LitBoolean (lucee.transformer.expression.literal.LitBoolean)8 Literal (lucee.transformer.expression.literal.Literal)8 ArrayList (java.util.ArrayList)7 TransformerException (lucee.transformer.TransformerException)7 BodyBase (lucee.transformer.bytecode.BodyBase)7 Statement (lucee.transformer.bytecode.Statement)7 Argument (lucee.transformer.bytecode.expression.var.Argument)7 PrintOut (lucee.transformer.bytecode.statement.PrintOut)6 FunctionBody (lucee.transformer.bytecode.FunctionBody)5