Search in sources :

Example 6 with Ref

use of lucee.runtime.interpreter.ref.Ref in project Lucee by lucee.

the class CFMLExpressionInterpreter method _plus.

private Ref _plus(Ref ref) throws PageException {
    // +=
    if (cfml.isCurrent('=')) {
        cfml.next();
        cfml.removeSpace();
        Ref right = assignOp();
        Ref res = preciseMath ? new BigPlus(ref, right, limited) : new Plus(ref, right, limited);
        ref = new Assign(ref, res, limited);
    } else {
        cfml.removeSpace();
        ref = preciseMath ? new BigPlus(ref, modOp(), limited) : new Plus(ref, modOp(), limited);
    }
    return ref;
}
Also used : Ref(lucee.runtime.interpreter.ref.Ref) BigPlus(lucee.runtime.interpreter.ref.op.BigPlus) Assign(lucee.runtime.interpreter.ref.var.Assign) DynAssign(lucee.runtime.interpreter.ref.var.DynAssign) Plus(lucee.runtime.interpreter.ref.op.Plus) BigPlus(lucee.runtime.interpreter.ref.op.BigPlus)

Example 7 with Ref

use of lucee.runtime.interpreter.ref.Ref in project Lucee by lucee.

the class CFMLExpressionInterpreter method checker.

/**
 * Hier werden die verschiedenen Moeglichen Werte erkannt
 * und jenachdem wird mit der passenden Methode weitergefahren
 * <br />
 * EBNF:<br />
 * <code>string | number | dynamic | sharp;</code>
 * @return CFXD Element
 * @throws PageException
 */
private Ref checker() throws PageException {
    Ref ref = null;
    // String
    if (cfml.isCurrentQuoter()) {
        // mode=STATIC; is at the end of the string function because must set after execution
        return string();
    }
    // Number
    if (cfml.isCurrentDigit() || cfml.isCurrent('.')) {
        // mode=STATIC; is at the end of the string function because must set after execution
        return number();
    }
    // Dynamic
    if ((ref = dynamic()) != null) {
        mode = DYNAMIC;
        return ref;
    }
    // Sharp
    if (!limited && (ref = sharp()) != null) {
        mode = DYNAMIC;
        return ref;
    }
    // JSON
    if ((ref = json(isJson ? JSON_ARRAY : LITERAL_ARRAY, '[', ']')) != null) {
        mode = DYNAMIC;
        return ref;
    }
    if ((ref = json(isJson ? JSON_STRUCT : LITERAL_STRUCT, '{', '}')) != null) {
        mode = DYNAMIC;
        return ref;
    }
    if (cfml.isAfterLast() && cfml.toString().trim().length() == 0)
        return new LString("");
    // else Error
    String str = cfml.toString();
    int pos = cfml.getPos();
    if (str.length() > 100) {
        // Failure is in the beginning
        if (pos <= 10) {
            str = str.substring(0, 20) + " ...";
        } else // Failure is in the end
        if ((str.length() - pos) <= 10) {
            str = "... " + str.substring(str.length() - 20, str.length());
        } else {
            str = "... " + str.substring(pos - 10, pos + 10) + " ...";
        }
    }
    throw new InterpreterException("Syntax Error, Invalid Construct", "at position " + (pos + 1) + " in [" + str + "]");
}
Also used : Ref(lucee.runtime.interpreter.ref.Ref) LString(lucee.runtime.interpreter.ref.literal.LString) ParserString(lucee.commons.lang.ParserString) LString(lucee.runtime.interpreter.ref.literal.LString)

Example 8 with Ref

use of lucee.runtime.interpreter.ref.Ref in project Lucee by lucee.

the class CFMLExpressionInterpreter method interpret.

public Object interpret(PageContext pc, String str, boolean preciseMath) throws PageException {
    this.cfml = new ParserString(str);
    this.preciseMath = preciseMath;
    init(pc);
    if (LITERAL_ARRAY == null)
        LITERAL_ARRAY = fld.getFunction("_literalArray");
    if (LITERAL_STRUCT == null)
        LITERAL_STRUCT = fld.getFunction("_literalStruct");
    if (JSON_ARRAY == null)
        JSON_ARRAY = fld.getFunction("_jsonArray");
    if (JSON_STRUCT == null)
        JSON_STRUCT = fld.getFunction("_jsonStruct");
    if (LITERAL_ORDERED_STRUCT == null)
        LITERAL_ORDERED_STRUCT = fld.getFunction("_literalOrderedStruct");
    cfml.removeSpace();
    Ref ref = assignOp();
    cfml.removeSpace();
    if (cfml.isAfterLast()) {
        // data.put(str+":"+preciseMath,ref);
        return ref.getValue(pc);
    }
    throw new InterpreterException("Syntax Error, invalid Expression [" + cfml.toString() + "]");
}
Also used : Ref(lucee.runtime.interpreter.ref.Ref) ParserString(lucee.commons.lang.ParserString)

