Search in sources :

Example 1 with DoWhile

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

the class AbstrCFMLScriptTransformer method doStatement.

/**
 * Liest ein do Statement ein.
 * <br />
 * EBNF:<br />
 * <code>block spaces "while" spaces "(" spaces condition spaces ")";</code>
 * @return do Statement
 * @throws TemplateException
 */
private final DoWhile doStatement(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("do")) {
        id = null;
        if (!data.srcCode.isCurrent('{') && !data.srcCode.isCurrent(' ') && !data.srcCode.isCurrent('/')) {
            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("do", '{') && !data.srcCode.forwardIfCurrent("do ") && !data.srcCode.forwardIfCurrent("do", '/')) {
            data.srcCode.setPos(pos);
            return null;
        }
        data.srcCode.previous();
    }
    // if(!data.srcCode.forwardIfCurrent("do",'{') && !data.srcCode.forwardIfCurrent("do ") && !data.srcCode.forwardIfCurrent("do",'/'))
    // return null;
    Position line = data.srcCode.getPosition();
    Body body = new BodyBase(data.factory);
    // data.srcCode.previous();
    statement(data, body, CTX_DO_WHILE);
    comments(data);
    if (!data.srcCode.forwardIfCurrent("while", '('))
        throw new TemplateException(data.srcCode, "do statement must have a while at the end");
    DoWhile doWhile = new DoWhile(condition(data), body, line, data.srcCode.getPosition(), id);
    if (!data.srcCode.forwardIfCurrent(')'))
        throw new TemplateException(data.srcCode, "do statement must end with a [)]");
    return doWhile;
}
Also used : Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException) DoWhile(lucee.transformer.bytecode.statement.DoWhile) 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