Search in sources :

Example 1 with While

use of lucee.transformer.bytecode.statement.While in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method whileStatement.

/**
 * Liest ein while Statement ein.
 * <br />
 * EBNF:<br />
 * <code>spaces condition spaces ")" spaces block;</code>
 * @return while Statement
 * @throws TemplateException
 */
private final While whileStatement(ExprData data) throws TemplateException {
    int pos = data.srcCode.getPos();
    // id
    String id = variableDec(data, false);
    if (id == null) {
        data.srcCode.setPos(pos);
        return null;
    }
    if (id.equalsIgnoreCase("while")) {
        id = null;
        data.srcCode.removeSpace();
        if (!data.srcCode.forwardIfCurrent('(')) {
            data.srcCode.setPos(pos);
            return null;
        }
    } else {
        data.srcCode.removeSpace();
        if (!data.srcCode.forwardIfCurrent(':')) {
            data.srcCode.setPos(pos);
            return null;
        }
        data.srcCode.removeSpace();
        if (!data.srcCode.forwardIfCurrent("while", '(')) {
            data.srcCode.setPos(pos);
            return null;
        }
    }
    Position line = data.srcCode.getPosition();
    Body body = new BodyBase(data.factory);
    While whil = new While(condition(data), body, line, null, id);
    if (!data.srcCode.forwardIfCurrent(')'))
        throw new TemplateException(data.srcCode, "while statement must end with a [)]");
    statement(data, body, CTX_WHILE);
    whil.setEnd(data.srcCode.getPosition());
    return whil;
}
Also used : Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException) DoWhile(lucee.transformer.bytecode.statement.DoWhile) While(lucee.transformer.bytecode.statement.While) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase)

Aggregations

TemplateException (lucee.runtime.exp.TemplateException)1 Position (lucee.transformer.Position)1 Body (lucee.transformer.bytecode.Body)1 BodyBase (lucee.transformer.bytecode.BodyBase)1 FunctionBody (lucee.transformer.bytecode.FunctionBody)1 ScriptBody (lucee.transformer.bytecode.ScriptBody)1 DoWhile (lucee.transformer.bytecode.statement.DoWhile)1 While (lucee.transformer.bytecode.statement.While)1