Example 9 with Ref

use of lucee.runtime.interpreter.ref.Ref in project Lucee by lucee.

the class CFMLExpressionInterpreter 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 PageException
 */
private Ref orOp() throws PageException {
    Ref ref = andOp();
    while (cfml.isValidIndex() && (cfml.forwardIfCurrent("||") || cfml.forwardIfCurrent("or"))) {
        cfml.removeSpace();
        ref = new Or(ref, andOp(), limited);
    }
    return ref;
}
Also used : Ref(lucee.runtime.interpreter.ref.Ref) Or(lucee.runtime.interpreter.ref.op.Or)

Example 10 with Ref

use of lucee.runtime.interpreter.ref.Ref in project Lucee by lucee.

the class CFMLExpressionInterpreter method dynamic.

/**
 * Liest den folgenden idetifier ein und prueft ob dieser ein boolscher Wert ist.
 * Im Gegensatz zu CFMX wird auch "yes" und "no" als bolscher <wert akzeptiert,
 * was bei CFMX nur beim Umwandeln einer Zeichenkette zu einem boolschen Wert der Fall ist.<br />
 * Wenn es sich um keinen bolschen Wert handelt wird der folgende Wert eingelesen mit seiner ganzen Hirarchie.
 * <br />
 * EBNF:<br />
 * <code>"true" | "false" | "yes" | "no" | startElement
 *                     {("." identifier | "[" structElement "]" )[function] };</code>
 * @return CFXD Element
 * @throws PageException
 */
private Ref dynamic() throws PageException {
    // get First Element of the Variable
    int pos = cfml.getPos();
    String name = identifier(false);
    if (name == null) {
        if (!cfml.forwardIfCurrent('('))
            return null;
        cfml.removeSpace();
        Ref ref = assignOp();
        if (!cfml.forwardIfCurrent(')'))
            throw new InterpreterException("Invalid Syntax Closing [)] not found");
        cfml.removeSpace();
        return limited ? ref : subDynamic(ref);
    }
    cfml.removeSpace();
    // Boolean constant
    if (name.equalsIgnoreCase("TRUE")) {
        cfml.removeSpace();
        return LBoolean.TRUE;
    } else if (name.equalsIgnoreCase("FALSE")) {
        cfml.removeSpace();
        return LBoolean.FALSE;
    } else if (!isJson && name.equalsIgnoreCase("YES")) {
        cfml.removeSpace();
        return LBoolean.TRUE;
    } else if (!isJson && name.equalsIgnoreCase("NO")) {
        cfml.removeSpace();
        return LBoolean.FALSE;
    } else if (allowNullConstant && name.equalsIgnoreCase("NULL")) {
        cfml.removeSpace();
        return new LString(null);
    } else if (!limited && name.equalsIgnoreCase("NEW")) {
        Ref res = newOp();
        if (res != null)
            return res;
    }
    return limited ? startElement(name) : subDynamic(startElement(name));
}
Also used : Ref(lucee.runtime.interpreter.ref.Ref) LString(lucee.runtime.interpreter.ref.literal.LString) ParserString(lucee.commons.lang.ParserString) LString(lucee.runtime.interpreter.ref.literal.LString)

Aggregations

Ref (lucee.runtime.interpreter.ref.Ref)34 Assign (lucee.runtime.interpreter.ref.var.Assign)9 DynAssign (lucee.runtime.interpreter.ref.var.DynAssign)9 ArrayList (java.util.ArrayList)6 Casting (lucee.runtime.interpreter.ref.cast.Casting)6 BIFCall (lucee.runtime.interpreter.ref.func.BIFCall)6 LString (lucee.runtime.interpreter.ref.literal.LString)6 FunctionLibFunctionArg (lucee.transformer.library.function.FunctionLibFunctionArg)5 ParserString (lucee.commons.lang.ParserString)4 FunctionLibFunction (lucee.transformer.library.function.FunctionLibFunction)4 ExpressionException (lucee.runtime.exp.ExpressionException)3 LFunctionValue (lucee.runtime.interpreter.ref.literal.LFunctionValue)3 BigPlus (lucee.runtime.interpreter.ref.op.BigPlus)3 Plus (lucee.runtime.interpreter.ref.op.Plus)3 BigIntDiv (lucee.runtime.interpreter.ref.op.BigIntDiv)2 BigMinus (lucee.runtime.interpreter.ref.op.BigMinus)2 Concat (lucee.runtime.interpreter.ref.op.Concat)2 IntDiv (lucee.runtime.interpreter.ref.op.IntDiv)2 Minus (lucee.runtime.interpreter.ref.op.Minus)2 Key (lucee.runtime.type.Collection.Key)2